Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

virtualenv 创建虚拟环境不成功

在阿里云上面的服务器有一台服务器,我已经安装好pip和virtualenv,我通过

virtualenv venv

创建虚拟环境的时候提示的错误信息如下

root@Wireless:~/flasky# virtualenv venv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /root/flasky/venv/bin/python2
Not overwriting existing python script /root/flasky/venv/bin/python (you must use /root/flasky/venv/bi                                                                                          n/python2)
Please make sure you remove any previous custom paths from your /root/.pydistutils.cfg file.
Installing setuptools, pkg_resources, pip, wheel...
  Complete output from command /root/flasky/venv/bin/python2 - setuptools pkg_resources pip wheel:
  Collecting setuptools
  Downloading http://mirrors.aliyun.com/pypi/packages/a7/62/3995dc3067cbf8d4a13ddac0f87417b9a08799c586                                                                                          b3faa77d62ad9085de/setuptools-34.1.0-py2.py3-none-any.whl (389kB)
Collecting pkg_resources
Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 328, in                                                                                           run
    wb.build(autobuilding=True)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 360, in prep                                                                                          are_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 512, in _pre                                                                                          pare_file
    finder, self.upgrade, require_hashes)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_install.py", line 273, in                                                                                           populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 442, in find_requi                                                                                          rement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 400, in find_all_c                                                                                          andidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 760, in get_page
    resp.raise_for_status()
  File "/root/flasky/venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/models.py",                                                                                           line 840, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: http://mirrors.aliyun.com/pypi/simple/pkg-resources/
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /root/flasky/venv/bin/python2 - setuptools pkg_resources pip wheel failed with error                                                                                           code 2

我发现我的系统里有3个版本的pip,如下

pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
root@Wireless:~/flasky# pip3 -V
pip 9.0.1 from /usr/local/lib/python3.5/dist-packages (python 3.5)
root@Wireless:~/flasky# pip2 -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

我尝试过升级pip,但最后那个pip8.1无法升级到pip9,好像最高版本就是pip8,我
试过用以下命令进行升级:

pip install -U pip
pip install -U pip2
pip install -U pip3
pip2 install -U pip
pip2 install -U pip2
pip2 install -U pip3
pip3 install -U pip
pip3 install -U pip2
pip3 install -U pip3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

HTTPError: 404 Client Error: Not Found for url: http://mirrors.aliyun.com/pyp...
这句说明阿里云服务器不向外发送请求。
解决方法:在服务器实例的“安全规则”---“外出方向”--“常用端口(TCP)” 选择http ;“授权策略”为允许。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...