Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing the library path as a command line argument to setup.py

modules = [Extension("MyLibrary",
                    src,
                    language = "c++",
                    extra_compile_args=["-fopenmp", "-std=c++11", "-DNOLOG4CXX"], # log4cxx is not currently used
                    extra_link_args=["-fopenmp", "-std=c++11"],
                    include_dirs=[os.path.join(os.path.expanduser("~"), (os.path.join(gtest, "include"))],
                    library_dirs=[log4cxx_library, os.path.join(os.path.expanduser("~"), gtest)],
                    libraries=["log4cxx", "gtest"])]

This is a part of my setup.py script. How do I pass options like include_dirs or library_dirs through command line arguments, so that path could be set up by the user?

like image 831
Alexey Avatar asked Jun 07 '13 12:06

Alexey


People also ask

How do I run a setup py file?

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.

What is Package_dir in setup py?

package_dir = {'': 'lib'} in your setup script. The keys to this dictionary are package names, and an empty package name stands for the root package. The values are directory names relative to your distribution root.


3 Answers

Think this may be what you're looking for:

http://docs.python.org/2/distutils/configfile.html

like image 116
Tom Dalton Avatar answered Oct 13 '22 07:10

Tom Dalton


You can specify it in the setup.cfg file

[build_ext]
include-dir="path/to/your/dir/"
like image 3
Sudar Avatar answered Oct 13 '22 08:10

Sudar


If you're using pip install you can do this to specify library_dirs, for example:

pip install --install-option=build_ext --install-option="--library-dirs=/absolute/path/to/your/library/directory" YourPackage

or just:

pip install --install-option=build_ext --install-option="-L/absolute/path/to/your/library/directory" YourPackage

--global-option also appears to work. See https://stackoverflow.com/a/22942120/1843329

From the docs for pip install:

--install-option Extra arguments to be supplied to the setup.py install command (use like --install-option=”--install-scripts=/usr/local/bin”). Use multiple --install-option options to pass multiple options to setup.py install. If you are using an option with a directory path, be sure to use absolute path.

like image 1
snark Avatar answered Oct 13 '22 08:10

snark