Biopython, import error with "import Bio" - anaconda

I have installed Biopython by Anaconda on Windows.
When I try import Bio I get this error:
ModuleNotFoundError: No module named 'Bio'
Why?

Simone.. it looks like your installation did go wrong somehow. Regardless of why and how try the following stepwise approach to see if your import error remains.
On Windows (the dots denote your installed program path specifics):
e.g. go to: C:\....\Anaconda...\Lib\site-packages
find and remove folders using delete.
folder 1: "\Bio"
folder 2: "\biopython-1.70.dist-info"
The version value 1.70 might be 1.69 when using conda for installation.
Empty your trashbin. This way the system can't do tricks and recover or link to deleted files and folders.
Install pip if its not and grab it from here.
try pip install biopython --no-cache-dir
Voila! Hope it works now for you too... Enjoy!
In case its not check windows environment variables\path.. via control panel>advanced system settings to include PATH to site-packages. Or do similar on other OS.

Related

no sudo cyipopt anaconda install : ImportError: libipopt.so.1: cannot open shared object file: No such file or directory

I am trying to install cyipopt package without sudo via anaconda on python 3.
I run conda install -c conda-forge cyipopt.
Then upon attempting to import cyipopt (import cyipopt) I get the error,
ImportError: libipopt.so.1: cannot open shared object file: No such file or directory
I do not know what libipopt.so.1 is. I presume it is a package ?
I found some relevant solutions, but I do not understand either of them or seem to missing some context.
In https://github.com/xuy/pyipopt the solution to my problem that is given is to find libipopt.so.1 and move it somewhere I have access to it. But I do not know where to find this package nor where an appropriate location for it is.
Meanwhile libipopt.so.1: Cannot open shared object file suggests changing/adding a path but I am not sure what paths are meant. I do not understand what is meant by the environment variable here and where I am to export it to.

Pip install local package in conda environemnt

I recently developed a package my_package and am hosting it on GitHub. For easy installation and use, I have following setup.py:
from setuptools import setup
setup(name='my_package',
version='1.0',
description='My super cool package',
url='https://github.com/my_name/my_package',
packages=['my_package'],
python_requieres='3.9',
install_requires=[
'some_package==1.0.0'
])
Now I am trying to install this package in a conda environment:
conda create --name myenv python=3.9
conda activate myenv
pip install git+'https://github.com/my_name/my_package'
So far so good. If I try to use it in the project folder, everything works perfectly. If I try to use the packet outside the project folder (still inside the conda environment), I get the following error:
ModuleNotFoundError: No module named 'my_package'
I am working on windows, if that matters.
EDIT:
I'm verifying that both python and pip are pointing towards the correct version with:
which pip
which python
/c/Anaconda3/envs/my_env/python
/c/Anaconda3/envs/my_env/Scripts/pip
Also, when I run:
pip show my_package
I get a description of my package. So pip finds it, but as soon as I try to import my_package in the script, I get the described error.
I also verified that the package is installed in my environment. So in /c/Anaconda3/envs/my_env/lib/site-packages there is a folder my_package-1.0.dist-info/
Further: python "import sys, print(sys.path)"
shows, among other paths, /c/Anaconda3/envs/my_env/lib/site-packages. So it is in the path.
Check if you are using some explicit shebang in your script pointing to other Python interpreters.
Eg. using the system default Python:
#!/bin/env python
...
While inside your environment myenv, try to uninstall your package first, to do a clean test:
pip uninstall my_package
Also, you have a typo in your setup.py: python_requieres --> python_requires.
And I actually tried to install with your setup.py, and also got ModuleNotFoundError - but because it didn't properly install due to install_requires:
ERROR: Could not find a version that satisfies the requirement some_package==1.0.0
So, check also that everything installs without errors and warnings.
Hope that helps.
First thing I would like to point out (not the solution) regards the following statement you made:
If I try to use it in the project folder [...] If I try to use the packet outside the project folder [...]
I understand "project folder" means the "my_package" folder (inside the git repository). If that is the case, I would like to point out that you are mixing two situations: that of testing a (remote) package installation, while in your (local) repository. Which is not necessarily wrong, but error-prone.
Whenever testing the setup/install process of a package, make sure to move far from your repository (say, "/tmp/" equivalent in Windows) and, preferably, use a fresh environment. That will eliminate "noise" in your tests.
First thing I would tell you to do -- if not already -- is to create a fresh conda env and install your package from an empty/new folder. Eg,
$ conda env create -n test_my_package ipython pip
$ cd /tmp # equivalent temporary or new in your Windows
$ pip install git+https://github.com/my_name/my_package
If that doesn't work (maybe a problem with your pip' git+http code), do another way: create a release for your package (eg, "v1") and then install the released version by indicating the zip package URL (that you get from your "my_package" releases page on Github):
$ pip install https://github.com/my_name/my_package/archive/v1.zip

Jupyter can't find my packages, how can I connect my kernel to the pip destination folder?

first time on stack overflow. Basically pip is installing packages and Jupyter notebook can't find them to import. I've searched other similar questions and found some tips, but none of them have worked in my particular instance. I've shown the information that was helpful in other posts so you can see what I' mworking with:
My Notebook
In similar questions they've asked what "jupyter kernelspec list" returns in the terminal, so I've inlcuded that here:
KernelSpec Results
I would include my kernel.json file as well, but I tried changing with it, and upon seeing no change, tried deleting it altogether and my notebook runs fine.
So I'm thoroughly confused, and could really use some help.
Thankyou
Make sure the packages you think you installed are really installed to the running environment.
E.g. from inside notebook run:
!pip list | grep package_name
If the package in question is installed, get details using [pip show][1]
!pip show pyyaml
Name: PyYAML
Version: 5.1
Summary: YAML parser and emitter for Python
Home-page: https://github.com/yaml/pyyaml
Author: Kirill Simonov
Author-email: xi#resolvent.net
License: MIT
Location: /home/ntg/anaconda3/lib/python3.7/site-packages
Requires:
Required-by: bokeh, anaconda-client
Remember that for some libraries the import is not the name of the module,e.g. to install pyyaml I did pip install pyyaml, but to import it I will need import yaml... When in doubt, google the specific module.
Keep in mind that pip deals with modules (think libraries such as pandas).
If you cannot find some of your code, make sure it is in the directory you think it is, if not in the same directory, make sure the other directory has a file named init.py to denote the dir is a module, and possibly check
Cannot import from __init__ in a subfolder

Theano is missing modules

