Skip to content

Adapt python3-config to produce correct output in a virtual environment #515

@A-CGray

Description

@A-CGray

Related to #462

Steps to reproduce

  1. Create a new virtualenv and activate it:
$ pyenv virtualenv 3.12.11 test
$ pyenv activate test
  1. Check that python3-config points to pyenv's shim
$ which python3-config
/home/ali/.pyenv/shims/python3-config
  1. Check where python3-config include directories are (same directory is listed twice for some reason?):
$ python3-config --includes
-I/home/ali/.pyenv/versions/3.12.11/envs/test/include/python3.12 -I/home/ali/.pyenv/versions/3.12.11/envs/test/include/python3.12
  1. Check what's in that directory (nothing)
ls -al /home/ali/.pyenv/versions/3.12.11/envs/test/include/python3.12
total 8
drwxr-xr-x 2 ali ali 4096 Aug 28 10:53 .
drwxr-xr-x 3 ali ali 4096 Aug 28 10:53 ..

Thus, whenever I try to compile something that needs to use python headers, I get the following error:

libsplinemodule.c:18:10: fatal error: Python.h: No such file or directory
   18 | #include <Python.h>
      |          ^~~~~~~~~~
compilation terminated.

I can get around this by linking the virtualenv include directory to the original pyenv include directory:

$ rm -rf /home/ali/.pyenv/versions/3.12.11/envs/test/include
$ ln -s /home/ali/.pyenv/versions/3.12.11/include /home/ali/.pyenv/versions/3.12.11/envs/test/include

Presumably pyenv-virtualenv should do something like this by default when you create the environment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions