让tox使用pyenv设置的Python版本

2024-06-19

我似乎无法集中精力管理 Python 版本。当我跑步时tox,我可以立即看到它使用的是 Python 3.7.9:

$ tox
py39: commands[0]> coverage run -m pytest
================================================================================== test session starts ==================================================================================
platform darwin -- Python 3.7.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /usr/local/bin/python3

但它配置为使用 3.9:

[tox]
envlist = py39,manifest,check-formatting,lint
skipsdist = True
usedevelop = True
indexserver =
    spotify = https://artifactory.spotify.net/artifactory/api/pypi/pypi/simple

[testenv]
basepython = python3.9
deps =
    :spotify:-r{toxinidir}/dev-requirements.txt
commands =
    coverage run -m pytest {posargs}
allowlist_externals = coverage

[testenv:manifest]
; a safety check for source distributions
basepython = python3.9
deps = check-manifest
skip_install = true
commands = check-manifest

这是我所看到的which:

$ pyenv local 3.9.10
$ which python
/Users/acheong/.pyenv/shims/python
$ which python3
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
$ pyenv which python
/Users/acheong/.pyenv/versions/3.9.10/bin/python

pytest还使用了错误的版本:

$ pytest tests
================================================================================== test session starts ==================================================================================
platform darwin -- Python 3.7.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
cachedir: .pytest_cache
rootdir: /Users/acheong/src/spotify/protean/ezmode-cli, configfile: tox.ini, testpaths: tests
plugins: mock-3.10.0, cov-2.10.0

但在这种情况下,我了解到我可以这样做:

$ pyenv exec pytest tests
================================================================================== test session starts ==================================================================================
platform darwin -- Python 3.9.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /Users/acheong/.pyenv/versions/3.9.10/bin/python
cachedir: .pytest_cache
rootdir: /Users/acheong/src/spotify/protean/ezmode-cli, configfile: tox.ini, testpaths: tests
plugins: mock-3.10.0, cov-2.10.0

但是当我尝试这样做时tox,我收到错误:

$ pyenv exec tox
Traceback (most recent call last):
  File "/Users/acheong/.pyenv/versions/3.9.10/bin/tox", line 8, in <module>
    sys.exit(run())
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/run.py", line 19, in run
    result = main(sys.argv[1:] if args is None else args)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/run.py", line 38, in main
    state = setup_state(args)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/run.py", line 53, in setup_state
    options = get_options(*args)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/config/cli/parse.py", line 38, in get_options
    guess_verbosity, log_handler, source = _get_base(args)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/config/cli/parse.py", line 61, in _get_base
    MANAGER.load_plugins(source.path)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/plugin/manager.py", line 90, in load_plugins
    self._register_plugins(inline)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/plugin/manager.py", line 38, in _register_plugins
    self.manager.load_setuptools_entrypoints(NAME)
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/importlib/metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox_pyenv.py", line 48, in <module>
    from tox import hookimpl as tox_hookimpl
ImportError: cannot import name 'hookimpl' from 'tox' (/Users/acheong/.pyenv/versions/3.9.10/lib/python3.9/site-packages/tox/__init__.py)

我已经尝试了很多在网上找到的东西,但我担心如果有的话,我只会让我的环境更加混乱。我可以采取哪些步骤来诊断问题并获得tox使用我的pyenv版本?


哦,原来我是如此接近。显然 Tox 4 破坏了 tox-pyenv。当我恢复到 Tox 3 后,它就起作用了。

$ pyenv exec python -m pip install "tox<4"
...
Installing collected packages: tox
  Attempting uninstall: tox
    Found existing installation: tox 4.4.6
    Uninstalling tox-4.4.6:
      Successfully uninstalled tox-4.4.6
Successfully installed tox-3.28.0
$ pyenv exec tox
py39 create: /Users/acheong/src/spotify/protean/ezmode-cli/.tox/py39
py39 installdeps: :spotify:-r/Users/acheong/src/spotify/protean/ezmode-cli/dev-requirements.txt
py39 installed: attrs==22.2.0,bump2version==1.0.1,bumpversion==0.6.0,CacheControl==0.12.11,cachetools==5.3.0,certifi==2022.12.7,chardet==4.0.0,click==7.1.2,colorama==0.4.6,coverage==5.2,event-definitions-protos-python==0.6.156,-e git+ssh://[email protected] /cdn-cgi/l/email-protection/protean/ezmode-cli.git@32fc2a748278862efd15e431363d4aa5c95916e4#egg=ezmode_cli,ezmode-common==0.2.5,gabito-python==2.2.0,ghp-import==2.1.0,google-auth==2.16.2,grpcio==1.51.3,idna==2.10,importlib-metadata==5.0.0,iniconfig==2.0.0,interrogate==1.5.0,Jinja2==3.1.2,Markdown==3.3.7,MarkupSafe==2.1.2,mergedeep==1.3.4,mkdocs==1.4.2,msgpack==1.0.5,packaging==23.0,pluggy==1.0.0,protobuf==4.22.1,py==1.11.0,pyasn1==0.4.8,pyasn1-modules==0.2.8,pytest==6.2.5,pytest-cov==2.10.0,pytest-mock==3.10.0,python-dateutil==2.8.2,PyYAML==5.1,pyyaml_env_tag==0.1,requests==2.25.1,rsa==4.9,six==1.16.0,spotify-python-metrics==0.0.26,spotify-service-auth==0.3.9,tabulate==0.9.0,techdocs-cli==0.16.3,toml==0.10.2,tqdm==4.65.0,urllib3==1.26.15,watchdog==2.3.1,zipp==3.15.0
py39 run-test-pre: PYTHONHASHSEED='658999387'
py39 run-test: commands[0] | coverage run -m pytest
================================================================================== test session starts ==================================================================================
platform darwin -- Python 3.9.10, pytest-6.2.5, py-1.11.0, pluggy-1.0.0 -- /Users/acheong/src/spotify/protean/ezmode-cli/.tox/py39/bin/python
cachedir: .tox/py39/.pytest_cache
rootdir: /Users/acheong/src/spotify/protean/ezmode-cli, configfile: tox.ini, testpaths: tests
plugins: mock-3.10.0, cov-2.10.0
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

让tox使用pyenv设置的Python版本 的相关文章

随机推荐

  • RSA 已处置对象错误 - 所有其他测试

    我们有几个测试生成 jwt 请求来调用服务器来检索令牌 我们有 6 个测试 使用相同的数据对相同的方法进行相同的调用 方法如下 private static string GenerateSignedTokenRequest string
  • 为什么我在 Windows 上使用 async 和 wait 时会收到 NotImplementedError 错误?

    我有这个代码 import os import time import asyncio async def run command args Example from http asyncio readthedocs io en lates
  • 如何使用 Nginx 将下划线替换为破折号

    我第一次使用Nginx 对它基本上一无所知 我需要将 100 多个 URL 中的 替换为 我想一定有一种简单的方法可以用 Nginx 来做到这一点 但在 Google 上找不到任何东西 Thanks Edit 我的网址例如 http www
  • 为什么我会遇到分段错误?

    我只想创建一个简单的 C 结构 它有一个 int 索引和一个 int greyValue 该函数被赋予带有灰度值的向量 当我尝试编译它时 出现分段错误 有人知道为什么吗 没有对向量进行排序 谢谢 vector
  • Xcode 6 仪器冻结

    在 Xcode 6 Instruments 中分析我的 iOS 8 应用程序将运行该应用程序约 5 秒 然后冻结 此后探查器仍将运行 但应用程序已冻结且无法使用 发生在设备和模拟器上 无论我使用哪个分析器 计时器 泄漏等 从调试器或临时构建
  • AngularJS 指令的完整列表?

    我正在学习 AngularJS 是否有所有开箱即用指令的完整列表 这FAQ http docs angularjs org misc faq提及ng repeat ng show and ng class 但我感觉还有更多 奇怪的是我找不到
  • Typescript 生成带有“#private;”字段的声明 d.ts 文件

    我有一个用 Typescript 编写的库 它分布在 2 个文件中 一个已编译的 ECMAScript 2015 兼容 Javascript 文件index js和一个 Typescript 声明文件index d ts 我的目标是让 Ja
  • 在 .Net 中创建 EPUB

    有没有可以用来在 NET C 中创建 epub 文件的库 Flowdocument gt epub 转换工具将是理想的选择 但任何类型的库都很棒 我还对评估编写一个程序的复杂程度感兴趣 我知道它基本上是一堆压缩的 XHTML 文件 但我不断
  • AWK数组初始化

    是否可以使用常见的方法在AWK中初始化数组list syntax array val1 val2 val3 或者是否必须使用索引值 syntax array 0 val1 array 1 val2 array 2 val3 不 不 您可以这
  • libmysqlclient.a 和 libmysqlclient_r.a 有什么区别?

    我应该使用哪个来链接 mysqlclient 库 它们之间有什么区别 我似乎找不到答案 谢谢 较新版本的 MySQL 客户端发行版不包含 r 版本 有些可能有从 libmyqslclient r a 到 libmyqslclient a 的
  • Java 中查看 ArrayList 是否包含对象的最有效方法

    我有一个 Java 对象的 ArrayList 这些对象有四个字段 我用其中两个字段来将对象视为与另一个对象相等 我正在寻找最有效的方法 给定这两个字段 以查看数组是否包含该对象 问题在于这些类是基于 XSD 对象生成的 因此我无法修改类本
  • SVN错误155009:无法运行WC DB工作\无法打开文件\系统找不到指定的文件

    I found 信息贫乏 https www google com webhp q 22Failed 20to 20run 20the 20WC 20DB 20work 20queue 20associated 20with 22 20 2
  • 本地主机中的 Ansible SSH 连接错误

    当我针对本地主机启动我的剧本时 出现此错误 TASK setup fatal 127 0 0 1 UNREACHABLE gt changed false msg SSH encountered an unknown error durin
  • 罗莎琳德《孟德尔第一定律》 IPRB

    作为即将到来的生物信息学课程的准备 我正在做一些来自 rosalind info 的作业 我目前正陷入任务 孟德尔第一定律 http rosalind info problems iprb 我想我可以用蛮力强迫自己解决这个问题 但不知怎的
  • 如何在 IE 中检测开窗器

    我在堆栈上找不到任何好的答案 它们与对话框 文本编辑器有关 并且有人使用 VBScript 我需要向开窗器发送消息 这在 FF Chrome 和 Opera 中运行良好 但是window opener在 IE8 10 中为空 我在用wind
  • 删除网格 Tkinter 中的某些行/列

    如果我在同一框架中有多个行和列 并且有多个条目 标签小部件 是否可以仅选择其中一个并将其删除 同时保留其他小部件 e g class Window def init self self root Tk self win1 Frame sel
  • Rails 4 - 每次运行 rake db:migrate 命令时,rake 命令都会显示弃用警告

    pinterestclone rake db migrate DEPRECATION WARNING Sprockets method register engine is deprecated Please register a mime
  • 在 Windows 7 上连接到高于 10 的 COM 端口时出现无效句柄错误

    我开发了一个简单的串行端口应用程序 可以在低于 10 的 COM 端口 COM9 COM8 COM1 上正常工作 但是 当我的设备连接到高于 10 的端口 例如 COM11 时 它无法连接 并且我收到 INVALID HANDLE 我的代码
  • 自定义WebApi授权数据库调用

    我正在尝试确定我编写的自定义授权属性是否确实是一个好主意 Scenario假设我们有一系列商店 每个商店Store有一个主人 只有商店的所有者才能对商店进行CRUD操作 除了具有Claim这基本上超越了所有权要求 并表示他们可以在任何商店上
  • 让tox使用pyenv设置的Python版本

    我似乎无法集中精力管理 Python 版本 当我跑步时tox 我可以立即看到它使用的是 Python 3 7 9 tox py39 commands 0 gt coverage run m pytest test session start