Skip to content

Instantly share code, notes, and snippets.

@saravanabalagi
Last active March 6, 2019 16:10
Show Gist options
  • Select an option

  • Save saravanabalagi/57ae41a7d743a55de40b0c83c5f6f8c2 to your computer and use it in GitHub Desktop.

Select an option

Save saravanabalagi/57ae41a7d743a55de40b0c83c5f6f8c2 to your computer and use it in GitHub Desktop.
cmake with python conda env
cd myAwesomeLibrary
mkdir build
cd build
cmake -DPYTHON_LIBRARY=/home/saravanabalagi/.conda/envs/dev/lib/libpython3.6m.so -DPYTHON_EXECUTABLE=/home/saravanabalagi/.conda/envs/dev/bin/python ..
cmake --build ..
@saravanabalagi

Copy link
Copy Markdown
Author

Make sure you also find in build/CMakeCache.txt something like

//Path to a program.
PYTHON_EXECUTABLE:FILEPATH=/home/saravanabalagi/.conda/envs/dev/bin/python

//Path to a library.
PYTHON_LIBRARY:FILEPATH=/home/saravanabalagi/.conda/envs/dev/lib/libpython3.6m.so

where you find your conda env python's path overwritten on variables.

@saravanabalagi

Copy link
Copy Markdown
Author

Usually devs create these variables with prefix PYTHON_, so it is important that you replace other python variables if they include the system python interpreter's path.

Commonly used variables include

  • PYTHON_EXECUTABLE:FILEPATH=/home/saravanabalagi/.conda/envs/dev/bin/python
  • PYTHON_LIBRARY:FILEPATH=/home/saravanabalagi/.conda/envs/dev/lib/libpython3.6m.so
  • PYTHON_INCLUDE_DIR:FILEPATH=/home/saravanabalagi/.conda/envs/dev/include/python3.6m

If you include variables that are not needed, it would appear in CMakeCache.txt as

//No help, variable specified on the command line.
PYTHON_INCLUDE_DIR:UNINITIALIZED=/home/saravanabalagi/.conda/envs/dev/include/python3.6m

@saravanabalagi

Copy link
Copy Markdown
Author

This was used to compile pypangolin python module from Pangolin, where cmake will by default use the system interpreter. Further to make pypangolin work, I had to rename pypangolin.cpython-36m-x86_64-linux-gnu.so inside build/src to pypangolin.so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment