Chulup Chulup - 1 year ago 96
Python Question

Install-time dependencies in requirements.txt

I'm using tox to prepare venv and run unit tests and my application needs openopt library which in turn imports

in its

No matter how I order numpy and openopt in my requirements.txt I can't ensure numpy is installed before 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.

Answer Source

If you use requirements.txt already, an easy (but admittedly ugly) solution would be:

  1. create two (or more) requirements files (e.g. requirements-0.txt and requirements-1.txt (hopefully with better names)).
  2. sort the packages by dependency into those files
  3. use commands instead of deps to install them in the right order


deps = 
    # whatever else where order does not matter

commands =
    pip install -r {toxinidir}/requirements-0.txt
    pip install -r {toxinidir}/requirements-1.txt
    # ... and more if needed

    # now do your actual testing ...
    py.test tests/unit

... or if you want to keep it even simpler, just stick the offending package right in front of your single requirements.txt

commands =
    pip install <nasty dependency>
    pip install -r {toxinidir}/requirements.txt        
    py.test tests/unit
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download