python NameError:未定义名称“文件”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16736833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:29:18  来源:igfitidea点击:

python NameError: name 'file' is not defined

pythonpipgunicorn

提问by nickik

I dont know much about python. I want to start working on the project and the setup instruction says:

我对python了解不多。我想开始处理这个项目,安装说明说:

pip install -r requirements-dev.txt

Simple enougth. The problem is that I get this:

很简单。问题是我得到了这个:

    Downloading/unpacking gunicorn==0.13.4 (from -r requirements.txt (line 7))
  Running setup.py egg_info for package gunicorn
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/tmp/pip-build-root/gunicorn/setup.py", line 18, in <module>
        long_description = file(
    NameError: name 'file' is not defined
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 16, in <module>

  File "/tmp/pip-build-root/gunicorn/setup.py", line 18, in <module>

    long_description = file(

NameError: name 'file' is not defined

I dont understand the problem. Maybe somebody can help out?

我不明白这个问题。也许有人可以帮忙?

I run this on Arch Linux, python defaults to python 3 and the project is not python 3 but Im not sure if thats it.

我在 Arch Linux 上运行它,python 默认为 python 3,项目不是 python 3,但我不确定是否是这样。

Thanks.

谢谢。

回答by Blubber

file is not defined in Python3, which you are using apparently. The package you're instaling is not suitable for Python 3, instead, you should install Python 2.7 and try again.

文件未在 Python3 中定义,您显然正在使用它。您正在安装的包不适用于 Python 3,相反,您应该安装 Python 2.7 并重试。

See: http://docs.python.org/release/3.0/whatsnew/3.0.html#builtins

请参阅:http: //docs.python.org/release/3.0/whatsnew/3.0.html#builtins

回答by mg007

It seems that your project is written in Python < 3. This is because the file()builtin function is removed in Python 3. Try using Python 2to3 toolor edit the erroneous file yourself.

您的项目似乎是用 Python < 3 编写的。这是因为Python 3 中删除file()内置函数。尝试使用 Python 2to3 工具自己编辑错误文件

EDIT: BTW, the project pageclearly mentions that

编辑:顺便说一句,项目页面清楚地提到

Gunicorn requires Python 2.x >= 2.5. Python 3.x support is planned.

Gunicorn 需要 Python 2.x >= 2.5。计划支持 Python 3.x。

回答by parkerproject

file()is not supported in Python 3

file()Python 3 不支持

Use open()instead; see Built-in Functions - open().

使用open()代替; 请参阅内置函数 - open()