Tox fails because setup.py can't find the requirements.txt - python

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.

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!

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 *

Related

FileNotFoundError: [Errno 2] No such file or directory: setup.py when importing a custom package from GitHub [duplicate]

When running pip install, I'm getting errors like this:
$ pip install pycairo
Downloading/unpacking pycairo
You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
Downloading pycairo-1.10.0.tar.bz2 (246kB): 246kB downloaded
Running setup.py egg_info for package pycairo
Traceback (most recent call last):
File "<string>", line 16, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/home/naught101/.virtualenvs/virtualenv-3/build/pycairo/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
FileNotFoundError: [Errno 2] No such file or directory: '/home/naught101/.virtualenvs/virtualenv-3/build/pycairo/setup.py'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/naught101/.virtualenvs/virtualenv-3/build/pycairo
Storing complete log in /home/naught101/.pip/pip.log
This is happening for pycairo, sip.
$ pip --version
pip 1.4.1 from /home/naught101/.virtualenvs/virtualenv-3/lib/python3.3/site-packages (python 3.3)
pycairo is not built by setuptools, and therefore can't be installed by pip.
As the INSTALL documentation says:
Install Procedure
-----------------
$ ./waf --help # shows available waf options
$ ./waf configure # use --prefix and --libdir if necessary
# --prefix=/usr --libdir=/usr/lib64 for Fedora 64-bit
$ ./waf build
$ ./waf install
Use
$ python3 ./waf ...
if you have python2 and python3 installed, and the default is python 2.
You can still use pip to fetch it:
$ pip install --download=. pycairo
Downloading/unpacking pycairo
Downloading pycairo-1.10.0.tar.bz2 (246kB): 246kB downloaded
$ tar xf pycairo-1.10.0.tar.bz2
$ cd pycairo-1.10.0
$ python ./waf etc.
Just make sure you use the Python from your virtualenv, and pass the right options to the configure command (--prefix=$VIRTUAL_ENV should be sufficient, but don't quote me on that; you might also have to set the PYTHON environment variable to the path to your virtualenv Python, or other things).
Another option is to use an alternate set of Cairo bindings, like cairocffi. But that's obviously a big change, which may not be appropriate.

Getting tox to reinstall console_scripts when package version changes

I'm using tox to test a module that has a script entry point defined in my setuptools-based setup.py script.
entry_points={
'console_scripts': [
'myscript = mypackage:main',
],
}
tox is configured thus:
[testenv]
commands = pytest --cov=mypackage --cov-report=html --cov-append tests/
deps =
pytest
pytest-cov
usedevelop = True
As expected, the file .tox/py38/lib/python3.8/site-packages/mypackage.egg-link points back to my development directory, which obviously has the new version number. The script installed at .tox/py38/bin/myscript.py includes the below reference to the old version number, and tox isn't updating it, so when I re-run tox after updating the version I end up getting a VersionConflict error.
==================================== ERRORS ====================================
_____________________ ERROR collecting tests/test_args.py ______________________
tests/test_args.py:6: in <module>
import mypackage
.tox/py38/bin/mypackage.py:4: in <module>
__import__('pkg_resources').require('mypackage==1.0.0b1')
.tox/py38/lib/python3.8/site-packages/pkg_resources/__init__.py:900: in require
needed = self.resolve(parse_requirements(requirements))
.tox/py38/lib/python3.8/site-packages/pkg_resources/__init__.py:791: in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
E pkg_resources.VersionConflict: (mypackage 1.0.0b2 (/Users/matt/devel/mypackage), Requirement.parse('mypackage==1.0.0b1'))
tox is installing the following two scripts in its bin directory which don't seem to get updated, and are triggering the above error:
% cat mypackage.py
#!/Users/matt/devel/mypackage/.tox/py38/bin/python
# EASY-INSTALL-DEV-SCRIPT: 'mypackage==1.0.0b1','mypackage.py'
__requires__ = 'mypackage==1.0.0b1'
__import__('pkg_resources').require('mypackage==1.0.0b1')
__file__ = '/Users/matt/devel/mypackage/mypackage.py'
with open(__file__) as f:
exec(compile(f.read(), __file__, 'exec'))
% cat myscript
#!/Users/matt/devel/mypackage/.tox/py38/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'mypackage','console_scripts','myscript'
__requires__ = 'mypackage'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('mypackage', 'console_scripts', 'myscript')()
)
Is there a way to convince tox to do a proper upgrade of the console script in its environment without manually wiping out all of the .tox/ subdirectories every time I change the version number?

