0

I'm using cython to convert my python file into c file, but when I tried to compile the c file, it failed for me.

Python.h: No such file or directory
       #include "Python.h"
                    ^
compilation terminated.

I read this post: Cython Fatal Error: Python.h No such file or directory

But I can't understand it. I tried using #include <Python.h> instead of #include "Python.h it also failed for me.

Any solution? Thank you.

Lab
  • 196
  • 3
  • 18
  • Go to the post you linked and read the second answer. – user2357112 May 16 '20 at 03:52
  • @user2357112supportsMonica Sorry, but how do I install sudo? I tried `apt-get` but looks like apt-get needs to install, too. And another method `yum` also needs installation. But all I have now is `pip`. – Lab May 16 '20 at 03:59
  • See second answer: https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory – codedawi May 16 '20 at 04:41
  • Which OS are you using? – Kashinath Patekar May 16 '20 at 05:15
  • @KashinathPatekar Windows 10 – Lab May 16 '20 at 05:45
  • 1
    How are you compiling it? Running setup.py automatically sets the paths (if the headers are installed) but o to otherwise the you may need to add an include path yourself. – DavidW May 16 '20 at 06:35
  • corrected grammar: "but otherwise you may need to add an include path yourself" – DavidW May 16 '20 at 08:18
  • 1
    Without knowing how you compile, hard to tell what is wrong. Please provide this missing information. One could also use cythonize. – ead May 16 '20 at 12:50
  • All the solutions that say `sudo`, `apt-get`, `yum` .etc are for Linux OS (`sudo` is not something you install). Those are not available on Windows, and you will need to setup a compilation env for Windows. How exactly did you run `cython`? The post you linked uses MinGW, and there is an [answer that uses Cygwin](https://stackoverflow.com/a/42983458/2745495). You'll have to describe your env. – Gino Mempin May 16 '20 at 14:05
  • @DavidW @ead @GinoMempin Windows 10, I install cython by `$ pip install Cython`, and convert the file by changing the `.py` filename extension into `.pyx` then run `cython MY_FILE.pyx` in my command line. I got a `.c` file so I open and compile it with Dev C++, then the error occured. – Lab May 16 '20 at 14:13
  • You should probably use a setup.py file instead ([start with following the instructions in the basic tutorial](https://cython.readthedocs.io/en/latest/src/tutorial/cython_tutorial.html#cython-hello-world) ) – DavidW May 16 '20 at 17:12

1 Answers1

0

Use:

sudo updatedb

locate Python.h

export CPATH=/usr/include/python3.5m:$CPATH 

(change your python version here)

export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

mincom
  • 670
  • 5
  • 21
  • 1
    This would be a better answer if you explained how the code you provided answers the question. – pppery Oct 23 '22 at 19:44