V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
SimWit
V2EX  ›  Python

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

  •  
  •   SimWit · 2020-01-08 15:49:34 +08:00 · 2546 次点击
    这是一个创建于 1766 天前的主题,其中的信息可能已经有所发展或是发生改变。

    环境

    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
    
    6 条回复    2020-01-13 11:25:10 +08:00
    nznd
        1
    nznd  
       2020-01-08 17:14:54 +08:00
    拿 3.8 的 virtualenvwrapper 创建 2 的 env...
    建议换个版本试试(指 python2 的
    SimWit
        2
    SimWit  
    OP
       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
        3
    kayseen  
       2020-01-08 20:22:45 +08:00
    这个工具我之前也遇到过类似的问题,后来建环境直接使用`python -m`也挺方便
    dxySheldon
        4
    dxySheldon  
       2020-01-08 20:28:03 +08:00 via Android
    要不试试 anaconda 创建虚拟环境
    mailmac
        5
    mailmac  
       2020-01-09 08:44:59 +08:00 via Android   ❤️ 1
    python -m venv .
    解君愁!! 早都不用 virtual 了。
    SimWit
        6
    SimWit  
    OP
       2020-01-13 11:25:10 +08:00 via Android
    谢谢,我之前不知道 venv,让我了解一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1749 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:44 · PVG 00:44 · LAX 08:44 · JFK 11:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.