pip/python:正常的站点包不可写 [英] pip/python: normal site-packages is not writeable
问题描述
我有一台新的Macbook-一个用户安装了它,然后我安装了一个新用户(我的),授予管理员权限并删除了旧的Macbook.我在OS Catalina上.
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.
自安装以来,我一直遇到一些权限问题.
VSCode找不到Jupyter Notebook,pip
在~/Library/Python/3.7/site-packages
处安装软件包.
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
.
当我执行which python3
时,我得到usr/bin/python3
.
当我执行pip3 install <package>
时,我得到:Defaulting to user installation because normal site-packages is not writeable
然后它说它已经安装了,即使我执行import <package>
时无法访问它.
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>
.
很明显这是一个权限问题,pip
无法安装到基本" python,并且它们python
找不到我已安装到~/Library/Python/3.7/site-packages
的内容.
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
.
我尝试重新安装操作系统,但是由于我没有进行全新安装,因此它没有任何改变.
我想念什么?
我到底该如何修复权限?我在哪里想要软件包安装(肯定是venv
,但是有些软件包是我想要的全局软件包(例如jupyter
).
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.就像您所经历的那样,因为操作系统可以以不希望的方式更改它,所以不要管它.
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.
最佳实践是使用virtualenv
(对于Python 2)或venv
(对于Python 3)来配置自己的Python版本并在每个项目的基础上进行管理.这样可以消除对系统提供的Python版本的所有依赖,并且可以将每个项目与计算机上的其他项目隔离开来.
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
(for Python 3). This eliminates all dependency on the system-provided Python version, and also isolates each project from other projects on the machine.
如果需要,每个项目可以具有不同的Python point版本,并具有其自己的site_packages
目录,因此pip安装的库也可以根据项目具有不同的版本.这种方法是一个主要的问题回避者.
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.
这篇关于pip/python:正常的站点包不可写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!