簡體   English   中英

使用 pyenv-virtualenv 設置 virtualenv 時出現 ASCII 編解碼器錯誤

[英]ASCII codec error when setting up an virtualenv with pyenv-virtualenv

我需要使用與系統上安裝的版本不同的 python 版本。 為此,我使用 penv 安裝了我想要的版本 - 2.7.12,然后在我安裝時顯示正確的版本:

pyenv which python
/root/.pyenv/versions/2.7.12/bin/python

當我嘗試使用以下命令創建新的虛擬環境時:

[root@localhost site-packages] pyenv virtualenv 2.7.12 nanovar

New python executable in /root/.pyenv/versions/2.7.12/envs/nanovar/bin/python2.7
Also creating executable in /root/.pyenv/versions/2.7.12/envs/nanovar/bin/python
Installing setuptools, pip, wheel...

  Complete output from command /root/.pyenv/version...anovar/bin/python2.7 - setuptools pip wheel:
  DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Created temporary directory: /tmp/pip-ephem-wheel-cache-gFPfrS
Created temporary directory: /tmp/pip-req-tracker-UI5fK2
Created requirements tracker '/tmp/pip-req-tracker-UI5fK2'
Created temporary directory: /tmp/pip-install-Ck6zPW
Looking in links: /root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support
Collecting setuptools
  1 location(s) to search for versions of setuptools:
  * https://pypi.org/simple/setuptools/
  Skipping link /root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support (from -f); not a file
  Getting page https://pypi.org/simple/setuptools/
  Looking up "https://pypi.org/simple/setuptools/" in the cache
  Request header has "max_age" as 0, cache bypassed
Cleaning up...
Removed build tracker '/tmp/pip-req-tracker-UI5fK2'
ERROR: Exception:
Traceback (most recent call last):
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/cli/base_command.py", line 178, in main
    status = self.run(options, args)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/commands/install.py", line 352, in run
    resolver.resolve(requirement_set)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py", line 131, in resolve
    self._resolve_one(requirement_set, req)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py", line 294, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/resolve.py", line 242, in _get_abstract_dist_for
    self.require_hashes
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/operations/prepare.py", line 282, in prepare_linked_requirement
    req.populate_link(finder, upgrade_allowed, require_hashes)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/req/req_install.py", line 198, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 766, in find_requirement
    candidates = self.find_candidates(req.name, req.specifier)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 752, in find_candidates
    self.find_all_candidates(project_name),
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 716, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 846, in _get_pages
    page = _get_html_page(location, session=self.session)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 231, in _get_html_page
    resp = _get_html_response(url, session=session)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/index.py", line 179, in _get_html_response
    "Cache-Control": "max-age=0",
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_internal/download.py", line 439, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/adapter.py", line 51, in send
    request.headers.update(self.controller.conditional_headers(request))
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/controller.py", line 233, in conditional_headers
    resp = self.serializer.loads(request, self.cache.get(cache_url))
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py", line 97, in loads
    return getattr(self, "_loads_v{}".format(ver))(request, data)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py", line 161, in _loads_v2
    cached["response"]["body"] = _b64_decode_bytes(cached["response"]["body"])
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv_support/pip-19.1.1-py2.py3-none-any.whl/pip/_vendor/cachecontrol/serialize.py", line 13, in _b64_decode_bytes
    return base64.b64decode(b.encode("ascii"))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-57970: ordinal not in range(128)
----------------------------------------
...Installing setuptools, pip, wheel...done.
Traceback (most recent call last):
  File "/root/.pyenv/versions/2.7.12/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py", line 870, in main
    symlink=options.symlink,
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py", line 1173, in create_environment
    install_wheel(to_install, py_executable, search_dirs, download=download)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py", line 1019, in install_wheel
    _install_wheel_with_search_dir(download, project_names, py_executable, search_dirs)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py", line 1110, in _install_wheel_with_search_dir
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=script)
  File "/root/.pyenv/versions/2.7.12/lib/python2.7/site-packages/virtualenv.py", line 963, in call_subprocess
    raise OSError("Command {} failed with error code {}".format(cmd_desc, proc.returncode))
OSError: Command /root/.pyenv/version...anovar/bin/python2.7 - setuptools pip wheel failed with error code 2
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-8.1.1 setuptools-20.10.1

我無法理解 ascii 編解碼器問題,我嘗試設置 LC_CTYPE="C.UTF-8" 但沒有效果。 可能出了什么問題? 系統安裝的 python 是否干擾了我使用 pyenv 安裝的 python?

清除 pip 緩存幫助我解決了這個問題。

cd $HOME/.cache 
rm -r pip

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM