distutils: How to pass a user defined parameter to setup.py?

As Setuptools/Distuils are horribly documented, I had problems finding the answer to this myself. But eventually I stumbled across this example. Also, this similar question was helpful. Basically, a custom command with an option would look like: from distutils.core import setup, Command class InstallCommand(Command): description = “Installs the foo.” user_options = [ (‘foo=’, None, ‘Specify … Read more

Don’t touch my shebang

Of course you can move the development directory around. Distutils changes the paths to the python that you should run with when you run it. It’s in Grok run when you run the buildout. Move and re-run the bootstrap and the buildout. Done! Distutils changes the path to the Python you use to run distutils … Read more

Make distutils look for numpy header files in the correct place

Use numpy.get_include(): from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext import numpy as np # <—- New line ext_modules = [Extension(“hello”, [“hello.pyx”], include_dirs=[get_numpy_include()])] # <—- New argument setup( name=”Hello world app”, cmdclass = {‘build_ext’: build_ext}, ext_modules = ext_modules )

Combine –user with –prefix error with setup.py install

One time workaround: pip install –user –install-option=”–prefix=” <package_name> or python setup.py install –user –prefix= Note that there is no text (not even whitespace) after the =. Do not forget the –user flag. Installing multiple packages: Create ~/.pydistutils.cfg (or equivalent for your OS/platform) with the following contents: [install] prefix= Note that there is no text (not … Read more

How can I add post-install scripts to easy_install / setuptools / distutils?

It depends on how the user installs your package. If the user actually runs “setup.py install”, it’s fairly easy: Just add another subcommand to the install command (say, install_vim), whose run() method will copy the files you want in the places where you want them. You can add your subcommand to install.sub_commands, and pass the … Read more

Execute a Python script post install using distutils / setuptools

The way to address these deficiences is: Get the full path to the Python interpreter executing setup.py from sys.executable. Classes inheriting from distutils.cmd.Command (such as distutils.command.install.install which we use here) implement the execute method, which executes a given function in a “safe way” i.e. respecting the dry-run flag. Note however that the –dry-run option is … Read more