58

I'm trying to install uswgi in a virutal env on linux ubuntu, python 3.5.2 I do

pip install uwsgi

I got this error

Failed building wheel for uwsgi

and at the end of the installing logs

    *** uWSGI compiling embedded plugins ***
[thread 0][x86_64-linux-gnu-gcc -pthread] plugins/python/python_plugin.o
[thread 1][x86_64-linux-gnu-gcc -pthread] plugins/python/pyutils.o
In file included from plugins/python/python_plugin.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
compilation terminated.
In file included from plugins/python/pyutils.c:1:0:
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory
compilation terminated.

----------------------------------------

Command "/home/ubuntu/envflask/env/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-wthov1ur/uwsgi/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-quiupta5-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/ubuntu/envflask/env/include/site/python3.5/uwsgi" failed with error code 1 in /tmp/pip-build-wthov1ur/uwsgi/
  • Linux 4.4.0-66-generic x86_64
  • Python 3.5.2

It is any solution for this? Thanks

carla
  • 1,970
  • 1
  • 31
  • 44
Alvaro B
  • 596
  • 1
  • 4
  • 7

12 Answers12

71

You need to install Python3.5 development files, so run this command:

apt-get install python3.5-dev

The above command will install Python 3 headers to build uWSGI from source.

McGrady
  • 10,869
  • 13
  • 47
  • 69
  • This works! Thanks!! now I have uWSGI installed in my virutal env. But i can not run it with python 3. I run with `sudo uwsgi --http :80 --wsgi-file main.py --callable app --master --processes 8 --threads 2` and I see this line `Python version: 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]` – Alvaro B May 18 '17 at 03:21
  • Because `sudo` means to run some command as some other user (root by default), you can see [this question](https://superuser.com/questions/600349/why-sudo-python-and-python-in-terminal-start-two-different-versions-python/600350). – McGrady May 18 '17 at 03:24
  • but if I don't run like sudo, I can not run it using port 80 – Alvaro B May 18 '17 at 03:32
  • 1
    @AlvaroB, just install proper python version in virtualenv. `$ virtualenv -p python3.6 .venv` and then `$ . .venv/bin/activate` and ' $ python --version ' must be `3.6.x` – kore666 Jul 18 '18 at 12:49
  • I have migrated to python3.6 and it's wokring fine. Thanks! – Alvaro B Aug 02 '18 at 20:15
  • 1
    Thanks! You saved my time! I installed python3.7-dev as I use python3.7.9. – iconique Jan 08 '21 at 21:09
37

apt-get install build-essential python3-dev

From the uWSGI documentation:

uWSGI is a (big) C application, so you need a C compiler (like gcc or clang) and the Python development headers. On a Debian-based distro an apt-get install build-essential python-dev will be enough.

For Python3, just change that to python3-dev.

$ python3 --version Python 3.5.2 $ pip3 freeze uWSGI==2.0.15

JCotton
  • 11,650
  • 5
  • 53
  • 59
16

For anyone with python 3.6 facing the same problem here is the step to solve it :

Get python 3.6 dev tools from this ppa:

sudo add-apt-repository ppa:deadsnakes/ppa

Then update your package list with :

sudo apt-get update

and then install your dev tools with 3.6 version

apt-get install build-essential python3.6-dev

Activate your virtual environment with and then install uwsgi:

pip install uwsgi
Espoir Murhabazi
  • 5,973
  • 5
  • 42
  • 73
7

Debian have package depending on all supported Python 3 development packages:

apt-get install python3-all-dev
neclude
  • 71
  • 1
  • 2
6

I have faced the same issue. I solve it by following:

sudo apt install libpython3.7-dev

If your python version is 3.6, then use 3.6 instead of 3.7. After that install uwsgi using pip:

sudo pip install uwsgi
mahbubcseju
  • 2,200
  • 2
  • 16
  • 21
6

Alternatively, you can use conda to install uwsgi, but make sure to use conda-forge channel:

conda install -c conda-forge uwsgi
tjysdsg
  • 656
  • 8
  • 19
5

if you faced with the same problem while installing uwsgi under python3.6 just

apt-get install python3.6-dev

In my case uwsgi installed via buildout

NOTE: may be you should add valid ppa

kore666
  • 1,501
  • 1
  • 11
  • 8
2

You must install python3-devel package:

$ sudo dnf install python3-devel -y

And then install uwsgi module:

$ pip install uwsgi
soroush
  • 170
  • 2
  • 9
2

I was stuck on this one, trying to install uwsgi on Unbuntu in Windows Linux Subsystem.
Although it didn't give permission error, I solved it by running:

sudo pip install uwsgi
Elar Saks
  • 151
  • 5
0

For openSUSE (tumbleweed),

  1. I deactivated and deleted my venv
  2. installed python3-devel via yast2
  3. then recreated and activated my venv
  4. and pip install uwsgi
Aaron Williams
  • 655
  • 4
  • 11
0

if you want to install uwsgi command, through

curl http://uwsgi.it/install | bash -s default /tmp/uwsgi

mv /tmp/uwsgi to /usr/local what ever

penny chan
  • 769
  • 1
  • 10
  • 15
0

I had a similar issue when installing uwsgi

 ibpython3.7m.a’ generated with LTO version 6.0 instead of the expected 8.1. 

The default Python was 3.7 and I had to use pip3.8 to solve this problem. However I have another problem. Running

sudo uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app

generates the following error:

uwsgi: invalid option -- 'w'
getopt_long() error

I have tried many things, including modular installation The main problem is that the default uwsgi folder is /usr/bin/uwsgi but when I install using pip3.8 it is not set to default. I couldn't resolve this problem and I switched to fastapi and uvicorn. I'm still interested to find the solution to my problem.

Matt Najarian
  • 151
  • 1
  • 8