tox 被跳过,因为找不到 Python 解释器。

huangapple go评论57阅读模式
英文:

tox skipped because could not find python interpreter

问题

我在使用 tox 时遇到了问题。首先要说的是,我并不是虚拟环境的专家,我更喜欢使用 conda 环境,我觉得它们更容易使用和理解。

所以,我的系统背景是,我有一个运行 Ubuntu 18 的系统,Python 版本是 3.6.9。我还有一个 conda 环境,其中 Python 版本是 3.9.16,以及一个带有 Python 3.8.3 的 Anaconda 基本环境。

不管怎样,我想要使用 tox 进行测试,使用以下 tox.ini 文件:

[tox]
envlist=py37
skipsdist = True

[testenv]
deps=pytest
commands= pytest

在安装了 tox 后(我分别在 conda 环境内外安装了它),当我运行 tox 时,我得到了以下错误:

py37: skipped because could not find python interpreter with spec(s): py37

我明白了,pytest 3.7 没有被安装。但我以为这就是虚拟环境的作用...如果我还需要手动安装版本的话,使用 tox 有什么意义呢?
而且如果我想要测试多个版本,难道我需要手动安装每个版本吗?

更重要的是,我如何安装多个版本呢?

conda 中,我可以在每个环境中拥有一个版本。在这种情况下,如何在 tox 中高效使用呢?

英文:

I am having a problem using tox. I have to say first that I am not an expert on virtual environments, and I prefer to use conda environments, I find them much more easy to use and understand.

So as the background of my system I have a Ubuntu 18 system, where Python is 3.6.9. I also have a conda environment where Python is 3.9.16, and an Anaconda base environment with Python 3.8.3

Anyway I want to use tox for testing with this tox.ini file

[tox]
envlist=py37
skipsdist = True

[testenv]
deps=pytest
commands= pytest

After installing tox (and I installed it in both inside the conda environment and outside), when I ran tox I got:

py37: skipped because could not find python interpreter with spec(s): py37

I get it, pytest 3.7 is not installed.
But I thought that is what virtual environments do... what is the point of me using tox if I have to install manually the version ?
And if I want to test it with multiple versions, do I have to install manually every version?

And what is more important, how can I install several versions?

With conda I have one version per environment.
How can I use tox efficiently here?

答案1

得分: 2

这不是pytest的版本有问题,py37指的是Python版本3.7,所以它没有找到与之关联的解释器。

您可以在Ubuntu 18.04中安装它:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7

要有效地使用tox,您需要学会如何正确配置tox.ini文件以及tox环境的工作原理。要启动任何py3X,将执行命令(通常是pytest)在您的主要环境中,通常定义为Python的3.X版本。

另一个提示是使用-p标志来并行执行不同的环境,例如tox -p -e py37,py39,这将同时在python3.7python3.9中执行testenv

英文:

It's not the version pytest which is wrong, py37 refers to Python version 3.7, so it didn't find the interpreter associated with it.

You can install it in Ubuntu 18.04 by:

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.7

To use effectively tox you need to learn how to configure properly the tox.ini file and how the tox environments works. To start any py3X will execute the commands (usually pytest) in your main environment, usually defined as testenv with the version 3.X of Python.

Other tip is to use the flag -p for parallel execution of different environments, e.g. tox -p -e py37,py39 which will execute testenv in python3.7 and python3.9 simultaneously.

答案2

得分: 1

tox 要求预先安装Python解释器。Python解释器的安装方式不是tox的关注点。

安装多个额外的Python解释器的一些想法:

英文:

tox requires Python interpreters to already be installed beforehand. How the Python interpreters get installed is not tox's concern.

Some ideas to install multiple additional Python interpreters:

huangapple
  • 本文由 发表于 2023年5月28日 20:35:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76351518.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定