Fatal error: pyconfig.h: No such file or directory

AidanGoldfarb: <p>I need to rebuild my py venv (v3.10.12). Following the ‘documentation’ <a href="https://devguide.python.org/getting-started/setup-building/" rel="noopener nofollow ugc">here</a>, I am able to successfully build and and create a venv. However, when trying to run anything with dynamo on the GPU, I get:</p>
<pre><code class="lang-auto">Python-3.10.12/Include/Python.h:8:10: fatal error: pyconfig.h: No such file or directory
    8 | #include "pyconfig.h"
</code></pre>
<p>Example:</p>
<pre><code class="lang-auto">model = torchvision.models.resnet50().to_cuda()
modelComp = torch.compile(model) #no error
model(input)                     #error here
</code></pre>
<p>I have tried installing dependencies prior to build:</p>
<pre><code class="lang-auto">sudo apt-get build-dep python3
sudo apt-get install pkg-config
sudo apt-get install libssl-dev libffi-dev
</code></pre>
<p>With no luck.</p>
<p>Environment:</p>
<p>torch vision built from source and installed with</p>
<pre><code class="lang-auto">pip install -e /path/to/vision/
</code></pre>
<pre><code class="lang-auto">torch: 2.3.0+cu121
</code></pre>
<pre><code class="lang-auto">python 3.10.12
</code></pre>
<p>Please let me know if there is any other information needed.</p>

ptrblck: <p>I haven’t seen this issue before, but maybe <code>python-dev</code> is needed. I use <code>minicoda/forge</code> to manage virtual Python environments and a quick <code>find / -name pyconfig.h</code> shows it’s available in all envs.<br>
CC <a class="mention" href="/u/malfet">@malfet</a> in case you’ve seen this issue before (I didn’t find anything on GitHub besides a Windows issue).</p>

AidanGoldfarb: <aside class="quote no-group" data-username="ptrblck" data-post="2" data-topic="203239">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/48/1823_2.png" class="avatar"> ptrblck:</div>
<blockquote>
<p>find / -name pyconfig.h</p>
</blockquote>
</aside>
<p>Yes, it exists:<br>
<code>/agoldf6/Python-3.10.12/pyconfig.h</code><br>
Although it is not in:<br>
<code>/agoldf6/Python-3.10.12/Include</code></p>
<p>Moving it in there manually seemed to fix the issue. I don’t want to make this as resolved, as I still do not understand what went wrong when created the environment.</p>

