Installing Biopython: ImportError: No module named Bio - python

trying to install Biopython on Fedora 21, Python 2.7. I've done the following
[mike#localhost Downloads](17:32)$ sudo pip2.7 install biopython
You are using pip version 6.1.1, however version 7.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting biopython
/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading biopython-1.65.tar.gz (12.6MB)
100% |████████████████████████████████| 12.6MB 33kB/s
Installing collected packages: biopython
Running setup.py install for biopython
Successfully installed biopython-1.65
And then
[mike#localhost Downloads](17:32)$ ipython
Python 2.7.9 |Anaconda 2.2.0 (64-bit)| (default, Mar 9 2015, 16:20:48)
In [1]: import Bio
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a7440e1156be> in <module>()
----> 1 import Bio
ImportError: No module named Bio
What am I doing wrong?
EDIT
I tried installing biopython using
sudo easy_install -f http://biopython.org/DIST/ biopython
and it installed it into /usr/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg/. Didn't work.
Then I tried installing it using the same command, without the sudo:
easy_install -f http://biopython.org/DIST/ biopython
which installed it into /home/mike/anaconda/lib/python2.7/site-packages/biopython-1.65-py2.7-linux-x86_64.egg
And that worked! Both for ipython and python. But why did it work...?

One should be very careful when using pip and the like that it is the pip which goes along with the supposed Python interpreter.
I see that you are trying to import Bio from the Python interpreter you get by typing ipython. You can make sure that you invoke the pip of exactly this interpreter like so:
sudo ipython -m pip install biopython
Note that the installation is not exclusive to ipython. It is however exclusive to whatever Python installation ipython is installed on top of.

It's not good practice to sudo pip, since it may install things under root permission, which is usually not granted to ordinary program.
The problem probably lies in library path. The most informative tools will be
import sys
print (sys.path)
and
which python
pip --version
And use pip install biopython --user to replace sudo pip

Related

How do I find and use my imported modules?

I am very new to python, and this is one of my first projects. I now use PyCharm, but started with Anaconda and jupyter notebook. When i try to import a module into my project, i get this error:
import stdiomask
stdiomask.getpass('Password: ')
/Users/Kristoffer/.conda/envs/Prosjekt_beginner/bin/python "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py"
Traceback (most recent call last):
File "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py", line 1, in <module>
import stdiomask
ModuleNotFoundError: No module named 'stdiomask'
After searching the internet for answers, I am still lost, but suspect it has something to do with my pythonpath. Anaconda might also have something to do with it. As I said I just started with python, so I do not know whether this is enough information to solve my problem, but this is what i did:
Checking if the module is installed with both pip and pip 3:
(base) KKWs-MBP-2:~ Kristoffer$ pip install stdiomask
Requirement already satisfied: stdiomask in ./opt/anaconda3/lib/python3.8/site-packages (0.0.6)
(base) KKWs-MBP-2:~ Kristoffer$ pip3 install stdiomask
Requirement already satisfied: stdiomask in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages (0.0.6)
WARNING: You are using pip version 20.2.3; however, version 20.3.1 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m pip install --upgrade pip' command.
And then i checked which version of python I am using and got two different answers.
(base) KKWs-MBP-2:~ Kristoffer$ python
Python 3.8.3 (default, Jul 2 2020, 11:26:31)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
(base) KKWs-MBP-2:~ Kristoffer$ python3
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
I then typed in this in PyCharm and got:
import sys
print(sys.path)
/Users/Kristoffer/.conda/envs/Prosjekt_beginner/bin/python "/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler/modultest.py"
['/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler', '/Users/Kristoffer/Desktop/Pycharm prosjekter/moduler', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python38.zip', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8/lib-dynload', '/Users/Kristoffer/.conda/envs/Prosjekt_beginner/lib/python3.8/site-packages']
So As You Said You are using Anaconda So when you are doing pip3 install stdiomask or pip install stdiomask you are installing it on your real python enviroment & as you mentioned you are using anaconda enviroment,
so give this command conda install stdiomask
Or visit This Website And Read...
I Hope it Helped
Jai Hind Jai Bharat
Unfortunately, when using pip or pip3 to install packages, these are python modules, but also binaries, and using them like:
pip install <package>
or
pip3 install <package>
Doesn't explicitly tell you which interpreter pip is pointing to. However, executing a module using python -m <module> uses the python in your path, and is explicit. You've already seen that the pip -V site-packages is different than your interpreter's site-packages. The way to get around this is to use pip as a module:
python -m pip install <package>
Then you know that you are using the python that you currently have activated

Difficulty installing/importing pyqt5 on ubuntu 18.04

Goal: To import pyqt5 into python3 under Ubuntu 18.04
I know there are many answers to similar questions here and elsewhere. I have tried a lot of them, but I don't see anything that exactly matches my situation.
Starting with a clean installation of Ubuntu 18.04, I have tried many ways to be able to have the statement import pyqt5 succeed in Python 3.6.9, which is the default python3 on this distribution.
None of them have succeeded.
In several attempts, reinstalling Ubuntu anew several times, I have had pip3 either experience a 404 downloading https://pypi.org/simple/python3-pyqt5/ and confirmed the error by pasting the URL into Firefox and also getting a 404. (I also checked the Firefox was working fine accessing the Internet)
But usually I run through a process that seems to indicate that pyqt was loaded successfully but was still unable to import it in Python3.
Among the things I've tried from various web sites are:
pip3 install --upgrade pip
pip3 install pyqt5==5.14.0 vs pip3 install pyqt5 (defaulting to 5.14.1)
installing a simple pypi module and finding that I can import it into Python3 with no problem
running pip3 under sudo
upgrading python3 to Python 3.7.4
A more complete list of what I did starting with the reinstall is shown below.
Any suggestions for solutions or what to look at on my system?
I have a bootable memory stick of Ubuntu 18.04.4 that I created last week by downloading the executable from Ubuntu.com. Everything that's packaged with the release seems to work fine, including Python 3.6.9 in other situations. I do virtually nothing except the following steps.
sudo apt install python3-pip
pip3 install humanfriendly (just to ensure that pip3 works for a simply pypi module)
pip3 install --upgrade pip
pip3 install python3-pyqt5
sudo apt-get install pyqt5-dev-tools (no complaints from pip3 seems to work okay)
sudo apt-get install qttools5-dev-tools (seems to work)
in python3
>>>import pyqt5
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyqt5'
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.0)
pip3 install pyqt5 --user (Successfully installed pyqt5-5.14.1
Try to import in python3 again, same result: "No module named 'pyqt5'"
cd ~/.local/bin
ls
humanfriendly pip pip3 pip3.6 pylupdate5 pyrcc5 pyuic5
(there seems not to be an entry for pyqt5 although there is for some of its stand-alone componentes)
pip3 uninstall pyqt5
ls
humanfriendly pip pip3 pip3.6
(what was there went away)
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.1)
pip3 install pyqt5 --user (seems to succeed)
try to import in python3 (same error)
pip3 uninstall pyqt5 (Successfully uninstalled PyQt5-5.14.1)
next I tried sudo pip3 uninstall pyqt5
seems to work; not importable in python3; sudo pip3 uninstall
next I created a virtual env, ~/.vents/tevs
activate the venv
pip3 install pyqt5==5.14.0
Installing collected packages: PyQt5-sip, pyqt5
attempt to import pyqt5 in python3: fails as before
pip3 uninstall pyqt5
(Successfully uninstalled PyQt5-5.14.0 after listing thousands of files
in .venvs/tevs/lib/python3.6/site-packages/PyQt5)
pip3 install python3-pyqt5
(fails with HTTP Error: 404 Client Error:
Not Found for url: https://pypi.org/simple/python3-pyqt5/)
Several problems should be noted in what the OP notes:
The name of the library does not necessarily match the name of how to import the libraries, on the other hand pip accepts names like pyqt5 and PyQt5 as equivalent, but when you import it you should use PyQt5, not pyqt5, so to test that you have installed you can do the following:
Run on the console:
$ python3 -c "from PyQt5.Qt import PYQT_VERSION_STR; print(PYQT_VERSION_STR)"
5.14.1
Run on python console:
Python 3.8.1 (default, Jan 22 2020, 06:38:00)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.Qt import PYQT_VERSION_STR
>>> print(PYQT_VERSION_STR)
5.14.1
python3-pyqt5 is the name of the package that offers ubuntu repositories for the version of pyqt5 that your community compiles which is generally a non-current version. So to install pyqt5 there are several methods:
Using ubuntu repository: sudo apt-get install python3-pyqt5
Using pip: python3 -m pip pyqt5 (You must use sudo if required) or python3 -m pip install pyqt5 --user (This method also applies to virtualenv)
So I can conclude that the OP has successfully installed PyQt5 but has failed to verify if the installation has been correct so I recommend using what is indicated in (1)
I recently encountered this problem on Ubuntu 20.04 and here is what worked for me.
Firstly, after trying much of what you described I finally decided to run python --version from terminal and the output told me that python 2.7 was the default version on my system. This was the problem.
Secondly, after thinking "sheeeee-*t partner", I checked for any python2 dependencies using apt rdepends python --installed.
Lastly, after confirming that I had no python2 dependencies, I ran sudo apt-get install python-is-python3 in order to make python3 the default version.

Python : setuptools module is already installed but still shows import error

I am trying to install something using "python setup.py install" but it shows me this error :-
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup
ImportError: No module named setuptools
I have installed this missing module using "pip install setuptools". But still it shows me the same error .I have also tried to install this using "sudo apt-get install python-setuptools" but the problem still remains the same. Help me in this issue
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:
On Linux or macOS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see link

Python 3.4 pip install

I am trying to install the xlrd module on my Mac, however when I open IDLE and import the xlrd module, I get the error:
Input Error: No module named xlrd
To install it, I used in my home directory...
sudo pip install xlrd
... and it is installed successfully.
Note that I have both Python 2.7 and Python 3.4.0 on my computer, in case this is what is causing problems. I want it installed for Python 3.4.0.
To avoid conflicts between parallel Python 2 and Python 3
installations, only the versioned pip3 and pip3.4 commands are
bootstrapped by default
You can try sudo pip3 install xlrd or sudo pip3.4 install xlrd to use the Python 3.4, see docs here https://docs.python.org/3/whatsnew/3.4.html#bootstrapping-pip-by-default

Python can't find module NLTK

I followed these instructions http://www.nltk.org/install.html to install nltk module on my mac (10.6)
I have installed python 2.7, but when I open IDLE and type import nltk it gives me this error
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import nltk
ImportError: No module named nltk
The problem is the module is installed in another python version, 2.6. How can I install the package in python version 2.7? I tried some of the solutions suggested in various answers, for example I tried typing this in the terminal
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages
and then installed NLTK again with the command
sudo pip install -U nltk
but I get the message: Requirement already up-to-date in /Library/Python/2.6/. So apparently the command line export PYTHONPATH didn't do anything (it still tries to install the package in 2.6) OR (more likely) I didn't understand the meaning/functioning of that command line. What am I doing wrong?
On OS X you could have multiple installation of Python, so investigate it first:
$ which python python2 python3
/usr/bin/python
/usr/local/bin/python3
$ which pip pip2 pip3
/usr/local/bin/pip
/usr/local/bin/pip2
/usr/local/bin/pip3
All within /usr/bin are built-in and all other in /usr/local/bin are external installed by Homebrew or some other package manager.
If you're using pip or pip3 from /usr/local, then you've to use the same Python instance, otherwise they're different instances.
Just install it via pip:
pip install nltk
or for Python 3:
pip3 install nltk
then run the right Python instance from /usr/local/bin or update your PATH system variable.
Make sure you install the actual Python for Mac, not the one built into the console. Then, install pip by executing this script. Then skip to part 3 of the instructions and go from there.
Try this
pip install --user -U nltk
On my mac I had two different versions of Python 3 installed: Python 3.6 and Python 3.7. I had installed nltk having Python 3.7 in my $PATH:
$ pip3 install nltk
$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
But nltk was missing for Python 3.6. Solution: install nltk also for version 3.6.
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ pip3 install nltk
Collecting nltk
Using cached https://files.pythonhosted.org/packages/6f/ed/9c755d357d33bc1931e157f537721efb5b88d2c583fe593cc09603076cc3/nltk-3.4.zip
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from nltk) (1.12.0)
Collecting singledispatch (from nltk)
Using cached https://files.pythonhosted.org/packages/c5/10/369f50bcd4621b263927b0a1519987a04383d4a98fb10438042ad410cf88/singledispatch-3.4.0.3-py2.py3-none-any.whl
Installing collected packages: singledispatch, nltk
Running setup.py install for nltk ... done
Successfully installed nltk-3.4 singledispatch-3.4.0.3
I would use a virtualenv, but if you really want to use it from the terminal, I'd recommend adding your export statement to ~/.bashrc
Just restart Jupyter Notebook or anything you are using after installing...
It works...
In my case, the following command worked for me. Try this!!
py -3 -m pip install nltk
I had a similar issue an an Intel MacBook.
Fixed with
Make sure the python bin directory in the path
mine is /Users/<user>/Library/Python/3.9/bin
Restart the computer
NOTE that just restarting the terminal did NOT help

Categories

Resources