构建uwsgi时出现错误

32

我遇到一个错误,uwsgi的构建失败。 我的环境是Ubuntu,现在我想要安装uwsgi,所以我运行命令pip install uwsgi,但是出现了错误。

 Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 126, in <module>
      distclass=uWSGIDistribution,
    File "/home/ubuntu/anaconda3/lib/python3.5/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/ubuntu/anaconda3/lib/python3.5/site-packages/wheel/bdist_wheel.py", line 215, in run
      self.run_command('install')
    File "/home/ubuntu/anaconda3/lib/python3.5/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 77, in run
      conf = uc.uConf(get_profile())
    File "/tmp/pip-build-9t06jm4_/uwsgi/uwsgiconfig.py", line 742, in __init__
      raise Exception("you need a C compiler to build 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
    Complete output from command /home/ubuntu/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-9t06jm4_/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-oxbyg6gk-record/install-record.txt --single-version-externally-managed --compile:
    /home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py:261: UserWarning: Unknown distribution option: 'descriptions'
      warnings.warn(msg)
    running install
    using profile: buildconf/default.ini
    detected include path: ['/usr/include', '/usr/local/include']
    Traceback (most recent call last):
      File "/tmp/pip-build-9t06jm4_/uwsgi/uwsgiconfig.py", line 734, in __init__
        gcc_version_components = gcc_version.split('.')
    AttributeError: 'NoneType' object has no attribute 'split'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 126, in <module>
        distclass=uWSGIDistribution,
      File "/home/ubuntu/anaconda3/lib/python3.5/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/home/ubuntu/anaconda3/lib/python3.5/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-9t06jm4_/uwsgi/setup.py", line 77, in run
        conf = uc.uConf(get_profile())
      File "/tmp/pip-build-9t06jm4_/uwsgi/uwsgiconfig.py", line 742, in __init__
        raise Exception("you need a C compiler to build uWSGI")
    Exception: you need a C compiler to build uWSGI

    ----------------------------------------
Command "/home/ubuntu/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-9t06jm4_/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-oxbyg6gk-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-9t06jm4_/uwsgi/

我运行了sudo apt-get -y install python-dev命令,但是同样的错误仍然存在。我真的不明白为什么会发生这些错误。我该如何解决?为什么uWSGI告诉我需要C编译器?我该如何解决?

4个回答

40

您的异常明确指出了问题所在:

gcc_version_components = gcc_version.split('.')
AttributeError: 'NoneType' object has no attribute 'split'

raise Exception("you need a C compiler to build uWSGI")
Exception: you need a C compiler to build uWSGI

总的来说,您的系统没有安装C编译器(例如gcc)。尝试安装它。在Ubuntu中,可以使用sudo apt-get install gcc命令进行安装。

另外,我认为这个问题更适合在askubuntu页面提问。


6

这是因为服务器上没有C编译器。如果您正在使用像AWS或Digital Ocean这样的云实例,gcc通常未安装。因此,您需要手动安装它。

sudo apt update
sudo apt install gcc 
sudo pip install uwsgi # Sudo as the server requires root access

应该解决这个问题。


1
永远不要在使用sudo命令时使用pip。这样会破坏权限。你可能之前使用过sudo pip,现在包文件夹中的权限已经混乱了,因此你被迫一直使用sudo命令。 - MuhsinFatih

3

大多数Linux软件包管理器都提供预编译的软件。例如,在Ubuntu上:

最初的回答:

sudo apt install uwsgi-plugin-python3

这将使uwsgi全局可用,不仅限于一个虚拟环境中,并且是安装C编译器的替代方法。翻译成:这样可以让uwsgi在全局范围内使用,而不仅仅是在一个虚拟环境中,也是一种避免安装C编译器的选择。

1
嗯,当你使用“env python”时,这不是一个好主意!!! - Cornea Valentin

3
这个命令对我有用:sudo apt install build-essential python3-dev

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