13

I have added tox to my project and my tox.ini is very simple:

[tox]
envlist = py37

[testenv]
deps = 
    -r{toxinidir}/requirements_test.txt
commands = 
    pytest -v

But when I run tox, I get the following error:

ERROR: invocation failed (exit code 1), logfile: /path/to/my_project/.tox/py37/log/py37-2.log
========================================================================================= log start ==========================================================================================
Processing ./.tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-ywna_4ks/setup.py", line 15, in <module>
        with open(requirements_path) as requirements_file:
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-ywna_4ks/requirements.txt'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-ywna_4ks/
You are using pip version 10.0.1, however version 19.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

========================================================================================== log end ===========================================================================================
__________________________________________________________________________________________ summary ___________________________________________________________________________________________
ERROR:   py37: InvocationError for command /path/to/my_project/.tox/py37/bin/python -m pip install --exists-action w .tox/.tmp/package/1/my_project-0+untagged.30.g6909bfa.dirty.zip (exited with code 1)

Here is my setup.py:

 -*- coding: utf-8 -*-

import os
import sys
from setuptools import setup, find_packages
import versioneer

here = os.path.abspath(os.path.dirname(__file__))

sys.path.insert(0, here)

requirements_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'requirements.txt')

with open(requirements_path) as requirements_file:
    requires = requirements_file.readlines()

setup(
    name='my_project',
    version=versioneer.get_version(),
    cmdclass=versioneer.get_cmdclass(),
    maintainer='Hamed',
    license='BSD',
    py_modules=['my_project'],
    packages=find_packages(),
    package_data={'': ['*.csv', '*.yml', '*.html']},
    include_package_data=True,
    install_requires=requires,
    long_description=open('README.md').read(),
    zip_safe=False
        ]
    },
)

python setup.py install works fine.

It seems that tox is looking for requirements in the tmp dir, but can't find it there. Is there something wrong with my configurations?

I am using tox==3.12.1, python==3.7.3, setuptools==41.0.1, and conda==4.6.9

I've tested this on Arch and SLES 12 and got the same result with both.

Hamed2005
  • 729
  • 8
  • 11
  • 2
    *It seems that tox is looking for requirements in the tmp dir, but can't find it there.* It's not `tox`, it's `pip`. Instead of `python setup.py install` try `pip install .` The problem is most probably is that the generated package (sdist) lacks the file `requirements.txt`. Try `python setup.py sdist` and look into the generated archive. – phd Aug 22 '19 at 16:09
  • 2
    @phd, `pip install .` worked fine as well. But, when I checked the `python setup.py sdist` output, `requirements.txt` was not there. Then I found out that I need to put the `requirements.txt` in my manifest template, and it solved the issue! thanks! – Hamed2005 Aug 23 '19 at 14:35

2 Answers2

21

Based on the point from @phd, I found out that requirements.txt was not present in the source distribution. Adding requirements.txt to the MANIFEST.in solved the issue!

Hamed2005
  • 729
  • 8
  • 11
  • In my case, I forgot to add an `__init__.py` file. I don't understand why that gave me a "FileNotFoundError" about the requirements files, but here we are... – NostraDavid Oct 27 '21 at 17:12
0

Complementing Hamed2005's answer:

I have my requirements split into different files (base_requirements.txt, dev_requirements.txt, etc), all of them in a requirements directory. In this case, you need to add this directory in the MANIFEST.in as

recursive-include requirements *
Arturo Moncada-Torres
  • 1,236
  • 14
  • 23