I'm using tox to prepare venv and run unit tests and my application needs openopt library which in turn imports numpy.distutils.core
in its setup.py.
No matter how I order numpy and openopt in my requirements.txt I can't ensure numpy is installed before setup.py from openopt is executed and exit with ImportError: No module named numpy.distutils.core
How can I fix that? For development I can add numpy to requirements.txt, run tox, add openopt and run tox again but it's not production-ready setup.
UPDATE There is an issue in the tox project that might be implemented that would add functionality to deal with these kinds of problems in a more "official" way. Discussion is here: Add an option to run commands after virtualenv creation but before other steps
UPDATE (a bit more background): The main problem is that it is a BadThing(TM) to assume that some other package is installed already in
setup.py
. these kinds of problems fall into the area of bootstrapping and they can be hellish to handle properly, but usually this is possible with some extra effort. If you really need a different package at setup time, you can look intosetup_requires
and some additional magic (have a look e.g. at setuptools_scm for inspiration). In the worst case and if the package is not to complicated, you can make it part of your package (which comes with its own problems though, like keeping it up to date and possible licensing conflicts).Original answer:
If you use
requirements.txt
already, an easy (but admittedly ugly) solution would be:requirements-0.txt
andrequirements-1.txt
(hopefully with better names))..e.g.
... or if you want to keep it even simpler, just stick the package that is being imported in
setup.py
of another package right in front of your single requirements.txtIt's documented in https://testrun.org/tox/latest/example/basic.html#depending-on-requirements-txt
According to common practice on github, common trick is:
I have a generic way to bootstrap build-time dependencies in
setup.py
. You can use this even if you are not usingtox
. For this case, add the following snippet to the top of thesetup.py
script.Warning: This will install
numpy
usingeasy_install
. Installingnumpy
with this method is somewhat tricky.