在Mac OS X上尝试使用冲煮安装的Python 2.7创建virtualenv时,出现以下错误:
Could not install packages due to an EnvironmentError:
[Errno 13] Permission denied: '/lib'
完整输出:
▶ virtualenv ./virtualenv
New python executable in /Users/alexharvey/git/home/sam-test/virtualenv/bin/python2.7
Also creating executable in /Users/alexharvey/git/home/sam-test/virtualenv/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/alexharvey/gi...ualenv/bin/python2.7 - setuptools pip wheel:
Looking in links: /usr/local/lib/python2.7/site-packages, /usr/local/lib/python2.7/site-packages/virtualenv_support, /usr/local/lib/python2.7/site-packages/virtualen
v_support
Collecting setuptools
Using cached https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl
Collecting pip
Collecting wheel
Using cached https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: setuptools, pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/lib'
Consider using the `--user` option or check the permissions.
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 762, in main
symlink=options.symlink,
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 1015, in create_environment
install_wheel(to_install, py_executable, search_dirs, download=download)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 968, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 854, in call_subprocess
raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command /Users/alexharvey/gi...ualenv/bin/python2.7 - setuptools pip wheel failed with error code 1
我看到以前经常在这里问过类似的问题(例如here),但是似乎建议使用sudo
来回答问题,这显然是错误的。
请注意,我在此页面上遵循了以下建议:Using python effectively on Mac OS X。
如何解决此问题(不使用sudo)?
答案 0 :(得分:3)
如评论中所建议,自定义Distutils配置文件存在问题。该文件显然可以放在以下三个位置之一中(ref):
// create an instance
WebClient webClient = new WebClient();
// call the HTML page you want to download, and get it as a string
string htmlCode = webClient.DownloadString(uri);
return htmlCode;
conda create --name new_env_name tensorflow-gpu
activate new_env_name
<prefix>/lib/pythonver/distutils/distutils.cfg
同时,我根据此答案here创建了一个$HOME/.pydistutils.cfg
,内容为:
setup.cfg
我已经不记得为什么我曾经咨询过这个答案,或者为什么我把那个文件放在那里了,但是在删除它之后,virtualenv再次正常工作,而且我再也没有任何问题了。
答案 1 :(得分:0)
在全局/lib
中安装任何内容显然需要root特权。
您可以在不使用sudo
的情况下将模块安装到用户的文件夹中,而在安装任何软件包时只需添加--user
参数即可。
答案 2 :(得分:0)
您必须以非sudo用户身份安装python和pip
Python安装
cd
mkdir python
cd python
mkdir src
cd src
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar xvfz Python-2.7.3.tgz
cd Python-2.7.3
mkdir ~/python/python27
./configure -prefix=/home/username/python/python27
make
make install
cd
echo "export PATH=$HOME/python/python27/bin" >> .bashrc
source .bashrc
获得点子
cd ~/python
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz --no-check-certificate
tar xvfz setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py install
cd ..
wget http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz --no-check-certificate
tar xvfz pip-1.1.tar.gz
cd pip-1.1
python setup.py install
cd
获取virtualenv
pip install virtualenv
pip install virtualenvwrapper
记下您的项目并激活虚拟环境
git clone ... # Whatever project you're doing
cd <projectname>
virtualenv --distribute env
source env/bin/activate
pip install -r requirements.txt