Ubuntu 20 安装 uwsgi 失败解决办法

环境:Ubuntu 20.04 LTS
Python 版本:python3.8.10
虚拟环境路径:/home/venv

激活虚拟环境后,安装 uswgi

pip install uwsgi

报错如下:

 ERROR: Command errored out with exit status 1:
     command: /home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3591s32k/uwsgi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3591s32k/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-5m3qkuq_/install-record.txt --single-version-externally-managed --compile --install-headers /home/venv/include/site/python3.8/uwsgi
         cwd: /tmp/pip-install-3591s32k/uwsgi/
    Complete output (92 lines):
    /usr/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'descriptions'
      warnings.warn(msg)
    running install
    using profile: buildconf/default.ini
    detected include path: ['/usr/lib/gcc/x86_64-linux-gnu/9/include', '/usr/local/include', '/usr/include/x86_64-linux-gnu', '/usr/include']
    Patching "bin_name" to properly install_scripts dir
    detected CPU cores: 2
    configured CFLAGS: -O2 -I. -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wformat-signedness -DUWSGI_HAS_IFADDRS -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_VERSION="\"2.0.26\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="26" -DUWSGI_VERSION_REVISION="0" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler);UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(logsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(stats_pusher_socket);"
    *** uWSGI compiling server core ***
    core/utils.o is up to date
    core/protocol.o is up to date
    core/socket.o is up to date
    core/logging.o is up to date
    core/master.o is up to date
    core/master_utils.o is up to date
    core/emperor.o is up to date
    core/notify.o is up to date
    core/mule.o is up to date
    core/subscription.o is up to date
    core/stats.o is up to date
    core/sendfile.o is up to date
    core/async.o is up to date
    core/master_checks.o is up to date
    core/fifo.o is up to date
    core/offload.o is up to date
    core/io.o is up to date
    core/static.o is up to date
    core/websockets.o is up to date
    core/spooler.o is up to date
    core/snmp.o is up to date
    core/exceptions.o is up to date
    core/config.o is up to date
    core/setup_utils.o is up to date
    core/clock.o is up to date
    core/init.o is up to date
    core/buffer.o is up to date
    core/reader.o is up to date
    core/writer.o is up to date
    core/alarm.o is up to date
    core/cron.o is up to date
    core/hooks.o is up to date
    core/plugins.o is up to date
    core/lock.o is up to date
    core/cache.o is up to date
    core/daemons.o is up to date
    core/errors.o is up to date
    core/hash.o is up to date
    core/master_events.o is up to date
    core/chunked.o is up to date
    core/queue.o is up to date
    core/event.o is up to date
    core/signal.o is up to date
    core/strings.o is up to date
    core/progress.o is up to date
    core/timebomb.o is up to date
    core/ini.o is up to date
    core/fsmon.o is up to date
    core/mount.o is up to date
    core/metrics.o is up to date
    core/plugins_builder.o is up to date
    core/sharedarea.o is up to date
    core/rpc.o is up to date
    core/gateway.o is up to date
    core/loop.o is up to date
    core/cookie.o is up to date
    core/querystring.o is up to date
    core/rb_timers.o is up to date
    core/transformations.o is up to date
    core/uwsgi.o is up to date
    proto/base.o is up to date
    proto/uwsgi.o is up to date
    proto/http.o is up to date
    proto/fastcgi.o is up to date
    proto/scgi.o is up to date
    proto/puwsgi.o is up to date
    lib/linux_ns.o is up to date
    core/yaml.o is up to date
    [thread 1][x86_64-linux-gnu-gcc -pthread] core/dot_h.o
    [thread 0][x86_64-linux-gnu-gcc -pthread] core/config_py.o
    *** 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:
    plugins/python/uwsgi_python.h:4:10: fatal error: Python.h: No such file or directory
        4 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    In file included from plugins/python/pyutils.c:1:
    plugins/python/uwsgi_python.h:4:10: fatal error: Python.h: No such file or directory
        4 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-3591s32k/uwsgi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-3591s32k/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-5m3qkuq_/install-record.txt --single-version-externally-managed --compile --install-headers /home/venv/include/site/python3.8/uwsgi Check the logs for full command output.

解决办法:安装对应的 Python 对应版本的编译依赖包即可
,比如我这里是 python3.8,即安装 3.8-dev 如下命令:

apt-get install python3.8-dev

然后直接在虚拟环境里安装 uwsgi 就可以了

pip install uwsgi

或者

pip3.8 install uwsgi

这一切都可以在虚拟环境激活的时候完成,不需要卸载 Python 环境或者重新创建虚拟环境,非常简单

上一篇:【中项第三版】系统集成项目管理工程师 | 第 5 章 软件工程② | 5.4 - 5.8


下一篇:基于STM32设计的智能门锁(微信小程序+手机APP等多种方式开锁)(188)