使用 virtualenvwrapper 创建 python2.7,2.5 版本的虚拟环境均报错

2020-01-08 15:49:34 +08:00
 SimWit

环境

virtualenv 16.7.9
virtualenvwrapper-win 1.2.5

报错信息

2.5

Running virtualenv with interpreter E:\Software\Python\Python25\python.exe
e:\software\python\python38\lib\site-packages\virtualenv.py:432: Warning: 'with' will become a reserved keyword in Python 2.6
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 432
    with open(dest, "wb") as f:
            ^
SyntaxError: invalid syntax

2.7

Cleaning up...
Removed build tracker 'c:\\users\\\xb9\xf9\xea\xbb\xc7\xbf\\appdata\\local\\temp\\pip-req-tracker-dd3usp'
ERROR: Exception:
Traceback (most recent call last):
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\cli\base_command.py", line 153, in _main
    status = self.run(options, args)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\commands\install.py", line 382, in run
    resolver.resolve(requirement_set)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\legacy_resolve.py", line 201, in resolve
    self._resolve_one(requirement_set, req)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\legacy_resolve.py", line 365, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\legacy_resolve.py", line 311, in _get_abstract_dist_for
    req.populate_link(self.finder, upgrade_allowed, self.require_hashes)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\req\req_install.py", line 225, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\index.py", line 879, in find_requirement
    req.name, specifier=req.specifier, hashes=hashes,
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\index.py", line 861, in find_best_candidate
    candidates = self.find_all_candidates(project_name)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\index.py", line 791, in find_all_candidates
    collected_links = self._link_collector.collect_links(project_name)
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\collector.py", line 509, in collect_links
    self.find_links, expand_dir=True,
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\collector.py", line 408, in group_locations
    sort_path(os.path.join(path, item))
  File "e:\software\python\python38\lib\site-packages\virtualenv_support\pip-19.3.1-py2.py3-none-any.whl\pip\_internal\collector.py", line 389, in sort_path
    if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
  File "E:\Software\Python\Python27\Lib\mimetypes.py", line 297, in guess_type
    init()
  File "E:\Software\Python\Python27\Lib\mimetypes.py", line 358, in init
    db.read_windows_registry()
  File "E:\Software\Python\Python27\Lib\mimetypes.py", line 258, in read_windows_registry
    for subkeyname in enum_types(hkcr):
  File "E:\Software\Python\Python27\Lib\mimetypes.py", line 249, in enum_types
    ctype = ctype.encode(default_encoding) # omit in 3.x!
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 in position 9: ordinal not in range(128)
--------------------------------------------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 2634, in <module>
    main()
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 870, in main
    symlink=options.symlink,
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 1179, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 1023, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 1116, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "e:\software\python\python38\lib\site-packages\virtualenv.py", line 963, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command E:\Software\Python\E...7\Scripts\python.exe - setuptools pip wheel failed with error code 2
2602 次点击
所在节点    Python
6 条回复
nznd
2020-01-08 17:14:54 +08:00
拿 3.8 的 virtualenvwrapper 创建 2 的 env...
建议换个版本试试(指 python2 的
SimWit
2020-01-08 18:14:22 +08:00
@nznd 谢谢。问题好像不在于此。通过查找 2.7 的问题在于字符集的问题。解决办法来自:“https://www.cnblogs.com/ingd/p/6185347.html”。
2.5 的话,根据官网,对于 virtualenvwrapper 测试范围为 2.6~3.6 没有问题,所以很有可能是不支持创建 2.5 版本的虚拟环境。但是我使用的是 virtualenvwrapper-win 好像有些不一样。
而针对版本来说,我使用 python2.7.17,安装 virtualenvwrapper,创建 2.5 的环境,仍报相同的错误。
kayseen
2020-01-08 20:22:45 +08:00
这个工具我之前也遇到过类似的问题,后来建环境直接使用`python -m`也挺方便
dxySheldon
2020-01-08 20:28:03 +08:00
要不试试 anaconda 创建虚拟环境
mailmac
2020-01-09 08:44:59 +08:00
python -m venv .
解君愁!! 早都不用 virtual 了。
SimWit
2020-01-13 11:25:10 +08:00
谢谢,我之前不知道 venv,让我了解一下

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/636186

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX