Install library packages for other python version - python

I have installed the two python versions v2.7 and v3.7 on the same machine. I want to install the some packages for Python 3.7 when i am trying to install it installing for python2.7. Can any one help here how can i install the packages for python3.7.
Installed /usr/lib/python2.7/site-packages/configlib-2.0.4-py2.7.egg
Processing dependencies for configlib==2.0.4
Searching for everett==0.9
Reading https://pypi.python.org/simple/everett/
[root#nodehost configlib-2.0.4]# /usr/local/lib/python3.7 setup.py install
bash: /usr/local/lib/python3.7: Is a directory
[root#nodehost configlib-2.0.4]#

A more elegant solution is to create a separate environment for different python. Anaconda is the way to go. It is free and it installs many everyday libraries already.
Download and install the python 3.7 version. And then create a python 2 version is simple:
conda create -n py27 python=2.7
Every time you need the 2.7, just
conda activate py27
And then you can install libraries there just for 2.7, without messing up your 3.7. Vice versa for 3.7.

You should be able to choose your Python version with the two following commands:
>> python --version
Python 2.7
>> python3 --version
Python 3.7
If this works, just call pip like so:
>> python3 -m pip install everett

Related

How to install brownie on mac os running both python 2.7 and 3.9 [duplicate]

I am trying to get python 3 working on my OSX laptop.
I need to install requests for python 3, and it isn't working.
I think I've managed to get pip installed for both python 2.7 & python 3 however...
Whenever I use 'pip' it points to python2... I can't seem to access the pip for python 3?
In all likelihood, pip3 will be installed pointing to your Python 3 installation, so your use case is probably solvable by just switching from:
$ pip install foo
to:
$ pip3 install foo # Or pip3.7 install foo if you need to disambiguate further
That said, it can get kind of complicated when you have many different Python installs, where pip/pip3 might have been installed pointing to a Python version that doesn't correspond to the python/python3 you're using, which can be quite confusing.
If you know python & python3 are the correct executable, just use it to invoke pip on your behalf. It's fairly easy too, just check your version to be sure it's the one you expect (e.g. on my system):
$ python --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.6
then use the appropriate one with -mpip, a flag to run an installed module/package via the chosen Python as the "main" executable, bypassing the need for specifically versioned pip executable entirely. So if you wanted to install foo for Python 3.6 on my machine, you'd run:
$ python3 -mpip install foo
This is especially useful on Windows, where the pip executables often either don't exist, or are not installed in the PATH, so it's irritating to use them. Instead, use the Windows launcher that comes with any modern Python 3 version (but manages all Python versions on the machine), and is used to disambiguate among various versions. For example:
C:\>; Installs foo for latest installed version of Python 3
C:\>py -3 -mpip install foo
C:\>; Installs foo for latest installed version of Python 2
C:\>py -2 -mpip install foo
C:\>; Installs foo for latest installed version of Python 3.6
C:\>py -3.6 -mpip install foo
Essentially, any use of pip can be replaced by executing the Python interpreter directly with the -mpip option to run the pip package as the "main" executable.
This trick applies to many other tools with dedicated launchers that are often not installed in the PATH, particularly on Windows, and it makes updates easier too; my Windows shortcut for launching ipython3 never used a hardcoded path to the launcher (e.g. C:\Program Files\Python36\Scripts\ipython3.exe), instead using %WINDIR%\py.exe -3 -mIPython. In addition to being more portable (the shortcut "just works" on any Windows system with a semi-recent Python 3 install), it's self-updating; when I upgraded from 3.6 to 3.7, the shortcut didn't have to change at all (I had to run py -3 -mpip install ipython again to get IPython reinstalled, but once I'd done that, the shortcut seamlessly began referring to the 3.7 install with no changes needed).
Run this command to find the python that is used before running pip: which python. You can do the same idea to find which pip version is being run: which pip
You’ll need to create separate virtual environments in order to use different python versions and/or python dependencies. Use something like conda or venv to do this. Then, ensure that the desired python version virtual environment is activated prior to installing a new package with pip.
To install requests for python3, use pip3 install requests which is the pip installer for Python 3 modules.
This guide has some further info on getting Python 3 working on a mac.
https://docs.python-guide.org/starting/install3/osx/
try to sudo apt-get update first then sudo apt-get install python3-pip --fix-missing

How to use pip with python 2 & 3 installed? (OSX)

I am trying to get python 3 working on my OSX laptop.
I need to install requests for python 3, and it isn't working.
I think I've managed to get pip installed for both python 2.7 & python 3 however...
Whenever I use 'pip' it points to python2... I can't seem to access the pip for python 3?
In all likelihood, pip3 will be installed pointing to your Python 3 installation, so your use case is probably solvable by just switching from:
$ pip install foo
to:
$ pip3 install foo # Or pip3.7 install foo if you need to disambiguate further
That said, it can get kind of complicated when you have many different Python installs, where pip/pip3 might have been installed pointing to a Python version that doesn't correspond to the python/python3 you're using, which can be quite confusing.
If you know python & python3 are the correct executable, just use it to invoke pip on your behalf. It's fairly easy too, just check your version to be sure it's the one you expect (e.g. on my system):
$ python --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.6
then use the appropriate one with -mpip, a flag to run an installed module/package via the chosen Python as the "main" executable, bypassing the need for specifically versioned pip executable entirely. So if you wanted to install foo for Python 3.6 on my machine, you'd run:
$ python3 -mpip install foo
This is especially useful on Windows, where the pip executables often either don't exist, or are not installed in the PATH, so it's irritating to use them. Instead, use the Windows launcher that comes with any modern Python 3 version (but manages all Python versions on the machine), and is used to disambiguate among various versions. For example:
C:\>; Installs foo for latest installed version of Python 3
C:\>py -3 -mpip install foo
C:\>; Installs foo for latest installed version of Python 2
C:\>py -2 -mpip install foo
C:\>; Installs foo for latest installed version of Python 3.6
C:\>py -3.6 -mpip install foo
Essentially, any use of pip can be replaced by executing the Python interpreter directly with the -mpip option to run the pip package as the "main" executable.
This trick applies to many other tools with dedicated launchers that are often not installed in the PATH, particularly on Windows, and it makes updates easier too; my Windows shortcut for launching ipython3 never used a hardcoded path to the launcher (e.g. C:\Program Files\Python36\Scripts\ipython3.exe), instead using %WINDIR%\py.exe -3 -mIPython. In addition to being more portable (the shortcut "just works" on any Windows system with a semi-recent Python 3 install), it's self-updating; when I upgraded from 3.6 to 3.7, the shortcut didn't have to change at all (I had to run py -3 -mpip install ipython again to get IPython reinstalled, but once I'd done that, the shortcut seamlessly began referring to the 3.7 install with no changes needed).
Run this command to find the python that is used before running pip: which python. You can do the same idea to find which pip version is being run: which pip
You’ll need to create separate virtual environments in order to use different python versions and/or python dependencies. Use something like conda or venv to do this. Then, ensure that the desired python version virtual environment is activated prior to installing a new package with pip.
To install requests for python3, use pip3 install requests which is the pip installer for Python 3 modules.
This guide has some further info on getting Python 3 working on a mac.
https://docs.python-guide.org/starting/install3/osx/
try to sudo apt-get update first then sudo apt-get install python3-pip --fix-missing

Managing Python Versions

So, for some reason, I have way too many versions of python on my Mac.
Running python in the terminal gets me Python 2.7.10.
python2 gets me Python 2.7.14.
python2.7 gets me 2.7.13.
python2.6 gets me 2.6.9.
python3 gets me 3.6.3.
python3.6 gets me 3.6.3 again. Not sure if this is a separate install or not.
python3.4 gets me 3.4.7.
So I have 6, possibly 7 versions of Python. And I have no idea what to do.
As for pip, I have the following installed: pip, pip2, pip2.6, pip2.7, pip3, and pip3.6.
Some of these versions of Python were shipped with the OS, and others were installed with Homebrew.
So it's a terrifying, yet sort of hilarious mess I've gotten myself into. How can I better manage my versions? Most of the versions installed I do not use, but can't remove them because they are part of the system. So how can I make my Python versions less of a pain?
I recommend looking into pyenv, it makes managing multiple versions of Python much easier. With the virtualenv plugin life gets even better. With both installed you can do something like this:
pyenv install 2.7.13
pyenv install 3.5.1
pyenv install 3.6.3
pyenv virtualenv 2.7.13 proj1
pyenv virutalenv 3.6.3 proj2
pyenv activate proj2
python -V # 3.6.3
pyenv activate proj1
python -V # 2.7.13
And of course each project now has its own clean virtual environment you can install packages in with pip.

Dealin with different Python versions using Pip (Mac OS X 10.9.5)

I'm dealin with installation problems for python 3.4 using Pip.
I have python versions 3.4(.3) and 2.5, 2.7
When i pip install a package, it will only be available on 2.7
I found a 'solution' on :
pip: dealing with multiple Python versions?
But seems not to work, maybe outdated..
FWIW, since it sounds like you have Anaconda and had trouble installing boto3, here's my workflow:
conda create -n myenv python=3.4 anaconda
Leave out anaconda if you want a completely clean Python-only environment. Substitute myenv for whatever name you like. Now activate:
source activate myenv
...and install boto3:
pip install boto3
That works for me.

python: install two versions of same module

To be more precise, I need to install two versions of Pandas. On one hand, I'm writing codes to be run on a server with pandas 0.13. All other part of my work, I want up-to-date pandas and other modules (0.16.1 for now).
The two projects are not connected and I won't need two versions in one program.
Is there a way to do that?
Edit: I'm using Python 2.7.8 with Anaconda under Windows
The best method is virtualenv. Virtualenv is a tool to create isolated Python environments.
http://virtualenv.readthedocs.org/en/latest/
I would highly recommended miniconda, which is the smaller version of Anaconda. Conda is a package manager which makes installing scientific libraries such as Scipy and Numpy easy. To get it, just install the Miniconda installer.
“Miniconda” only contains Python and conda, and is much smaller than
a full Anaconda installer. There are two variants of the installer:
Miniconda is based on Python 2, while Miniconda3 is based on Python 3.
Once Miniconda is installed, you can use the conda command to install
any other packages and create environments (still containing any
version of Python you want). If you have a slow internet connection or
limited disk space, Miniconda is the way to go.
It is fast to install packagaes such as Pandas and Numpy because many have been precompiled.
On OS X, the latest Python 2 version can be found here and is installed as follows:
$ bashMiniconda-latest-MacOSX-x86_64.sh -p /usr/local/miniconda -b
$ export PATH=/usr/local/miniconda/bin:$PATH
$ which conda
/usr/local/miniconda/bin/conda
$ conda --version
conda 3.7.0
Once Miniconda is installed, you can use the conda command to install any other packages and versions, and create environments, etc. For example:
$ conda install pandas=0.16.0
...
$ conda create -n py3k anaconda python=3
...
Two versions of the same package cannot run simultaneously, so I would recommend setting up a copy of your existing environment and then installing the desired version.
conda list will show all of your installed packages.
Use pkg_resourcesto force the version:
import pkg_resources
pkg_resources.require("YOUR_PACKAGE==VERSION")
import YOUR_PACKAGE

Categories