关于pip install uwsgi安装失败问题的解决方案

 更新时间:2023年06月12日 10:23:25   作者:小龙狗  
这篇文章主要介绍了关于pip install uwsgi安装失败问题的解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

pip install uwsgi安装失败问题解决

问题描述

Linux下使用python开发,需要uwsgi模块时,常常会出现pip install 失败的情况,就像下图这样。

是什么原因造成的呢?

因为缺少一个python-devel包,所以只需要下载安装这个包就可以解决了。

但是要特别注意python版本要与之对应的问题。

[root@VM_0_13_centos ~]# pip install uwsgi
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting uwsgi
  Downloading http://mirrors.tencentyun.com/pypi/packages/98/b2/19b34b20662d111f7d2f926cdf10e13381761dd7dbd10666b9076cbdcd22/uwsgi-2.0.17.tar.gz (798kB)
    100% |████████████████████████████████| 798kB 2.6MB/s 
Installing collected packages: uwsgi
  Running setup.py install for uwsgi ... error
******省略******
    [gcc -pthread] core/config_py.o
    *** uWSGI compiling embedded plugins ***
    [gcc -pthread] plugins/python/python_plugin.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
     #include <Python.h>
                        ^
    compilation terminated.
    ----------------------------------------
Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-e385dqxe/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-record-azcl8hbu/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-e385dqxe/uwsgi/

解决办法

从yum源上下载安装对应python版本的python-devel,如果不清楚的话先用 python --version 命令查看python版本,然后yum search python3,Tab键搜索出来下载。

[root@VM_0_13_centos ~]# yum install python36u-devel
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration*
******省略******
Installed:
  python36u-devel.x86_64 0:3.6.5-1.ius.centos7                                                         
Complete!

Python-dev是个啥?

linux发行版通常会把类库的头文件和相关的pkg-config分拆成一个单独的xxx-dev(el)包.以下情况需要python-dev包:

1.安装一个源外的python类库, 而这个类库内含需要编译的调用python api的c/c++文件;

2.自己写的一个程序编译需要链接libpythonXX.(a|so)

(不含使用ctypes/ffi或者裸dlsym方式直接调用libpython.so)

其他正常使用python或者通过安装源内的python类库的不需要python-dev.

linux下通过pip安装最新uwsgi

通过yum install uwsgi 安装的uwsgi在进行测试的时候,发现版本是2.0.15,但是启动uwsgi测试的时候报参数错误,后来改用pip安装(先yum remove uwsgi删除老的uwsgi)就成功了。uwsgi安装完成之后的样子

安装pip

wget  https://bootstrap.pypa.io/get-pip.py
python ./get-pip.py

安装uwsgi,一个干净的linux系统安装uwsgi过程中,会遇到以下两个错误。

Exception: you need a C compiler to build uWSGI
  ----------------------------------------
  Failed building wheel for uwsgi
  Running setup.py clean for uwsgi
Failed to build uwsgi
Installing collected packages: uwsgi
  Running setup.py install for uwsgi ... error

解决办法:yum install gcc-*

另外一个错误:

fatal error: Python.h: No such file or directory

解决办法:yum install python-devel

安装成功的打印信息:

[root@VM_68_155_centos ~]# pip install uwsgi
Collecting uwsgi
  Using cached uwsgi-2.0.16.tar.gz
Building wheels for collected packages: uwsgi
  Running setup.py bdist_wheel for uwsgi ... done
  Stored in directory: /root/.cache/pip/wheels/3a/e7/aa/24207bb9d885fe11fab3f7ad7d9d80c538a423d98494d43fd7
Successfully built uwsgi
Installing collected packages: uwsgi
Successfully installed uwsgi-2.0.16
[root@VM_68_155_centos ~]# 

编辑一个简单的测试文件hello.py:

def application(env,start_response):
        start_response('200 OK',[('Content-Type','text/html')])
        return "Hello,world"

启动uwsgi : uwsgi --http-socket :80 --wsgi-file hello.py

[root@VM_68_155_centos ~]# /usr/bin/uwsgi --http-socket :80 --wsgi-file hello.py 
*** Starting uWSGI 2.0.16 (64bit) on [Fri Feb 23 15:31:16 2018] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-16) on 23 February 2018 07:28:20
os: Linux-3.10.0-514.26.2.el7.x86_64 #1 SMP Tue Jul 4 15:04:05 UTC 2017
nodename: VM_68_155_centos
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
dropping root privileges as early as possible
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3895
your memory page size is 4096 bytes
detected max file descriptor number: 100001
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to TCP address :80 fd 3
dropping root privileges after socket binding
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
Python version: 2.7.5 (default, Aug  4 2017, 00:39:18)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7d64c0
dropping root privileges after plugin initialization
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x7d64c0 pid: 6557 (default app)
dropping root privileges after application loading
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 6557, cores: 1)

测试uwsgi-server

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • OpenCV简单标准数字识别的完整实例

    OpenCV简单标准数字识别的完整实例

    这篇文章主要给大家介绍了关于OpenCV简单标准数字识别的相关资料,要通过opencv 进行数字识别离不开训练库的支持,需要对目标图片进行大量的训练,才能做到精准的识别出目标数字,需要的朋友可以参考下
    2021-09-09
  • 10个杀手级应用的Python自动化脚本

    10个杀手级应用的Python自动化脚本

    重复的任务总是耗费时间和枯燥的。如果逐一裁剪100张照片,或者做诸如Fetching APIs、纠正拼写和语法等任务,所有这些都需要大量的时间。为什么不把它们自动化呢?本文详细介绍了10个Python自动化脚本,感兴趣的小伙伴可以阅读一下
    2023-03-03
  • python高阶爬虫实战分析

    python高阶爬虫实战分析

    这篇文章给大家分享了python高阶爬虫实战的相关实例内容以及技巧分析,有兴趣的朋友参考下。
    2018-07-07
  • 编写自定义的Django模板加载器的简单示例

    编写自定义的Django模板加载器的简单示例

    这篇文章主要介绍了编写自定义的Django模板加载器的简单示例,Django是各色人气Python框架中最为著名的一个,需要的朋友可以参考下
    2015-07-07
  • 利用python pywifi实现破解WiFi密码

    利用python pywifi实现破解WiFi密码

    家里没有怎么办,只要你会Python,办法总比困难多,本文就利用pywifi 这个库实验一下如何破解Wi-Fi 密码,注意,该方法仅可用来研究学习所用,需要的朋友可以参考下
    2024-03-03
  • python开发之函数定义实例分析

    python开发之函数定义实例分析

    这篇文章主要介绍了python开发之函数定义方法,以实例形式较为详细的分析了Python中函数的定义与使用技巧,需要的朋友可以参考下
    2015-11-11
  • Python中的分支与循环结构解读

    Python中的分支与循环结构解读

    这篇文章主要介绍了Python中的分支与循环结构解读,在Python编程中,分支(Branch)和循环(Loop)是掌握的关键要素之一,它们允许您根据条件执行不同的代码块,以及重复执行特定任务,需要的朋友可以参考下
    2023-10-10
  • Python变量格式化输出实现原理解析

    Python变量格式化输出实现原理解析

    这篇文章主要介绍了Python变量格式化输出实现原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-08-08
  • pycharm如何调整最大堆发挥最大

    pycharm如何调整最大堆发挥最大

    本文详细介绍了如何在PyCharmar中设置最大堆内存以提高Python程序运行效率,建议将8GB内存设置为约6GB,利用约75%的内存运行效果最佳
    2026-05-05
  • 如何更改Pycharm配置文件的存放路径

    如何更改Pycharm配置文件的存放路径

    Pycharm配置文件默认是放在C盘的,修改存放位置,这样系统重装的时候就不会不见了,下面这篇文章主要给大家介绍了关于如何更改Pycharm配置文件的存放路径的相关资料,需要的朋友可以参考下
    2022-12-12

最新评论