I am on windows 64bit, I have installed anaconda, and managed to create an environment with python 2.7
I have numpy, pylearn2, theano, and every package is built properly
I have been able to import all these modules, however I get some very esoteric messages when I try to complete the model, like
ImportError: Could not import pylearn2.models.softmax_regression but could import pylearn2.models. Original exception: No module named dnn
Then I tried to actually find the package in the installation, but inside the cuda folder, there is no module named dnn. Looking at github, I see that it should be there.
Why is theano missing modules? I installed using conda install theano, and it gave some suggestions, I have managed to pick the correct one.
I have uninstalled and installed theano many time, I can import it but I can never get the proper modules.
What is going wrong?
Ok, after a few days of search, it seems like Theano installed from anaconda is missing a lot of modules. However, installing theano by cloning the repository with
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
seems to resolve the issue. Since windows normally does not have git, it can be easily installed (seems to take care of the environment's path variable) from here
https://git-scm.com/download/win

Why is pydot unable to find GraphViz's executables in Windows 8?

I have GraphViz 2.32 installed in Windows 8 and have added C:\Program Files (x86)\Graphviz2.32\bin to the System PATH variable. Still pydot is unable to find its executables.
Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
graph.write_png('example1_graph.png')
File "build\bdist.win32\egg\pydot.py", line 1809, in <lambda>
lambda path, f=frmt, prog=self.prog : self.write(path, format=f, prog=prog))
File "build\bdist.win32\egg\pydot.py", line 1911, in write
dot_fd.write(self.create(prog, format))
File "build\bdist.win32\egg\pydot.py", line 1953, in create
'GraphViz\'s executables not found' )
InvocationException: GraphViz's executables not found
I found this https://code.google.com/p/pydot/issues/detail?id=65 but am unable to get the problem solved.
The problem is that the path to GraphViz was not found by the pydot module as shown in the traceback:
'GraphViz\'s executables not found'
I solved this problem on my windows 7 machine by adding the GraphViz bin directory to my computer's PATH. Then restarting my python IDE to use the updated path.
Install GraphViz if you haven't already (I used the MSI download)
Get the path for gvedit.exe (for me it was "C:\Program Files
(x86)\Graphviz2.34\bin\")
Add this path to the computer's PATH
One way to get to environment settings to set your path is to click on each of these button/menu options: start->computer->system
properties->advanced settings->environment variables
Click Edit User path
Add this string to the end of your Variable value list (including
semicolon): ;C:\Program Files (x86)\Graphviz2.34\bin
Click OK
Restart your Python IDE
On Mac brew install graphviz solved the problem for me.
This happened because I had installed graphviz after I had installed pydot. Hence, pydot wasn't able to find it. Reinstalling it in the correct order solved the problem.
I tried adding PATH via Control Panel, but restarting the command prompt is also needed. The following also works for updating the path in a Notebook session without exiting:
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
in my case answer from Sadik
pydot and graphviz error: Couldn't import dot_parser, loading of dot files will not be possible worked for me on Ubuntu 12.04.5 LTS
sudo apt-get install python-pydot
You need to install from Graphviz and then just add the path of folder where you installed Graphviz and its bin directory to system environments path.
For windows 8.1 & python 2.7 , I fixed the problem by following below steps
1 . Download and install graphviz-2.38.msi https://graphviz.gitlab.io/_pages/Download/Download_windows.html
2 . Set the path variable
Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit
add 'C:\Program Files (x86)\Graphviz2.38\bin'
Restart your currently running application that requires the path
I'm working on Windows 10 with Anaconda 3.6.5. I have not admin rights, so if someone is under the circumstances like me this solution works perfectly.
The path for my graphviz is looks
C:\Users\User_Name\AppData\Local\Continuum\anaconda3\Library\bin\graphviz
In Spyder or in Jupyter type the following:
import os
os.environ['PATH'].split(os.pathsep)
This will lists all the path in you environment. Take a look to them, if your graphviz path is not here, then go find it and copy the path, like above in my example.
Then type the following:
os.environ['PATH'] += os.pathsep + 'C:\\Users\\User_Name\\AppData\\Local\\Continuum\\anaconda3\\Library\\bin\\graphviz'
That's all, but note that you have to run these command every time if you restart kernel
Add dot.exe to your path.
right click my computer > advanced system settings > environment variables > high light 'path' > edit
then append everything in the quotes to path ";C:\Program Files (x86)\Graphviz2.34\bin\" depending on where you installed Graphviz ofcourse.Then restart the python shell and type.
import pydot
pydot.find_graphviz()
Make sure there is a slash after 'bin' so it gets everything from inside the folder, I tried with out the slash and the above code returned nothing, however after adding the slash it returned the graphviz executables it needed and their paths.
For me: (Win10, Anaconda3)
Make sure you have done "conda install graphviz"
I have to add to the PATH: C:\Users\username\Anaconda3\Library\bin\graphviz
To modify PATH go to Control Panel > System and Security > System > Advanced System Settings > Environment Variables > Path > Edit > New
MAKE SURE TO RESTART YOUR IDE AFTER THIS.
It should work
In Windows, even after installing graphviz-2.38.msi, you can add your own path in pydot.py (found under site-package folder)
if os.sys.platform == 'win32':
# Try and work out the equivalent of "C:\Program Files" on this
# machine (might be on drive D:, or in a different language)
#
if os.environ.has_key('PROGRAMFILES'):
# Note, we could also use the win32api to get this
# information, but win32api may not be installed.
path = os.path.join(os.environ['PROGRAMFILES'], 'ATT', 'GraphViz', 'bin')
else:
#Just in case, try the default...
path = r"C:\PYTHON27\GraphViz\bin" # add here.
I too had the same issue and I finally resolved it by having a look at the library.
The library considers making the path set as C:\Program Files\ATT\Graphviz\bin but by default Graphviz is installed to C:\Program Files(x86)\Graphviz undergoing the 32-bit criteria hence the pydot fails in getting the required path.
Simply shift the directory as required by the script and you're good to go.
P.S.:- Consider making the equivalent changes to the Environmnet Variable.
P.S.S:- Also check if Graphviz is directly under Program Files(x86) or under ATT.
I am running a Windows 10 machine and had some problems, too.
I installed graphviz via msi installer. Adding via System settings did not work for me.
I removed the installation with the msi and used chocolatey, a windows package manager.
Removing the installed version is necessary, otherwise chocolatey won't install.
Now it runs fine. I would recommend doing it this way.
Here is what I did for the above mentioned problem. I'm using windows 10 os and python 3.6.5
Install PIP by clicking here
open command prompt and type command "pip install graphviz"
go to my computer(this pc) and search with the keyword "graphviz"
open the graphviz folder and copy its path and save it in notepad
In graphviz look for the bin folder and copy the folder by right click of your mouse
now again head back to my computer and search for "pydotplus"
a folder named pydotplus is displayed. Open it and paste the copy of bin folder (of Graphviz) that you copied earlier
head to control panel>system and security> system settings> advanced settings> environmental variables> add new path
add the path that you copied in notepad and click a series of "ok"
that's it now you can enjoy using graphviz
install Graphviz here and add its bin path solved my problem
https://graphviz.gitlab.io/_pages/Download/Download_windows.html
pip install Graphviz itself seems inadequate
Some things to know about graphviz:
graphviz is not only a python module, it's also a standalone program. I believe you need both to make graphviz to work.
The standalone graphviz program was originally developed by AT&T, open sourced, then abandoned. The current maintainers of the package forgot to include Windows registry entries so Python can find the program executable.
Line 620 of pydotplus\graphviz.py includes a backup path to look for graphviz if it isn't found in the registry. It uses the old ATT file path. Update the file path to what is on your machine (you will need to have administrator privileges) and graphviz should work with pydotplus.
Example:
# Just in case, try the default...
path = r"C:\Program Files (x86)\Graphviz2.38\bin"
In "pydot.py" (located in ...\Anaconda3\Lib\site-packages), replace:
def get_executable_extension():
# type: () -> str
if is_windows():
return '.bat' if is_anacoda() else '.exe'
else:
return ''
with:
def get_executable_extension():
# type: () -> str
if is_windows():
return '.exe'
else:
return ''
There does not seem to be any eason to add ".bat" when the system is "Windows/Anaconda" vs "Windows" and there may be no ".bat" associated with the ".exe". This seems better than adding a ".bat" for every executable pydot calls...
I had this issue and noticed that it was printing my PATH with two sets of double-quotes. I worked around the problem by adding the following to Line 1959 of:
C:\Anaconda\Lib\site-packages\pydot.py
self.progs[prog] = os.path.normpath(self.progs[prog][1:-1])
Obviously not the best fix but it got me through the day.
I found a manual solution:
sudo apt-get install graphviz
graph.write('test.dot')
dot -Tps test.dot -o outfile.ps
You can the files here: https://github.com/jecs89/LearningEveryDay/tree/master/GP
Tried all installation sequence as described in all solutions/posting/blogs, finally realized anaconda was not able to read the Environment variables. Closed Anaconda and Spyder. Then opened Anaconda in Administrator mode (on Windows 64 bit OS machine) and then opened Spyder. Script worked fine with PYDOT calls.
I am not using a windows machine, I am on a linux platform. I ran across this executable-not-found issue in the context of using the python package pyAgrum for plotting bayesian networks. pyAgrum uses graphviz to plot the networks. I installed pyagrum and graphviz using the anaconda platform in a python 3.6.4 environment (i.e. conda install <package name>).
I found the executables in /conda/envs/<environment name>/bin directory. So, it was just a matter of getting my notebook kernel to find them.
If you import os, use the command os.environ['PATH'].split(os.pathsep) to see the executable paths in which your environment is looking. If the path containing your graphviz executables isn't in there, you can add it by doing the following: os.environ['PATH'] += os.pathsep + <path to executables>.
I imagine this solution will work outside of my context. The main downside to this solution is that you need to do it every time you restart the kernel.
you can use pydotplus instead of pydot.then follow the belows:
First, find C:\Users\zhangqianyuan\AppData\Local\Programs\Python\Python36\Lib\site-packages\pydotplus
Second, open graphviz.py
Third, find line 1925 - line 1972, find the function def create(self, prog=None, format='ps'):
Final, in the function:
find:
if prog not in self.progs:
raise InvocationException(
'GraphViz\'s executable "%s" not found' % prog)
`
if not os.path.exists(self.progs[prog]) or \
not os.path.isfile(self.progs[prog]):
raise InvocationException(
'GraphViz\'s executable "{}" is not'
' a file or doesn\'t exist'.format(self.progs[prog])
)
between the two blocks add this(Your Graphviz's executable path):
self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"
after adding the result is:
if prog not in self.progs:
raise InvocationException(
'GraphViz\'s executable "%s" not found' % prog)
self.progs[prog] = "C:/Program Files (x86)/Graphviz2.38/bin/gvedit.exe"
if not os.path.exists(self.progs[prog]) or \
not os.path.isfile(self.progs[prog]):
raise InvocationException(
'GraphViz\'s executable "{}" is not'
' a file or doesn\'t exist'.format(self.progs[prog])
)
save the changed file then you can run it successfully.
you'd better save it as bmp file because png file will not work.
If you dont want to mess around with path variables (e.g. if you are no admin) and if you are working on windows, you can do the following which solved the problem for me.
Open graphviz.py (likely located in ...Anaconda\pkgs\graphviz***\Library\bin) in an editor. If you cant find it you might be able to open it via the error message.
Go to the fuction __find_executables and replace:
elif os.path.exists(os.path.join(path, prg + '.exe')):
if was_quoted:
progs[prg] = '"' + os.path.join(path, prg + '.exe') + '"'
else:
progs[prg] = os.path.join(path, prg + '.exe')
with
elif os.path.exists(os.path.join(path, prg + '.bat')):
if was_quoted:
progs[prg] = '"' + os.path.join(path, prg + '.bat') + '"'
else:
progs[prg] = os.path.join(path, prg + '.bat')
The solution is easy, you just need to download and install the Graphviz, from here.
Then set the path variable to the bin directory, in my case it was C:\Program Files (x86)\Graphviz2.38\bin. Last, do the conda install python-graphviz and it should work fine.
On Anaconda distro, pip install did not work. I did a pip uninstall graphviz, pip uninstall pydot, and then I did conda install graphviz and then conda install pydot, in this order, and then it worked!
I used conda install python-graphviz
then
conda install pydot
and then
conda install pydot plus
and then it worked.
So:
conda install python-graphviz
conda install pydot
conda install pydotplus
after doing all the installation of graphviz, adding to the PATH of environment variables, you need to add these two lines:
import os
os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/'
I tried several ways and all failed on Windows 10 and finally this worked for me:
Try to install it directly from graphviz website, just google "install graphviz" and I believe it will be the first option.

Resources