安装gunicorn时的语法错误

38 投票
1 回答
9802 浏览
提问于 2025-04-19 06:19

我正在跟着这个Heroku的教程:https://devcenter.heroku.com/articles/getting-started-with-python-o,但是当我在一个虚拟环境中安装gunicorn时,出现了这个错误:

(venv)jabuntu14@ubuntu:~/Desktop/helloflask$ pip install gunicorn
Downloading/unpacking gunicorn
Downloading gunicorn-19.1.1-py2.py3-none-any.whl (104kB): 104kB downloaded
Installing collected packages: gunicorn
Compiling /home/jabuntu14/Desktop/helloflask/venv/build/gunicorn/gunicorn/workers    /_gaiohttp.py ...
File "/home/jabuntu14/Desktop/helloflask/venv/build/gunicorn/gunicorn/workers    /_gaiohttp.py", line 64
    yield from self.wsgi.close()
         ^

SyntaxError: invalid syntax
Successfully installed gunicorn
Cleaning up...

不过,当我运行$foreman start时,它似乎正常工作。

这个错误有多重要呢?有没有什么办法可以解决它?

1 个回答

75

这个错误可以忽略,你的 gunicorn 包已经成功安装了。

这个错误是因为有一段代码只能在 Python 3.3 或更新的版本上运行,但 Gunicorn 支持的旧版本 Python 并不会用到这段代码。

你可以查看这个链接了解更多信息:https://github.com/benoitc/gunicorn/issues/788

这个错误是在安装过程中出现的语法错误,实际上是无害的。

在安装时,setup.py 脚本会尝试收集所有要安装的文件,并将它们编译成 .pyc 字节缓存文件。其中有一个文件只在 Python 3.3 或更高版本中使用,因此这个文件的编译失败了。

这个文件是为了支持 aiohttp http 客户端/服务器包,而这个包本身也只能在 Python 3.3 及以上版本中使用。所以你完全可以忽略这个错误。

撰写回答