Python Setup.py Build_Ext --inplace

G01 picture G01 · Oct 26, 2014 · Viewed 25k times · Source

I am building a Cython program (called for ex. testpackage) using the command:

python setup.py build_ext --inplace

In a folder like /home/USER/Documents/testpackage/. The build runs successfully but when I cd into another folder, I can no longer use the module testpackage. Is there another command I can run instead of --inplace so that I can import testpackage in Python in any folder? I looked at the anaconda/lib/python2.7/site-packages/ folder and do not see any reference to testpackage anywhere. Is this standard for Cython builds?

NOTE: I am doing this through a .sh file using conda build testpackage so the command python setup.py build_ext --inplace is actually in the shell file.

Thank you for your help.

Answer

ProProcrastinatrix picture ProProcrastinatrix · Mar 27, 2015

The --inplace option creates the shared object file (with .so suffix) in the current directory. To use this module from python this file must be in the python path (sys.path).

To install to the system python folder run

python setup.py build_ext
sudo python setup.py install

If you don't have admin rights, you can also install locally using

python setup.py build_ext
python setup.py install --user