背景
因为项目老旧,仍需使用python2.7,仍需要使用pip2 安装依赖。在安装uwsgi的时候,报错。
错误一
Building wheel for uwsgi (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-IwFDiU/uwsgi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-IwFDiU/uwsgi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-6LMh94
cwd: /tmp/pip-install-IwFDiU/uwsgi/
Complete output (35 lines):
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'descriptions'
warnings.warn(msg)
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying uwsgidecorators.py -> build/lib.linux-x86_64-2.7
installing to build/bdist.linux-x86_64/wheel
running install
using profile: buildconf/default.ini
detected include path: ['/usr/local/include', '/usr/include']
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-IwFDiU/uwsgi/setup.py", line 143, in <module>
'Programming Language :: Python :: 3.11',
File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 162, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/usr/local/lib/python2.7/dist-packages/wheel/bdist_wheel.py", line 335, in run
self.run_command('install')
File "/usr/lib/python2.7/distutils/cmd.py", line 326, in run_command
self.distribution.run_command(command)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/tmp/pip-install-IwFDiU/uwsgi/setup.py", line 77, in run
conf = uc.uConf(get_profile())
File "uwsgiconfig.py", line 758, in __init__
raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI
----------------------------------------
ERROR: Failed building wheel for uwsgi
Running setup.py clean for uwsgi
解决办法
sudo apt install -y gcc
错误二
[x86_64-linux-gnu-gcc -pthread] core/dot_h.o
[x86_64-linux-gnu-gcc -pthread] core/config_py.o
*** uWSGI compiling embedded plugins ***
[x86_64-linux-gnu-gcc -pthread] plugins/python/python_plugin.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.
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-MZMAXI/uwsgi/setup.py'"'"'; __file__='"'"'/tmp/pip-install-MZMAXI/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-NlwlI9/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/kyc/.local/include/python2.7/uwsgi Check the logs for full command output.
解决办法
sudo apt-get install python2-dev
结果
安装成功