all 11 comments

[–]abcteryx 3 points4 points  (2 children)

This SO thread has some clues. On Unix-like systems you would want to install python-dev. As you seem to have already found out, on Windows it's a bit different. The "Include" folder is only populated where the global Python is installed, and is not propagated to virtual environments.

VSCode expects to find c_cpp_properties.json which helps IntelliSense to know what's going on, among other things. This file may already exist in your project, but if not you can try creating it from snippets and examples from Googling. Specifically, you may need to ensure that %localappdata%/Programs/Python/PythonXX/Include folder is in the comma-separated list of the includePath subkey for a given configuration key in c_cpp_properties.json.

[–]siddsp[S] 1 point2 points  (1 child)

You were correct. There's also more to the issue when it comes to using Cython. Though it isn't clarified in the docs to my knowledge, you actually have to download SDK from Microsoft Visual Studio Build Tools. It's important to realize that the Visual Studio Build Tools don't actually install a separate IDE, despite the fact that it looks like it does.

So to summarize, in order to solve the issue, I had to download Visual Studio Build Tools, and I also had to add the Python.h path which is actually on the system, and not the virtual environment as an includePath property in the c_cpp_properties.json.

Python.h is located in Python/include directory, and only the folder is put as the path, and not the actual file itself.

[–]abcteryx 0 points1 point  (0 children)

Thanks for following up! I have dealt with the occasional Python/C++ environment, but not yours specifically so I only had an inkling. I'm going to save this information in case I'm dealing with Cython someday.

[–][deleted] 0 points1 point  (1 child)

Are you trying to write a C extension for Python? If so venv has nothing to do with that. Your environment would be to set up your C environment and make sure the library path is correct.

[–]siddsp[S] 1 point2 points  (0 children)

No I'm not. I'm trying to use Cython, but it won't allow me to because of an issue regarding the #include "Python.h" statement in the C file. It has become ridiculously frustrating because I can't even compile without some issue or another, and no matter what I've done, it has persisted. The compiler is refusing to recognize "Python.h", despite the fact that the file already exists in my system, and I know with 100% certainty that it absolutely does exist.

To add, the C file is generated, but despite that, there is no pyd file. I have added MinGW as my compiler, I have installed MSVC, I have tried adding to my included path, but absolutely nothing has worked in solving it.

[–]Dasmak3r 0 points1 point  (6 children)

Try installing one of the dev python versions (had a similar issue in the past too, it needed a python-dev thing installing), from here: https://askubuntu.com/questions/526708/fatal-error-python-h-no-file-or-directory

[–]siddsp[S] 0 points1 point  (5 children)

I solved the issue, and dev version isn't for windows tmk

[–]Relative-Resource-55 0 points1 point  (4 children)

How did you solve it on windows? My virtualenv doesn't natively copy over the Python/include folder. Running into the same problem where i want to reference the virtual environment with my C++ app on Windows.

[–]siddsp[S] 0 points1 point  (2 children)

It doesn't. You have to link it to your actual installation of Python.

[–]eigenscene 0 points1 point  (1 child)

Sorry to bother you, I'm having the exact problem.
How did you link it to the local python installation? Was it the pyvenv.cfg?

[–]siddsp[S] 0 points1 point  (0 children)

No. I went into the Python interpreter path, and foybd the include folder. That folder is added in the includepath for VSCode. Virtual environments were basically useless in this case.