【问题标题】:Tox not finding python3.6 even with the shim present. What is wrong with my pyenv setup?即使存在 shim,Tox 也找不到 python3.6。我的 pyenv 设置有什么问题?
【发布时间】:2019-02-13 15:00:31
【问题描述】:

试图为已经失修的 django 包注入一些活力。他们使用 tox 进行测试,所以我在我的 MacBook 上设置了 pyenv。我已经安装了 3 个版本的 python,如下所示,一切看起来都应该可以工作,但如果可以,我不会问为什么不可以。

我已将我的主目录替换为 ~ 以使其更易于阅读。

pyenv 用brew install pyenv 安装,各种版本的python 用pyenv install #.#.# 安装

垫片存在:

$ echo $PATH
~/.pyenv/shims:~/.platformsh/bin:/usr/local/sbin:...
$ which python3.6
~/.pyenv/shims/python3.6
$ which python3.4
~/.pyenv/shims/python3.4
$ which python3.5
~/.pyenv/shims/python3.5

但是执行它们并没有按预期工作:

$ pyenv local 3.4.9 3.5.6 3.6.8
$ python3.4
Python 3.4.9 (default, Feb 12 2019, 10:33:47)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ python3.5
pyenv: python3.5: command not found

The `python3.5' command exists in these Python versions:
  3.5.6

$ python3.6
pyenv: python3.6: command not found

The `python3.6' command exists in these Python versions:
  3.6.8

tox 像这样失败:

  py34-1.11: commands succeeded
ERROR:   py36-1.11: Error creating virtualenv. Note that some special characters (e.g. ':' and unicode symbols) in paths are not supported by virtualenv. Error details: InvocationError("Failed to get version_info for python3.6: pyenv: python3.6: command not found\n\nThe `python3.6' command exists in these Python versions:\n  3.6.8\n\n", None)
ERROR:   py36-2.0: Error creating virtualenv. Note that some special characters (e.g. ':' and unicode symbols) in paths are not supported by virtualenv. Error details: InvocationError("Failed to get version_info for python3.6: pyenv: python3.6: command not found\n\nThe `python3.6' command exists in these Python versions:\n  3.6.8\n\n", None)
  py36-latest: commands succeeded
  docs: commands succeeded

但是在 .tox 文件夹中你会发现这些 VirtualEnvs 可以手动激活。

$ ls .tox
dist        docs        flake8      log     py34-1.11   py36-1.11   py36-2.0    py36-latest

因为在某些时候它正在工作......

我确实理解它为什么不起作用的机制,我不明白为什么 pyenv 没有正确设置环境(或者也许这正是它应该表现的方式)。我读到的一切似乎都表明 python3.6 应该启动一个 python3.6.8 解释器

$ bash -x python3.6
+ set -e
+ '[' -n '' ']'
+ program=python3.6
+ [[ python3.6 = \p\y\t\h\o\n* ]]
+ export PYENV_ROOT=~/.pyenv
+ PYENV_ROOT=~/.pyenv
+ exec /usr/local/Cellar/pyenv/1.2.9/libexec/pyenv exec python3.6
pyenv: python3.6: command not found

The `python3.6' command exists in these Python versions:
  3.6.8

【问题讨论】:

    标签: python tox pyenv


    【解决方案1】:

    pyenv 默认picks the python“本地”,即查找PYTHON_VERSION 环境变量或.python-version 文件。

    我个人觉得这种设置有点麻烦(需要将这些文件散布在所有项目中,尤其是在需要多个版本的项目中)。幸运的是,您可以使用pyenv global #.#.#pyenv global #.#.# 使这些“垫片”在任何地方使用默认版本的 python 发挥作用

    在您的情况下,要使 python3.6 shim 执行 3.6.8 而无需设置 .python-version 文件,您将运行 pyenv global 3.6.8 - 您也可以针对不同的 python 版本多次运行它:pyenv global 3.6.8 3.5.6 ...

    您可能在tox 中没有这些解析的原因是tox 在执行时会清除环境,因此PYTHON_VERSION 环境变量不会执行。您可以通过在您的tox.ini 中设置passenv= 来关闭它。例如:

    [testenv]
    passenv = PYTHON_VERSION
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 2013-07-23
      • 2011-12-06
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-06-26
      相关资源
      最近更新 更多