anxianglemon: <p>I am trying to compile</p>
<pre><code class="lang-auto">lemon@clx:~/myfrida/frida$ sudo make
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /home/lemon/myfrida/frida/deps/toolchain-linux-x86_64/bin/ninja
[1/2] Compiling C object subprojects/frida-python/frida/_frida/_frida.abi3.so.p/extension.c.o
FAILED: subprojects/frida-python/frida/_frida/_frida.abi3.so.p/extension.c.o
/usr/bin/cc -Isubprojects/frida-python/frida/_frida/_frida.abi3.so.p -Isubprojects/frida-python/frida/_frida -I../subprojects/frida-python/frida/_frida -Isubprojects/frida-core/src/api -I../subprojects/frida-core/src/api -Isubprojects/frida-gum -I../subprojects/frida-gum -Isubprojects/frida-gum/gum -I../subprojects/frida-gum/gum -I../subprojects/frida-gum/gum/arch-x86 -I../subprojects/frida-gum/gum/arch-arm -I../subprojects/frida-gum/gum/arch-arm64 -I../subprojects/frida-gum/gum/arch-mips -Isubprojects/frida-gum/libs -I../subprojects/frida-gum/libs -Isubprojects/frida-gum/libs/gum/heap -I../subprojects/frida-gum/libs/gum/heap -Isubprojects/frida-gum/libs/gum/prof -I../subprojects/frida-gum/libs/gum/prof -I../subprojects/frida-gum/gum/backend-linux/include -I../subprojects/frida-gum/gum/backend-elf -I../subprojects/frida-gum/gum/backend-libunwind/include -Isubprojects/frida-gum/bindings -I../subprojects/frida-gum/bindings -I/usr/lib/include/python3.10 -I/usr/lib/include/x86_64-linux-gnu/python3.10 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/glib-2.0 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/lib/glib-2.0/include -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/gee-0.8 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/json-glib-1.0 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/capstone -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/libsoup-3.0 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/quickjs -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/gio-unix-2.0 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/libusb-1.0 -I/home/lemon/myfrida/frida/deps/sdk-linux-x86_64/include/nice -fvisibility=hidden -fdiagnostics-color=always -DNDEBUG -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Os -g -ffunction-sections -fdata-sections -fPIC -pthread -DNGTCP2_STATICLIB -DNGHTTP2_STATICLIB -DGUM_STATIC -DFFI_STATIC_BUILD -DG_DISABLE_ASSERT -DG_DISABLE_CHECKS -DG_DISABLE_CAST_CHECKS -DPy_LIMITED_API=0x03070000 -MD -MQ subprojects/frida-python/frida/_frida/_frida.abi3.so.p/extension.c.o -MF subprojects/frida-python/frida/_frida/_frida.abi3.so.p/extension.c.o.d -o subprojects/frida-python/frida/_frida/_frida.abi3.so.p/extension.c.o -c ../subprojects/frida-python/frida/_frida/extension.c
../subprojects/frida-python/frida/_frida/extension.c:33:11: fatal error: pyconfig.h: No such file or directory
   33 | # include &lt;pyconfig.h&gt;
      |           ^~~~~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
Command '['/usr/bin/python3', '/home/lemon/myfrida/frida/releng/meson/meson.py', 'compile']' returned non-zero exit status 1.
make: *** [Makefile:4: all] Error 1
lemon@clx:~/myfrida/frida$ ls /usr/include/python3.10/pyconfig.h
/usr/include/python3.10/pyconfig.h
</code></pre>
<p>The environment I am using is WSL Ubuntu</p>
<p>I tried asking GPT, but it didn’t solve my problem</p>
<p>I saw that you solved the problem, but I couldn’t find the file  ‘Include’</p>
<pre><code class="lang-auto">lemon@clx:/usr/include/python3.10$ ls
Python.h           compile.h              exports.h             interpreteridobject.h  namespaceobject.h  pyerrors.h     pystrcmp.h      token.h
abstract.h         complexobject.h        fileobject.h          intrcheck.h            object.h           pyexpat.h      pystrhex.h      traceback.h
bltinmodule.h      context.h              fileutils.h           iterobject.h           objimpl.h          pyframe.h      pystrtod.h      tracemalloc.h
boolobject.h       cpython                floatobject.h         listobject.h           opcode.h           pyhash.h       pythonrun.h     tupleobject.h
bytearrayobject.h  datetime.h             frameobject.h         longintrepr.h          osdefs.h           pylifecycle.h  pythread.h      typeslots.h
bytesobject.h      descrobject.h          funcobject.h          longobject.h           osmodule.h         pymacconfig.h  rangeobject.h   unicodeobject.h
cellobject.h       dictobject.h           genericaliasobject.h  marshal.h              patchlevel.h       pymacro.h      setobject.h     warnings.h
ceval.h            dynamic_annotations.h  genobject.h           memoryobject.h         py_curses.h        pymath.h       sliceobject.h   weakrefobject.h
classobject.h      enumobject.h           graminit.h            methodobject.h         pycapsule.h        pymem.h        structmember.h
code.h             errcode.h              import.h              modsupport.h           pyconfig.h         pyport.h       structseq.h
codecs.h           eval.h                 internal              moduleobject.h         pydtrace.h         pystate.h      sysmodule.h
</code></pre>
<p>English is not my native language; please excuse typing errors.</p>