Installing pandas with tox for py26

There is an issue when using tox to run pytest for my package using py26 as one of the envs (global env is py3.6, py26 env is py2.6.9 installed via pyenv)
tox.ini file:
[tox]
envlist = py26,py27,py36
[testenv]
deps=
pytest
PyPDT
py26: numpy<1.12.0
py{27,36}: numpy
py26: pandas==0.16.2
py{27,36}: pandas
py26: matplotlib<1.5.0
py{27,36}: matplotlib<2.1.0
commands=pytest
The following error occurs during pandas installation:
Collecting pandas==0.16.2
Using cached pandas-0.16.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/pr/ghw8lmr94c5g9ntx4cp9990w0000gn/T/pip-build-cuCAyE/pandas/setup.py", line 406, in <module>
from wheel.bdist_wheel import bdist_wheel
File "/Users/brianpollack/Coding/scikit-hep/.tox/py26/lib/python2.6/site-packages/wheel/bdist_wheel.py", line 407
ignore=lambda x, y: {'PKG-INFO', 'requires.txt', 'SOURCES.txt',
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/pr/ghw8lmr94c5g9ntx4cp9990w0000gn/T/pip-build-cuCAyE/pandas/
ERROR: could not install deps [setuptools, pytest, PyPDT, numpy<1.12.0, pandas==0.16.2, matplotlib<1.5.0]; v = InvocationError('/Users/brianpollack/Coding/scikit-hep/.tox/py26/bin/pip install setuptools pytest PyPDT numpy<1.12.0 pandas==0.16.2 matplotlib<1.5.0 (see /Users/brianpollack/Coding/scikit-hep/.tox/py26/log/py26-1.log)', 1)
Any idea what's causing this syntax error?
EDIT:
Updated best answer: using -cconstraints.txt to enforce downgraded version of wheel
wheel dropped support for Python 2.6.
To install wheel compatible with Python 2.6 install version 0.29:
source /Users/brianpollack/Coding/scikit-hep/.tox/py26/bin/activate‌​
pip uninstall wheel
pip install wheel==0.29.0
In tox.ini:
[testenv]
deps=
…
py26: wheel==0.29.0
…
Or try constraints file:
[testenv]
deps=
…
-cconstraints.txt
…
constraints.txt:
wheel==0.29.0

File.open(readme) in setup.py isn't found

The setup.py file in a Python package I've sent to pip:
#!/usr/bin/env python
from distutils.core import setup
setup(
#......
long_description=open('README.md').read(),
#....
)
The file README.md exists. When put a breakpoint in setup.py and execute it locally, it reads the file well. However, when I install it from pip (pip install my_lib), it throws an exception during the installation that it's not found:
File "/private/var/folders/ty/0nvksfhn29z_cjb6md2t3x8c0000gn/T/pip_build_alex/my_app123/setup.py", line 14, in <module>
long_description=open('README.md').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
Complete output from command python setup.py egg_info:
UPDATE:
I just downloaded my library from pip, unzipped and discovered that the file README, LICENCE, MANIFEST aren't in it. And they're in gitignore either because they exist at github.
I needed to create MANIFEST.in with the following content:
include README.md
include LICENSE.txt

How should I do to install all dependencies pypi?

I wrote a package available in pypi, python repository and it depends of other packages as I show with the following code of setup.py file.
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
setup(
name='aTXT',
packages=['aTXT'],
# package_data={ '':['*.py'],
# 'bin': ['bin/*'], 'docx': ['docx/*'], 'pdfminer': ['pdfminer']},
version=VERSION,
include_package_data=True,
# arbitrary keywords
install_requires=[
'lxml>=3.2.3',
'docx>=0.2.0',
'pdfminer',
'docopt>=0.6.2',
'PySide',
'kitchen>=1.1.1',
'scandir>=0.8'
],
requires=['docopt', 'scandir', 'lxml', 'PySide', 'kitchen'],
)
When I'd tried to install from pip with:
pip install aTXT
If some of the requirements package are not installed, it raise a Import Error.
But, why not pip try to install all dependencies?
The following is an example if I don't have lxml package installed.
ImportError: No module named lxml
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

Categories