Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install package which has setup_requires from local source distributions

Take the following trivial package which contains setup_requires:

from setuptools import setup
setup(name='my_package', setup_requires=['cython'])

Assuming I have done the following to build it to a source distribution:

$ python setup.py sdist

And downloaded the source distribution for Cython

$ pip install --download ./dist/ --no-use-wheel Cython

So now I have:

$ ls dist/
my_package-0.0.0.tar.gz
Cython-0.21.1.tar.gz

What I'd like to be able to do is install the package on a network-isolated machine using some combination of --find-links, etc.

I'd imagine I could do something like

pip install --no-index --find-links="file:///$(pwd)/dists" dist/my_package-0.0.0.tar.gz

However I get an error that looks like this:

No local packages or download links found for cython (Full text here: http://paste.pound-python.org/show/IxmzEEfQ5yZRU45i2FBM/ )

What I've tried unsuccessfully:

Setting the following

[easy_install]
allow_hosts = ''
find_links = file:///$(pwd)/emr-sdists

in:

/usr/lib/python2.6/distutils/distutils.cfg
~/.pydistutils.cfg
./setup.cfg

I'm currently using the --net none setting of docker to help debug this if it makes it easier for you to get to a reproduction.

like image 707
Anthony Sottile Avatar asked Dec 05 '14 00:12

Anthony Sottile


People also ask

What is Setup_requires in setup py?

The items listed in setup_requires get implicitly installed whenever you execute the setup.py but one of the common ways that the setup.py is executed is via another tool, such as pip , who is already managing dependencies.

Does pip depend on setuptools?

In Fedora, our pip package Recommends setuptools. Practically that means: Majority of users who install pip will get setuptools by default. Users can explicitly uninstall setuptools after installing pip or exclude setuptools when installing pip.

How do I build and install a Python package?

Installing Python Packages with Setup.py To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 Answers

The problem (besides that your --find-links is typoed as dists instead of dist) is that the first thing pip does to install a package is run python setup.py egg_info, without bothering to pass along any of the package-finding information. Pip doesn't actually want setuptools to install any dependencies! It wants setuptools to spit out the dependencies as egg_info so pip can read them and go fetch them itself.

But dependencies in setup_requires are always installed on any invocation of setup.py. I'd go so far as to say that setup_requires is completely incompatible with pip.

The alternative is... to just put your build code in the build step. Pip won't try to build your package until all of its dependencies are installed anyway.

like image 52
Eevee Avatar answered Oct 23 '22 00:10

Eevee