I have run into this under MacOS (10.11), but have seen the same problem under various Linuxes as well. I installed the "official" Python3 package, it goes into /Library/Frameworks/Python.framework/Versions/3.4
. (Note: the examples below use Python 3.4, but the issue persists with 3.5 as well. I have no access to a machine that has Python 3.6 due to lack of admin privileges, should the issue have been solved in 3.6.)
I need virtual environments and I need the python-config
script to figure out which libraries Python3 uses because my project combines Python and C++ code.
If I set up the virtual environment with virtualenv
, everything is fine:
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/3.4/bin/virtualenv
$ virtualenv --python=$(which python3) vienv
Running virtualenv with interpreter /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
Using base prefix '/Library/Frameworks/Python.framework/Versions/3.4'
[...blabla...]
Installing setuptools, pip, wheel...done.
$ source vienv/bin/activate
(vienv) $ which python-config
/Users/XXXXX/DEV/STANDALONE/misc/python/vienv/bin/python-config
(vienv) $ python-config --libs
-lpython3.4m -ldl -framework CoreFoundation
However, pyvenv
forgets to set up python-config
in the virtual environment:
$which pyvenv
/Library/Frameworks/Python.framework/Versions/3.4/bin/pyvenv
$ pyvenv pe
$ source pe/bin/activate
(pe) $ which python-config
/usr/bin/python-config # !!! Here's the problem !!!
(pe) $ python-config --libs
-lpython2.7 -ldl -framework CoreFoundation
In other words, the system default Python2 python-config
stays in my PATH
even though I activated the virtual environment.
Now you could say: What's the problem? Use virtualenv
and be done with it. However, virtualenv
needs to be installed extra via pip
and this requires admin rights which I do not always have. pyvenv
, OTOH, comes with Python3, or at least that was my understanding.
You could also say: Why don't you just install python-config
in your virtual environment using pip
? Here's why:
(pe) $ pip install python-config
Requirement already satisfied (use --upgrade to upgrade): python-config in ./pe/lib/python3.4/site-packages
Cleaning up...
Yes, the package is there, but the script itself is not installed into the bin
subdirectory of the virtual environment.
Summary: I would like to configure my project so that it can be installed only using the Python3 standard modules/tools, and it does not depend on extra stuff such as virtualenv
. And I do not want to pester sysadmins :-)
Question: is there a workaround to get pyvenv
install python-config
properly? Or: is there another way to figure out which headers and libraries I should use if I link my C++ code against a particular Python3 installation in a virtual environment?