configure pip, give it python interpreter - python

I am new to python. I have installed pip and it have python2.4 interpreter,
I want to give pip newer version of python interpreter.
how can I do that on Unix system?
I am trying this:
pip --environment=/usr/lib/python2.6/site-packages/
but it not works.
thanks in advance!

Alternative to pip you can also run pip2.x and pip3.y (for python2.x and 3.y respectively)

Related

Homebrew not installing the correct version of Python

I was trying to install Python 3.7 using homebrew with "brew install python". When I check the version of python installed, I get python 2.7.10. Anyone know how to fix this?
Most likely you need to call python 3.7 commands with
python3
and install packages with
pip3
as well, also check your $PATH configuration, as is it usually takes the OSx python as default in Macs

Pip install location

I have python2.7 and python3.6 installed side by side in my computer. Now when I install a package using "pip install", how can I know in which python's site-packages is my package going to be installed?
Thank you.
When you have both version 2 and 3 installations pip and pip3 differentiate the target installtion.
For installing anything on Python 3(versions 3.5 and above) use pip3
for Python 2.7 use pip
Make sure python path is set in environment variables too.
also you can use where pip or which pip as #mshsayem mentioned.
Additional Reference
if you use virtualenv, the modules are located in:
{path_to_your_virtualenv}/lib/python{your_python_version}/site-packages/
and if you don't use virtualenv, normally are installed in:
/usr/local/lib/python{your_python_version}
You have to use pip3 for install python3 modules.
Check where a specific package is installed by:
pip3 show <package_name>
List all installed packages with install locations by:
pip3 list -v
Check the install location used by default when installed without sudo:
pip3 --version
and the location for packages installed with sudo, meaning system-wide installation:
sudo pip3 --version
You can find the location of pip by which pip. Then you view the pip executable header using head `which pip` or using your preferred editor. You can find the python interpreter location on the first line. You may have a pip2 and a pip3 executable.
By the way, you can run pip as a python module by python -m pip <command>. In this way, you can specify your python interpreter.
The answer to you question is divided to two parts:
1. Which python version the native terminal selects for me?
2. How do I specify which python version to use?
Which python version the native terminal selects for me?
In windows, the default pip that will be used is the one associated with the default python version you use. You can edit it in the PATH environmental variable (Start->find-type "Environmental" and click "Edit system variables"). Look the PATH variable and see which version of python is listed. If both versions are listed, windows will select the first.
See more information on system environmental variables here.
In Ubuntu/Linux, usually pip is associated with the native legacy version (2.7), pip3 is associated with Python3.5.x and pip3.6 is associated with Python3.6.x.
However, if you are using Unix OS (such as Ubuntu) or Mac, it is highly recommended to use virtualenv and activate it. See Official documentation to see how to use it. It's true for both Python2.7 and
Python3.6. In short, you will create a lightweight copy of you python installation without any packages, and, your installed packages will be installed within this virtual environment. Once you activate a virtual environment, the pip is associated with this environment.
How do I specify which python version to use?
You have multiple choices to specify in which environment you want to install the package. It depends if you are on Windows/Linux/MAC.
Shortly, you have the following options:
Use an IDE and let it help you manage your packages (e.g. Pycharm). Using PyCharm, you will find it very easy to use its package manager. You can also open the IDE's terminal and when you use pip, it will use the package manager of the selected interpreter. See official documentation.
Use OS native terminal and specify the version. In windows, the easiest way is to go to a command line or powershell, and type "c:\path\to\python.exe -m pip install ". On Ubuntu, use pip/pip3/pip3.6. Again, on Ubuntu it is highly recommended to use venv (virtual environment) since installing wrong package on the wrong version can interrupt the native python (Ubuntu uses python for multiple reasons such as the GNOME GUI).
Use virtual environments. You can look it up, there are plenty of threads explaining on that, as well as the Official documentation.

Run Python 3.6 in Terminal on Mac?

I am using a Python on a Mac and I know that Python 2 comes preinstalled on the system (and in fact usable through Terminal). Is there a way to make it so Terminal can run Python 3? Can/should you set this as a default? I know changing the default settings for Python version usage could break your system so should I just install Python 3 and then use it through its launch icon instead?
Use can use python version management tool
https://github.com/yyuu/pyenv
Package manager:
pip3 install something
Interpreter:
python3
You can use python 3 in terminal after you have python 3 installed. Every time you run a command type python3 instead of python if you are using pip to install modules you can do this:
But you must have pip installed for python 3
$ python3 -m pip install something
Best option is to install Python through Anaconda. This allows easy management and much more. You can have virtual environments having different Python versions as well as different modules installed.
as usual in Mac python 2.7 is already installed, however if you installed python 3+
then you can just type in terminal: python3
so that you can use the newer version that you installed.
if you want to use python 2.7 then just type: python

Does the python.org installer of python come with pip, and how do I use it?

I can download python 2.7.12 from python.org, and all python versions from 2.7.9 onwards are supposed to come with pip, but after installing it, using pip in the terminal does not work.
I am on macOS.
Have I installed pip, and if I have, how do I use it?
Here you have informations about pip:
https://packaging.python.org/installing/
normally python from python.org come with pip, maybe you should just update...
to update from terminal:
pip install -U pip setuptools
After when you need to install package, for example numpy, just do in a terminal:
pip install numpy
more informations here :
https://pip.pypa.io/en/stable/reference/pip_install/
you can also use conda install from anaconda as an alternative of pip :
http://conda.pydata.org/docs/get-started.html
Multiple instances of Python can coexist on your machine. Thus you could have installed Python 2.7.12 yet, when you call Python from terminal, you may be calling an older version.
To know which version you are using, type which python in terminal and look at its path. Then from Python in terminal, type
import sys
print(sys.version)
to get the exact version.
As Dadep says, I would recommend using conda to isolate your invironments if you have to play with multiple Python interpreters. Further conda simplifies 3rd party package installation process beyond doubt.

Python running setup.py through cmd doesn't work?

So I'm trying to install via cmd using a setup.py file..
However, when I try to install it through CMD, this happens:
The first way you were trying to install it is correct python setup.py install, however you need Python 2.x for this installer to work. You are in a Python 3.2 environment and it appears that this module has not been updated to work with Python3 at this time.
http://ocemp.sourceforge.net/manual/installation.html
The print bdist.bdist_base, self.install_dir statement is Python 2.x syntax. If it were compatible with Python3, it would be print(bdist.bdist_base, self.install_dir)
----------
If you require development in both Python3 and Python2, I highly recommend installing Anaconda
https://www.continuum.io/downloads
You can set up multiple environments with whatever versions of Python that you want. Then you can activate each one as necessary.
http://conda.pydata.org/docs/py2or3.html

Categories