Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip/python: normal site-packages is not writeable

Tags:

python

pip

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).

like image 952
lowercase00 Avatar asked Jan 31 '20 02:01

lowercase00


People also ask

How do I uninstall a pip package?

To use pip to uninstall a package locally in a virtual environment: Open a command or terminal window (depending on the operating system) cd into the project directory. pip uninstall <packagename>

Where are Python packages installed?

When a package is installed globally, it's made available to all users that log into the system. Typically, that means Python and all packages will get installed to a directory under /usr/local/bin/ for a Unix-based system, or \Program Files\ for Windows.


2 Answers

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] 
like image 76
Dammio Avatar answered Sep 23 '22 02:09

Dammio


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.

like image 34
Chris Johnson Avatar answered Sep 20 '22 02:09

Chris Johnson