2

我正在pip3为我的 python 项目安装模块。我的requirements.txt样子是这样的:

urllib3==1.22
cx_freeze==6.0b1
pytest==3.2.2
pytest-cov==2.5.1
pytest-dependency==0.2

我显然已经pytest添加了我的要求,但是当我运行pip3 install -r requirements.txt它时找不到pytest并显示以下异常:

Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-y300zryw/pytest-dependency/setup.py", line 9, in <module>
    import pytest_dependency
  File "/tmp/pip-build-y300zryw/pytest-dependency/pytest_dependency.py", line 8, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

当我手动执行 apip3 install pytest然后运行我的需求文件时,它工作正常。

为什么 pytest 不从安装requirements.txt

4

2 回答 2

4

对于您的版本pytest-cov需要pytest==3.4.2 如此简单的编辑requirements.txt

urllib3==1.22
cx_freeze==6.0b1
pytest==3.4.2
pytest-cov==2.5.1
pytest-dependency==0.2

第一次对我有帮助,但现在它甚至适用于 3.2.2

$ workon ptest

(ptest) $ python -V
Python 3.5.3

看安装

(ptest) $ pip freeze
attrs==17.4.0
coverage==4.5.1
pluggy==0.6.0
py==1.5.2
six==1.11.0

安装

(ptest) $ cat requirements.txt 
urllib3==1.22
cx_freeze==6.0b1
pytest==3.2.2
pytest-cov==2.5.1
pytest-dependency==0.2

(ptest) $ pip install -r requirements.txt 
Collecting urllib3==1.22 (from -r requirements.txt (line 1))
  Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting cx_freeze==6.0b1 (from -r requirements.txt (line 2))
Collecting pytest==3.2.2 (from -r requirements.txt (line 3))
  Using cached pytest-3.2.2-py2.py3-none-any.whl
Collecting pytest-cov==2.5.1 (from -r requirements.txt (line 4))
  Using cached pytest_cov-2.5.1-py2.py3-none-any.whl
Collecting pytest-dependency==0.2 (from -r requirements.txt (line 5))
Requirement already satisfied: setuptools in /home/user/.virtualenvs/ptest/lib/python3.5/site-packages (from pytest==3.2.2->-r requirements.txt (line 3))
Requirement already satisfied: py>=1.4.33 in /home/user/.virtualenvs/ptest/lib/python3.5/site-packages (from pytest==3.2.2->-r requirements.txt (line 3))
Requirement already satisfied: coverage>=3.7.1 in /home/user/.virtualenvs/ptest/lib/python3.5/site-packages (from pytest-cov==2.5.1->-r requirements.txt (line 4))
Installing collected packages: urllib3, cx-freeze, pytest, pytest-cov, pytest-dependency
Successfully installed cx-freeze-6.0b1 pytest-3.2.2 pytest-cov-2.5.1 pytest-dependency-0.2 urllib3-1.22

核实

(ptest) $ pip freeze
attrs==17.4.0
coverage==4.5.1
cx-Freeze==6.0b1
pluggy==0.6.0
py==1.5.2
pytest==3.2.2
pytest-cov==2.5.1
pytest-dependency==0.2
six==1.11.0
urllib3==1.2
于 2018-03-13T15:06:11.953 回答
1

问题在于pytest-dependency您拥有的版本 - 0.2 太旧了。您不能pytest-dependency==0.2一次性安装pytest

$ pip install pytest-dependency==0.2 pytest

将失败。

但是,此问题已在 0.3 版本中修复,请参阅问题 #13问题 #14已关闭。因此,只需pytest-dependency升级到当前版本,您就可以开始了:

urllib3==1.22
cx_freeze==6.0b1
pytest==3.2.2
pytest-cov==2.5.1
pytest-dependency==0.3.2
于 2018-03-13T19:39:23.657 回答