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
).
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>
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.
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]
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With