tox 没有找到 numpy

tox does not find numpy

我尝试 运行 tox 以自动测试我的项目。我的 tox 文件非常简单:

[tox]
envlist = py3

[testenv]
deps = pytest
commands =
    pytest --doctest-modules

我还有一个 requirements.txt 文件,它定义了所需的模块:

cmake
osqp
numpy
cvxpy
networkx
matplotlib

和一个 setup.py 文件:

from setuptools import setup, find_packages
... 
requirements = ["numpy","cvxpy","networkx","matplotlib"]
... 
setup(
    name='fairpy', 
    version='1.0', 
    description=...,
    packages=find_packages(),
    install_requires=requirements, 
    ...
)

但是当我从终端 运行 tox 时,我收到一条错误消息,指出找不到模块 numpy:

GLOB sdist-make: /mnt/d/Dropbox/ariel/fairpy/setup.py
py3 inst-nodeps: /mnt/d/Dropbox/ariel/fairpy/.tox/.tmp/package/1/fairpy-1.0.zip
py3 installed: attrs==19.3.0,fairpy==1.0,more-itertools==8.1.0,packaging==20.1,pluggy==0.13.1,py==1.8.1,pyparsing==2.4.6,pytest==5.3.4,six==1.14.0,wcwidth==0.1.8
py3 run-test-pre: PYTHONHASHSEED='188600482'
py3 run-test: commands[0] | pytest --doctest-modules
========================================================== test session starts ==========================================================
platform linux -- Python 3.8.1, pytest-5.3.4, py-1.8.1, pluggy-0.13.1
cachedir: .tox/py3/.pytest_cache
rootdir: /mnt/d/Dropbox/ariel/fairpy
collected 0 items / 20 errors                                                                                                           

================================================================ ERRORS =================================================================
__________________________________________________ ERROR collecting Deng_Qi_Saberi.py ___________________________________________________
Deng_Qi_Saberi.py:13: in <module>
    from agents import *
agents.py:10: in <module>
    import numpy as np
E   ModuleNotFoundError: No module named 'numpy'
...

我安装了 numpy - 在我的 python 3.8.1 终端中,我可以毫无问题地导入 numpy。

我对 tox 做错了什么?

首先,

I have numpy installed - in my python 3.8.1 terminal, I can import numpy with no problem.

tox 会在您 运行 时创建一个虚拟环境,因此您的计算机原始解释器上是否安装了 numpy 并不重要。

其次, 如果你想让tox安装你必须添加的需求文件 deps = -rrequirements.txt 到 tox.ini。 你也可以随时手动添加 numpy 作为依赖项。

第三, tox 在某些情况下有一些依赖项跟踪问题。尝试 运行 tox -r 强制 tox 重新创建其环境,并确保在 setup.py.

的 "install_requires" 部分中提到的 numpy