How do I install a pip package globally instead of locally?

PythonPip

Python Problem Overview


I am trying to install flake8 package using pip3 and it seems that it refuses to install because is already installed in one local location.

How can I force it to install globally (system level)?

pip3 install flake8
Requirement already satisfied (use --upgrade to upgrade): flake8 in ./.local/lib/python3.4/site-packages

Please note that I would prefer a generic solution (that should work on Debian, OS X maybe even Windows), one that should be used on any platform so I don't want to specify the destination myself.

For some weird reason it behaves like I already specified --user which in my case I didn't.

The only way I was able to install a package globally was to first remove it and install it again after this. Somehow it seems that pip (8.1.1) refuses to install a package globally if it exists locally.

Disclaimer: No virtual environments were used or harmed during the experiments.

Python Solutions


Solution 1 - Python

Why don't you try sudo with the H flag? This should do the trick.

sudo -H pip install flake8

A regular sudo pip install flake8 will try to use your own home directory. The -H instructs it to use the system's home directory. More info at https://stackoverflow.com/a/43623102/

Solution 2 - Python

Maybe --force-reinstall would work, otherwise --ignore-installed should do the trick.

Solution 3 - Python

> Where does pip installations happen in python?

I will give a windows solution which I was facing and took a while to solve.

First of all, in windows (I will be taking Windows as the OS here), if you do pip install <package_name>, it will be by default installed globally (if you have not activated a virtual enviroment). Once you activate a virtual enviroment and you are inside it, all pip installations will be inside that virtual enviroment.


> pip is installing the said packages but not I cannot use them?

For this pip might be giving you a warning that the pip executables like pip3.exe, pip.exe are not on your path variable. For this you might add this path ( usually - C:\Users\<your_username>\AppData\Roaming\Programs\Python\ ) to your enviromental variables. After this restart your cmd, and now try to use your installed python package. It should work now.

Solution 4 - Python

For the Windows case:

Are you using virtualenv? If yes, deactivate the virtualenv. If you are not using a venv, the package should have already be installed on system level (system-wide). In that case, try to upgrade the package.

pip install flake8 --upgrade

Solution 5 - Python

For windows 10:

Installing Python for all users is straight forward since when you install you have to click a checkbox for all users.

In order to install modules globally under C:\Program Files\Python310\Lib\site-packages start CMD prompt as administrator and then install modules

python -m pip install selenium

Solution 6 - Python

I actually don‘t see your issue. Globally is any package which is in your python3 path‘s site package folder.

If you want to use it just locally then you must configure a virtualenv and reinstall the packages with an activated virtual environment.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsorinView Question on Stackoverflow
Solution 1 - PythonnikhilweeeView Answer on Stackoverflow
Solution 2 - PythonEmmaView Answer on Stackoverflow
Solution 3 - PythonuinstinctView Answer on Stackoverflow
Solution 4 - PythonMauro BaraldiView Answer on Stackoverflow
Solution 5 - PythonAaj KaalView Answer on Stackoverflow
Solution 6 - PythonLITView Answer on Stackoverflow