conda环境pip试图全局安装依赖项 [英] conda environment pip is trying to install dependencies globally
问题描述
以某种方式,我的Python/Conda/Pip安装使得pip-即使在活动的conda环境中运行时-也会尝试安装到全局site-packages目录中.
在运行10.12.4的macbook pro上,我可以通过以下方式重现:
- 创建conda环境:
$conda create -n test python=3.6
- 激活conda环境:
$source activate test
- 验证pip命令是否引用了正确的pip二进制文件:
$which pip /Users/ethankeller/anaconda3/envs/test/bin/pip
- 使用pip安装任何软件包-例如numpy:
$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'
我想有些环境变量设置不正确...关于什么可能是错误的,或者从哪里开始寻找任何建议?
在奋斗了一段时间之后,我非常愿意让自己摆脱这个问题,所以我搜索了一段时间,然后才弄清楚并进行了测试. /p>
通过指定python版本创建新的conda env时,它将使用conda_root_python版本.而且,如果您没有安装 pip 软件包,并尝试在创建的conda env下使用pip,则它将仅运行conda_root_pip并将该软件包安装在根site_packages中.
我知道在您创建的conda env中仅仅安装python软件包的三种方法. 为了获得更好的解释,我们使用相同的python版本的conda根环境创建了一个conda env.
conda create -n myenv python
I.一位官员建议,使用 conda 命令为指定的conda环境安装软件包,
conda install -n myenv tensorflow
II.另一项官方建议是进入您指定的环境并运行conda install
source activate myenv
conda install tensorflow
通过上述两种方式,您不需要安装额外的软件包,例如pip和其他与pip相关的软件包.
III.对于真正想点子的人,只是因为习惯了. 安装pip程序包(就像上述两种方法一样).
conda install -n myenv pip
或
source active myenv
conda install pip
然后在您的环境中进行pip安装
pip install tensorflow
Somehow my Python/Conda/Pip installation is such that pip - even when operating within an active conda environment - attempts to install to the global site-packages directory.
On my macbook pro running 10.12.4, I can reproduce by:
- creating a conda environment:
$conda create -n test python=3.6
- Activating the conda environment:
$source activate test
- Verify that the pip command references the correct pip binary:
$which pip /Users/ethankeller/anaconda3/envs/test/bin/pip
- Use pip to install any package - for instance numpy:
$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'
I imagine that some environment variable is set wrong somehow... Any advice on what could be wrong, or where to start looking?
After struggling for a while, I was so willing to make myself clear of this issue, so I searched for a while, and just figured out and tested.
When you create a new conda env by specifying the python version, it will use the conda_root_python version. And if you didn't install the pip package, and try to use pip under your created conda env, it will only run the conda_root_pip and install the package in the root site_packages.
I know three ways to install python packages only in your created conda env. For a better explanation, we create a conda env with same python version of conda root environment.
conda create -n myenv python
I. One of the officials advise, install package with conda command for specified conda environment,
conda install -n myenv tensorflow
II. Another one of official advise, get into your specified environment and run conda install
source activate myenv
conda install tensorflow
in above two ways you don't need to install extra packages like pip and other pip related packages.
III. For people who really want to pip, just because get used of that. install pip package(just as above two ways did).
conda install -n myenv pip
or
source active myenv
conda install pip
then comes the pip install when you are in your environment
pip install tensorflow
这篇关于conda环境pip试图全局安装依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!