Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Setup.py Build_Ext --inplace

Tags:

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.

like image 449
G01 Avatar asked Oct 26 '14 15:10

G01


People also ask

What is Python setup py Build_ext?

python setup.py build_ext --inplace uses the setup.py to build our extension modules. The --inplace flag moves the compiled shared objects into the source tree so that they are in the Python search path.

Is setup py install deprecated?

...as of the last few years all direct invocations of setup.py are effectively deprecated in favor of invocations via purpose-built and/or standards-based CLI tools like pip, build and tox.

Do you need a setup py and setup CFG?

you must have a valid setup.py file apart from setup. cfg and pyproject. toml . You can use the same dummy setup file I shared in the previous section that makes just a single call to the setup() method.


1 Answers

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
like image 124
ProProcrastinatrix Avatar answered Oct 19 '22 01:10

ProProcrastinatrix