SubhasisM
SubhasisM

Reputation: 352

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.

Upvotes: 9

Views: 48720

Answers (5)

Antonio
Antonio

Reputation: 324

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

Upvotes: 3

mr_mo
mr_mo

Reputation: 1528

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.

Upvotes: 0

Baurin Leza
Baurin Leza

Reputation: 2104

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.

Upvotes: 3

Morse
Morse

Reputation: 9124

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

Upvotes: 5

zguangyu
zguangyu

Reputation: 56

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.

Upvotes: 1

Related Questions