问题描述
我发现了一些类似的问题/答案,但不是我所拥有的。感谢您的帮助!
系统:ubuntu 20.04 全新安装,python 3.8.5 系统安装,pyenv 运行良好。 不过,Tox 创建了 venv,但会继续运行系统解释器。
pyenv 运行良好:
aj@jaja:/tmp$ python --version
Python 3.8.5
aj@jaja:/tmp$ pyenv versions
* system (set by /home/aj/.pyenv/version)
3.6.13
pypy3.6-7.0.0
aj@jaja:/tmp$ pyenv local 3.6.13
aj@jaja:/tmp$ python --version
Python 3.6.13
我的 tox.ini :
[tox]
envlist = 3.6.13,3.8.5
skipsdist = True
[testenv]
deps =
pytest
commands =
python --version
python -c 'import sys; print(sys.executable)'
pytest
tox 似乎可以很好地创建 venv:
aj@jaja:/tmp/foo$ tox -l
3.6.13
3.8.5
但它总是运行系统解释器而不是 venv 解释器:
3.6.13 installed: attrs==20.3.0,iniconfig==1.1.1,packaging==20.9,pluggy==0.13.1,py==1.10.0,pyparsing==2.4.7,pytest==6.2.2,toml==0.10.2
3.6.13 run-test-pre: PYTHONHASHSEED='3215808768'
3.6.13 run-test: commands[0] | python --version
**Python 3.8.5**
3.6.13 run-test: commands[1] | python -c 'import sys; print(sys.executable)'
**/tmp/foo/.tox/3.6.13/bin/python**
3.6.13 run-test: commands[2] | pytest
======================================================================= test session starts =======================================================================
platform linux -- Python 3.8.5,pytest-6.2.2,py-1.10.0,pluggy-0.13.1
cachedir: .tox/3.6.13/.pytest_cache
rootdir: /tmp/foo
collected 1 item
test_calc.py .
感兴趣的 pyenv 表明了这一点,但我不知道直接使用 tox 有多正确:
aj@jaja:/tmp/foo$ cat .tox/3.6.13/pyvenv.cfg
home = /usr
implementation = cpython
version_info = 3.8.5.final.0
virtualenv = 20.4.3
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3.8
解决方法
您的环境没有按照 tox 期望的方式命名
约定是 py##
,其中 ##
是没有点的版本(或 ###
在 3.10
+ 的情况下)
所以在你的情况下你想要:
envlist = py36,py38
这将导致 tox 在您的 python3.6
上自动查找并使用 python3.8
和 PATH
-- 如果您需要它来选择特定的解释器,您可以使用 envpython
在个人 [testenv]
免责声明:我是 tox 核心维护者之一
,我从未遇到过与 tox 相关的 pyenv 问题: 请确保您启用所有版本,该 tox 将使用。
例如
pyenv shell system 3.6.13
tox
我也认为,tox 只处理两个版本号,所以尝试将您的 tox.ini 文件更改为
3.6
和 3.8
编辑:
事实上,正如@Anthony Sottile 的回答中指出的那样:(我在阅读您的问题时甚至没有注意到。
您必须使用 py36
和 py38
而不是我在初始答案中建议的 3.6
和 3.8
您可以使用 pyenv 强制使用 3.6 或 3.8 的确切版本
一般来说,测试 3.6.a 和 3.6.b 并没有多大意义 通常,较新的子版本应该与以前的子版本完全兼容,当然错误行为除外,已修复
仅供参考:(我知道您不会尝试这样做)
请注意,您不能以有意义的方式在一个 pyenv 'session'(shell)中激活例如 3.6.1 和 3.6.2。
键入以下命令以了解我的意思:
pyenv which python
pyenv which python3
pyenv which python3.6
pyenv which python3.6.13 # this one will not be found