Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How might one specify or add a directory to the Python.h search path during a module build/install using setup.py?

I'm running Linux, and have downloaded a python module I must install without access to any but my particular /home/user directory (I have no root privileges nor the option to pursue them).

This of course requires the Python source. This I've downloaded and have laying around in said user directory.

While asking the admin to copy the proper files into /usr/include/python2.7 is easiest way to go about this, I am hoping for a more general and portable solution to this kind of problem.

Changing only data in the module source (MANIFEST.in, README.txt, setup.py, etc.), how might I add an arbitrary directory to the search path for Python.h and friends?

(Without a solution, "python setup.py build" will continue returning with the "Python.h: No such file or directory" error)

Thank you very much.

like image 453
ca2longoria Avatar asked Jun 02 '12 00:06

ca2longoria


People also ask

How do I add a directory to a path in Python?

Clicking on the Environment Variables button o​n the bottom right. In the System variables section, selecting the Path variable and clicking on Edit. The next screen will show all the directories that are currently a part of the PATH variable. Clicking on New and entering Python's install directory.

How do I get the Python package path?

In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.


1 Answers

For building compiled packages, you need to tell the configure step of setup.py to look in a different location for include files. I believe this can be done like so:

python setup.py config --with-includepath=/path/to/your/install/of/python/includes/

You may also need to tell setup.py about the location of other files (such as libraries), in which case take a look at:

python setup.py config --help

and check out the --libraries and --library-dirs options. To change the location the resulting package is installed to, use the prefix option after building, e.g.:

python setup.py install --prefix=/path/to/install/to/

Although the exact combination of options you require might depend on the package you are installing. If you need to do this frequently, I think it can be done by specifying a setup.cfg config file, as discussed here.

like image 53
Mark Streatfield Avatar answered Nov 16 '22 03:11

Mark Streatfield