Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pip does not install my package dependencies

Tags:

python

pip

I have developed a python package on github that I released on PyPi. It installs with pip install PACKAGENAME, but does not do anything with the dependencies that are stated in the "install_requires" of the setup.py file.

Weirdly enough, the zip file of the associated release does install all dependencies.. I tried with different virtual environments and on different computers but it never installs the dependencies.. Any help appreciated.

like image 816
crazjo Avatar asked Nov 15 '19 17:11

crazjo


2 Answers

pip install pythutils downloads a wheel if it's available — and it's available for your package.

When generating a wheel setuptools runs python setup.py locally but doesn't include setup.py into the wheel. Download your wheel file and unzip it (it's just a zip archive) — there is your main package directory pythutils and a directory with metadata pythutils-1.1.1.dist-info. In the metadata directory there is a file METADATA that usually lists static dependencies but your file doesn't list any. Because when you were generating wheels all your dependencies has already been installed so all your dynamic code paths were skipped.

The archive that you downloaded from Github release install dependencies because it's not a wheel so pip runs python setup.py install and your dynamic dependencies work.

What you can do? My advice is to avoid dynamic dependencies. Declare static dependencies and allow pip to decide what versions to install:

install_requires=[
    'numpy==1.16.5; python_version>="2" and python_version<"3"',
    'numpy; python_version>="3"',
],

Another approach would be to create version-specific wheel files — one for Python 2 and another for Python 3 — with fixed dependencies.

Yet another approach is to not publish wheels at all and only publish sdist (source distribution). Then pip is forced to run python setup.py install on the target machine. That not the best approach and it certainly will be problematic for packages with C extensions (user must have a compiler and developer tools to install from sources).

like image 164
phd Avatar answered Sep 30 '22 05:09

phd


Your setup.py does a series of checks like

try:
    import numpy
except ImportError:
    if sys.version_info[0] == 2:
        install_requires.append('numpy==1.16.5')
    if sys.version_info[0] == 3:
        install_requires.append("numpy")

Presumably the system where you ran it had all the required modules already installed, and so ended up with an empty list in install_requires. But this is the wrong way to do it anyway; you should simply make a static list (or two static lists, one each for Python 2 and Python 3 if you really want to support both in the same package).

like image 33
tripleee Avatar answered Sep 30 '22 05:09

tripleee