不知何故,我的 Python/Conda/Pip 安装是这样的:即使在活动的 conda 环境中运行,pip 也会尝试安装到全局站点包目录。
在运行 10.12.4 的 macbook pro 上,我可以通过以下方式重现:
$conda create -n test python=3.6$source activate test
$which pip
/Users/ethankeller/anaconda3/envs/test/bin/pip
$pip install numpy
Collecting numpy
Using cached numpy-1.13.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Installing collected packages: numpy
Exception:
Traceback (most recent call last):
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/commands/install.py", line 342, in run
prefix=options.prefix_path,
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_set.py", line 784, in install
**kwargs
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_install.py", line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/req/req_install.py", line 1064, in move_wheel_files
isolated=self.isolated,
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/wheel.py", line 345, in move_wheel_files
clobber(source, lib_dir, True)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/wheel.py", line 316, in clobber
ensure_dir(destdir)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/site-packages/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/Users/ethankeller/anaconda3/envs/test/lib/python3.6/os.py", line 220, in makedirs
mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/lib/python3.6/site-packages/numpy'
我想某些环境变量以某种方式设置错误...有关可能出现问题或从哪里开始查找的任何建议?
经过一段时间的挣扎,我很愿意把这个问题弄清楚,所以我搜索了一段时间,然后就弄清楚并测试了。
当您通过指定 python 版本创建新的 conda env 时,它将使用 conda_root_python 版本。如果您没有安装pip软件包,并尝试在创建的 conda env 下使用 pip,它只会运行 conda_root_pip 并将软件包安装在根 site_packages 中。
我知道仅在您创建的 conda env 中安装 python 包的三种方法。为了更好的解释,我们创建一个与 conda 根环境相同的 python 版本的 conda env。
conda create -n myenv python
Run Code Online (Sandbox Code Playgroud)
I. 一位官员建议,使用conda命令为指定的 conda 环境安装软件包,
conda install -n myenv tensorflow
Run Code Online (Sandbox Code Playgroud)
二. 另一种官方建议,进入您指定的环境并运行 conda install
source activate myenv
conda install tensorflow
Run Code Online (Sandbox Code Playgroud)
通过以上两种方式,您不需要安装额外的软件包,例如 pip 和其他 pip 相关软件包。
三.对于那些真正想要点子的人来说,只是因为习惯了这一点。安装pip包(就像上面两种方法一样)。
conda install -n myenv pip
Run Code Online (Sandbox Code Playgroud)
或者
source active myenv
conda install pip
Run Code Online (Sandbox Code Playgroud)
然后在您的环境中进行 pip install
pip install tensorflow
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2925 次 |
| 最近记录: |