virtualenv创建环境报错
今天使用virtualenv创建虚拟环境时,提示如下报错,重点在最后一行。
JacksonShawnMBP:server jacksonshawn$ virtualenv venv
New python executable in /Users/jacksonshawn/hexoblog/fullstack/server/venv/bin/python
Installing setuptools, pip, wheel...
Complete output from command /Users/jacksonshawn/...rver/venv/bin/python - setuptools pip wheel:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "//anaconda/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
File "//anaconda/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/Users/jacksonshawn/hexoblog/fullstack/server/venv/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /Users/jacksonshawn/hexoblog/fullstack/server/venv/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /Users/jacksonshawn/hexoblog/fullstack/server/venv/lib/python2.7/lib-dynload/_io.so
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
File "//anaconda/bin/virtualenv", line 11, in <module>
sys.exit(main())
File "//anaconda/lib/python2.7/site-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "//anaconda/lib/python2.7/site-packages/virtualenv.py", line 945, in create_environment
download=download,
File "//anaconda/lib/python2.7/site-packages/virtualenv.py", line 901, in install_wheel
call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
File "//anaconda/lib/python2.7/site-packages/virtualenv.py", line 797, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /Users/jacksonshawn/...rver/venv/bin/python - setuptools pip wheel failed with error code 1
查到一种说法是安装Anaconda后,如果默认Python环境是Anaconda自带的,那么安装virtualenv这个包应该使用conda install virtualenv,而不是使用pip install virtualenv,这正是我操作报错的原因。
给出的解决办法如下,我试了一下,pip卸载virtualenv成功,但是使用conda安装virtualenv一直报错。
pip uninstall virtualenv
conda install virtualenv
virtualenv YourVirtualEnvName
先使用conda info列出全部镜像源。
JacksonShawnMBP:~ jacksonshawn$ conda info
Warning: could not import binstar_client ('args' object has no attribute 'site')Current conda install:
platform : osx-64
conda version : 4.1.11
conda-env version : 2.5.2
conda-build version : 1.14.1
python version : 2.7.12.final.0
requests version : 2.10.0
root environment : //anaconda (writable)
default environment : //anaconda
envs directories : //anaconda/envs
package cache : //anaconda/pkgs
channel URLs : http://pypi.python.com/osx-64/
http://pypi.python.com/noarch/
https://mirrors.ustc.edu.cn/anaconda/osx-64/
https://mirrors.ustc.edu.cn/anaconda/noarch/
https://pypi.mirrors.ustc.edu.cn/simple/osx-64/
https://pypi.mirrors.ustc.edu.cn/simple/noarch/
https://pypi.tuna.tsinghua.edu.cn/simple/osx-64/
https://pypi.tuna.tsinghua.edu.cn/simple/noarch/
http://pypi.douban.com/simple/osx-64/
http://pypi.douban.com/simple/noarch/
https://repo.continuum.io/pkgs/free/osx-64/
https://repo.continuum.io/pkgs/free/noarch/
https://repo.continuum.io/pkgs/pro/osx-64/
https://repo.continuum.io/pkgs/pro/noarch/
config file : /Users/jacksonshawn/.condarc
offline mode : False
is foreign system : False
再使用conda install virtualenv操作,就提示报错,无法找到URL,见最后一行,但复制这条url,发现它是真实存在的,并且可以打开。
JacksonShawnMBP:~ jacksonshawn$ conda install virtualenv
Fetching package metadata ...Could not connect to http://pypi.python.com/osx-64/
.Could not connect to http://pypi.python.com/noarch/
.Error: Could not find URL: https://mirrors.ustc.edu.cn/anaconda/osx-64/
查了半天出错原因,最后发现是下面这6个包含simple名称的镜像源无法访问导致的,可能是conda install检查所有镜像源时发现有一个无法访问时就报错,最后使用conda命令将这6个url删除后,conda install virtualenv操作成功。
https://pypi.mirrors.ustc.edu.cn/simple/osx-64/
https://pypi.mirrors.ustc.edu.cn/simple/noarch/
https://pypi.tuna.tsinghua.edu.cn/simple/osx-64/
https://pypi.tuna.tsinghua.edu.cn/simple/noarch/
创建环境报错参考链接:
http://blog.csdn.net/GZHermit/article/details/78915999
virtualenv学习链接:
https://foofish.net/virtualenv.html