On Ubuntu 10.04 by default Python 2.6 is installed, then I have installed Python 2.7. How can I use pip install
to install packages for Python 2.7.
For example:
pip install beautifulsoup4
by default installs BeautifulSoup for Python 2.6
When I do:
import bs4
in Python 2.6 it works, but in Python 2.7 it says:
No module named bs4
I faced a similar problem with another package called Twisted. I wanted to install it for Python 2.7, but it only got installed for Python 2.6 (system's default version).
Making a simple change worked for me.
When adding Python 2.7's path to your
$PATH
variable, append it to the front like this:PATH=/usr/local/bin:$PATH
, so that the system uses that version.If you face more problems, you can follow this blog post which helped me - https://github.com/h2oai/h2o-2/wiki/installing-python-2.7-on-centos-6.3.-follow-this-sequence-exactly-for-centos-machine-only
In Windows, you can execute the pip module by mentioning the python version ( You need to ensure that the launcher is on your path )
Use a version of
pip
installed against the Python instance you want to install new packages to.In many distributions, there may be separate
python2.6-pip
andpython2.7-pip
packages, invoked with binary names such aspip-2.6
andpip-2.7
. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).pip's website includes installation instructions, if you can't find anything within your distribution.
For Python 3
For Python 2
You can use this syntax
For example. If you're running python3.5, you named it as "python3", and want to install numpy package
Alternatively, if you want to install specific version of the package with the specific version of python, this is the way
if the "=" doesnt work, use ==
x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev=0.16
Invalid requirement: 'pyudev=0.16' = is not a valid operator. Did you mean == ?
x@ubuntuserv:~$ sudo python2.7 -m pip install pyudev==0.16
works fine