4

I am trying to install mod_wsgi on Ubuntu. When running the "sudo make" command as described on the mod_wsgi website I receive the error:

src/server/wsgi_python.h:24:10: fatal error: Python.h: No such file or directory

The mod_wsgi troubleshoot section and other posts on SO (1,2,3) say to install python-dev of the correct version. This is already done based on the below output. Python3 running 3.6.7 and apt-get saying python3-dev is on the newest version of 3.6.7.

$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 

$ sudo apt-get install python3-dev
...
python3-dev is already the newest version (3.6.7-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.

So it seems like the Python.h file is there but make can't find it. I looked at this SO post (4) but I don't think it applies to me as I am able to locate Python.h.

$ locate Python.h
/usr/include/python3.6m/Python.h

I am unsure where to go next with this. Python3.6-dev is installed and I can locate Python.h, but make cannot. I am using a venv that Pycharm created for me automatically and I have a hunch it's involved in the problem but I'm not sure how to follow up on this hunch. I am running make on the same terminal as python3 and apt-get so they should be using same environment vars (is my understanding).

Any suggestions from anyone on next steps?

esafresa
  • 480
  • 7
  • 19

2 Answers2

3

To add to the above answer (because I'm stubborn), I'll note that you have to have the python[3]-dev package installed (this is the package that provides Python.h). On ubuntu, apt install python3-dev sorted this out for me.

Zeph
  • 362
  • 3
  • 11
  • I solved my issue by installing python-dev to use a script that works only with Python 2. – baptx Jun 29 '21 at 15:56
1

I ran ./configure for mod_wsgi and saw the output checking for python... /usr/bin/python. When I run locate Python.h it gives me /usr/include/python3.6m/Python.h. So it looks like the configuration was finding the wrong version of python. I then ran ./configure --with-python=/usr/bin/python3.6m as suggested by the mod_wsgi documentation. Now running make was successful.

I later found out this is the tougher way to install mod_wsgi though. I ended up just following this tecadmin guide which says to run the command sudo apt-get install libapache2-mod-wsgi. This is what I did and mod_wsgi is now working with apache.

esafresa
  • 480
  • 7
  • 19