在虚拟环境中安装uwsgi时出现错误

60

我正在尝试在Linux Ubuntu上的虚拟环境中安装uswgi,Python版本是3.5.2。

pip install uwsgi

我收到了这个错误。

Failed building wheel for uwsgi

安装日志的最后

    *** 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

有什么解决方案吗?谢谢。


将Python升级到3.9.7版本解决了我的问题。 - Superluminal
12个回答

73
你需要安装Python3.5的开发文件,因此运行以下命令:

sudo apt-get install python3.5-dev

apt-get install python3.5-dev
上述命令将安装Python 3头文件以从源代码构建uWSGI。

这个可行!谢谢!!现在我已经在我的虚拟环境中安装了uWSGI。但是我无法使用Python 3运行它。我使用 sudo uwsgi --http :80 --wsgi-file main.py --callable app --master --processes 8 --threads 2 运行,然后看到这一行 Python version: 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] - Alvaro B
因为 sudo 的意思是以其他用户身份运行某些命令(默认为 root),所以您可以查看 此问题 - McGrady
但如果我不像超级用户一样运行,我就无法使用80端口运行它。 - Alvaro B
1
@AlvaroB,只需在虚拟环境中安装正确的Python版本即可。 $ virtualenv -p python3.6 .venv,然后 $ . .venv/bin/activate$ python --version 必须是 3.6.x - kore666
我已经迁移到Python3.6,并且它很好地工作。谢谢! - Alvaro B
1
谢谢!你节省了我的时间!我安装了python3.7-dev,因为我使用的是python3.7.9。 - iconique

37

apt-get install build-essential python3-dev

根据 uWSGI 文档:

uWSGI 是一个庞大的C应用程序,因此您需要一个C编译器(如gcc或clang)和Python开发头文件。在基于Debian的发行版上,使用apt-get install build-essential python-dev就足够了。

对于Python3,只需将其改为python3-dev

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


18

对于遇到同样问题的 Python 3.6 用户,以下是解决步骤:

从此 PPA 获取 Python 3.6 开发工具:

sudo add-apt-repository ppa:deadsnakes/ppa

然后使用以下命令更新您的包列表:

sudo apt-get update

然后使用3.6版本安装你的开发工具

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

使用以下命令激活您的虚拟环境,然后安装uwsgi:

pip install uwsgi

7

Debian有依赖于所有支持的Python 3开发包的软件包:

apt-get install python3-all-dev

6

我曾经遇到过相同的问题,我通过以下方法解决:

sudo apt install libpython3.7-dev

如果你的python版本是3.6,则使用3.6代替3.7。 然后使用pip安装uwsgi:

sudo pip install uwsgi

6

另外,您也可以使用conda来安装uwsgi,但请确保使用conda-forge频道:

conda install -c conda-forge uwsgi

5

如果您在安装Python3.6下的uWSGI时遇到了同样的问题,只需

apt-get install python3.6-dev

在我的情况下,uwsgi是通过buildout安装的。
注意:也许你应该添加有效的ppa。

2

你必须安装python3-devel软件包:

$ sudo dnf install python3-devel -y

然后安装 uwsgi 模块:

$ pip install uwsgi

2
我在安装uwsgi到Windows Linux子系统的Ubuntu上遇到了困难。
虽然没有出现权限错误,但是我通过运行以下命令解决了问题:
sudo pip install uwsgi

0

对于 openSUSE (tumbleweed),

  1. 我停用并删除了我的 venv
  2. 通过 yast2 安装了 python3-devel
  3. 然后重新创建并激活了我的 venv
  4. 最后执行 pip install uwsgi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接