pip/python: normal site-packages is not writeable

PythonPip

Python Problem Overview


I have a new Macbook - a user installed it, and then I installed a new user (mine), granted admin privileges and deleted the old one. I am on OS Catalina.

Since the installation I've been having several permission problems. VSCode can't find Jupyter Notebook, pip installs packages at ~/Library/Python/3.7/site-packages.

When I do which python3 I get usr/bin/python3. When I do pip3 install <package> I get: Defaulting to user installation because normal site-packages is not writeable And then it says it has already been installed, even though I can't access it when I do import <package>.

It's seems clear that this is a permission problem, pip can't install to the "base" python, and them python can't find what I've installed into ~/Library/Python/3.7/site-packages.

I've tried reinstalling the OS, but since I haven't done a clean install, it didn't change anything. What am I missing? How exactly can I fix permissions? Where do I want packages to be installed (venv sure, but some packages I want global (like jupyter).

Python Solutions


Solution 1 - Python

As @TomdeGeus mentioned in the comments, this command works for me:

Python 3:

python3 -m pip install [package_name]

Python 2:

python -m pip install [package_name]

Solution 2 - Python

It's best to not use the system-provided Python directly. Leave that one alone since the OS can change it in undesired ways, as you experienced.

The best practice is to configure your own Python version(s) and manage them on a per-project basis using virtualenv (for Python 2) or venv, possibly via poetry, (for Python 3). This eliminates all dependency on the system-provided Python version, and also isolates each project from other projects on the machine.

Each project can have a different Python point version if needed, and gets its own site_packages directory so pip-installed libraries can also have different versions by project. This approach is a major problem-avoider.

Solution 3 - Python

python3.7 -m pip install [package_name]

(you should use the version that you have, of course)

solved it for me.

The most voted answer python3 -m pip install [package_name] does not help me here.

In my case, this was caused by a conflict with the dominating 3.6 version that was also installed as a default. You might ask yourself why you have 3.6 on your system, you will most probably not use that version now. The reason is that 3.6 is used as an independent default python version for many package installers. Those installers do not want to check which individual version you use and whether that fits, they just use 3.6 as a default, if you like it or not.

Here is a proof by example --upgrade pip:

pip3 install --upgrade pip

> Defaulting to user installation because normal site-packages is not writeable
> Requirement already satisfied: pip in > /home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)

python3 -m pip install --upgrade pip

> Defaulting to user installation because normal site-packages is not writeable
> Requirement already satisfied: pip in > /home/USERNAME/.local/lib/python3.6/site-packages (20.3.1)

python3.7 -m pip install --upgrade pip

> Collecting pip
> Cache entry deserialization failed, entry ignored
> Using cached https://files.pythonhosted.org/packages/ab/11/2dc62c5263d9eb322f2f028f7b56cd9d096bb8988fcf82d65fa2e4057afe/pip-20.3.1-py2.py3-none-any.whl
> Installing collected packages: pip Successfully installed pip-20.3.1

Solution 4 - Python

> sudo pip install

Worked for me. But pip install is not recommended to be run with sudo. The issue I was facing on BIGSUR was, it was using system python. Once I Installed python 3.9 using

> brew install [email protected]

Then pip worked fine

Solution 5 - Python

It occurs with me when I the virtual enviroment folder name was : venv.

in this case, It gives errors like :

No module pip

Default folder is unwritable

renaming the folder solve the proplem.

Solution 6 - Python

I'm using Anaconda on Ubuntu and had the same problem.I fixed it by the following steps:

deactivating current environment

conda deactivate

Then, the base environment activates. I deactivated the base conda environment too. To do so, I used conda deactivate again.

Finally, I activate my project environment directly (instead of activating from the base environment) by the following command. Afterward, I installed the intended package successfully and worked perfectly.

conda activate myenv
pip install somepackage

Solution 7 - Python

For readers in 2022 who thought themselves accidentally update system pip:

If you saw this info in your terminal output:

Defaulting to user installation because normal site-packages is not writeable

then you will be fine. Use the pip3 you just updated to run:

pyenv global system # since I use pyenv
pip3 uninstall pip # this one does the trick

Then you can check again pip3 --version will point to the original old (XCode/System-)pip. E.g. (2022/2/28):

pip 20.2.3 from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages/pip (python 3.8)

Solution 8 - Python

Had this same issue on a fresh install of Debian 9.12. Rebooting my server solved the issue.

Solution 9 - Python

In my case on Linux, the ownership of the conda env directory had changed to another Linux user (long story), and so the the normal site-packages was not writeable due to a permissions issue.

The solution was to change ownership back to the user doing pip install.

Solution 10 - Python

I met exactly the same issue.

I just type sudo python3.8 -m pip install .... and the error disappeared.

If I remove the sudo, issue remains.

Solution 11 - Python

in my case python3 -m pip install [package_name] did not solve that. in my case, it was a problem related to other processes occupying the directory. I restart Pycharm and close any other program that might occupy this folder, and reinstalled the package in site-packages directory successfully.

Solution 12 - Python

When this problem occurred to me I have tried all the mentioned approaches but they don't seem to work.

Instead, restarting Python language server in my VSCode did the job - my SimPy package is now found. On Mac it is Cmd+Shift+P and select "Python: Restart Language Server".

Solution 13 - Python

Had similar issue on Ubuntu 20.04.4 LTS in VirtualBox, but none of the suggestions here worked for me.

I was trying to install open3d in a venv and every time I was getting "Defaulting to user installation because normal site-packages is not writeable" which at first I didn't even noticed. open3d was always being installed in /usr/bin/python3 environment. I've restarted the VM but without luck, so I guess the problem was not just missing write access.

So in VS Code, which was using the venv, importing open3d was not possible. But testing from terminal from the activated venv with python3 -c "import open3d as o3d; print(o3d.__version__)" was working fine and that confused me totally. I even broke my system pip installation using sudo, see further below if you want to know how to fix it.

Anyhow, the solution to my problem was to explicitly point to the python3 file in the venv where I wanted to install the package:

venv/bin/python3 -m pip install open3d

So I was testing out everything and eventually installed with sudo: sudo pip3 install open3d. This of course didn't solved the problem and open3d was still missing in the venv. Even worse, I got the message:

"WARNING: You are using pip version 21.3.1; however, version 22.0.4 is available. You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command."

So I did it but with sudo, updating the system pip and then found out here that this is not good:

WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

Following an advice here, I tried to revert to original version, only then pip3 broke:

sudo pip3 uninstall pip
sudo pip3 --version
sudo: pip3: command not found

The apt package was still there:

> sudo apt install python3-pip python3-pip is already the newest version > (20.0.2-5ubuntu1.6).

So I had to reinstalled to fix the problem:

sudo apt-get remove python3-pip
sudo apt install python3-pip

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
Questionlowercase00View Question on Stackoverflow
Solution 1 - PythonDammioView Answer on Stackoverflow
Solution 2 - PythonChris JohnsonView Answer on Stackoverflow
Solution 3 - Pythonquestionto42standswithUkraineView Answer on Stackoverflow
Solution 4 - PythonShreehariView Answer on Stackoverflow
Solution 5 - PythontabebqenaView Answer on Stackoverflow
Solution 6 - PythonPayam Jome YazdianView Answer on Stackoverflow
Solution 7 - PythonVimNingView Answer on Stackoverflow
Solution 8 - PythonChris SView Answer on Stackoverflow
Solution 9 - PythonshanebView Answer on Stackoverflow
Solution 10 - PythonsmwikipediaView Answer on Stackoverflow
Solution 11 - PythonEliav LouskiView Answer on Stackoverflow
Solution 12 - Python0xTomatoView Answer on Stackoverflow
Solution 13 - PythonMihail ValchevView Answer on Stackoverflow