我厌倦了用pip安装venv,它给了我以下错误消息:
我尝试了很多次,几天前效果很好...
这是命令:
$ pip install venv
和错误:
Collecting venv
Exception:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
wb.build(autobuilding=True)
File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
self.requirement_set.prepare_files(self.finder)
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 465, in find_requirement
all_candidates = self.find_all_candidates(req.name)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 423, in find_all_candidates
for page in self._get_pages(url_locations, project_name):
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_pages
page = self._get_page(location)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 683, in _get_page
return HTMLPage.get_page(link, session=self.session)
File "/usr/lib/python2.7/dist-packages/pip/index.py", line 795, in get_page
resp.raise_for_status()
File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/venv/
操作系统:linux ubuntu 18.04 python 3.7
谢谢!
答案 0 :(得分:4)
在ubuntu 18.04上,python
可执行文件默认情况下绑定到python2.7
,请参见this;因此,当您这样做时:
pip install venv
您正尝试在仅与python3.3 +兼容的python2.7上安装venv
(请参见下文),这就是为什么会出现这些错误的原因。
请注意,您无需在venv
+上安装python3.3
,因为它是默认包含的,请参见venv documentation。
通过执行以下命令来创建虚拟环境:
python3 -m venv /path/to/new/virtual/environment
对于python的早期版本(在您的情况下为2.7),可以使用virtualenv
pip install virtualenv
创建:
virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>
请注意,-p
标志不是强制性的,只是为了确保在使用python 2和python 3都安装virtualenv的情况下调用正确的python版本。