简体   繁体   中英

Where are include and libs when using a Python virtual environment?

I use a Python virtual environment. Basically, it works fine, but I run into problems when compiling some Python bindings, namely with libIGL and pybind11.

CMake has the following Python-related variables:

 PYTHON_EXECUTABLE                /users/me/libs/pyvenv/bin/python                           
 PYTHON_INCLUDE_DIR               /usr/include/python2.7                                          
 PYTHON_LIBRARY                   /usr/lib64/libpython2.7.so 

It seems that it can detect the executable which is a python3.5 of the previously-activated virtual environment properly, but it finds some wrong 2.7 paths for include and library.

So I'd like to just set those paths manually to my virtual environment. I browsed around in the directory structure of the virtual environment, and I think I found the includes in /users/me/libs/pyvenv/include/python3.5m . But I can't find the libpython* , there's no *.so file at all in my virtual environment. So which library should I use in that case?

Restrict python libs to match version of found interpreter in cmake:

find_package(PythonInterp REQUIRED)
find_package(PythonLibs "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" REQUIRED )

Or use FindPython if cmake>=3.12 is availble

Similarly to this question , you could run python from within your virtualenv and run

import pybind11
print(pybind11.__file__)
# '/home/me/.pyenv/versions/py36/lib/python3.6/site-packages/pybind11/__init__.py'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM