python NameError: name 'file' is not defined
Asked Answered
E

5

78

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

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 I'm not sure if that's it.

Eosinophil answered 24/5, 2013 at 14:2 Comment(0)
D
195

file() is not supported in Python 3

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

Durden answered 27/11, 2014 at 19:25 Comment(0)
T
9

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 tool or edit the erroneous file yourself.

The project page clearly mentions that

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

Tabshey answered 24/5, 2013 at 14:17 Comment(3)
For someone who claims he's not familiar with Python I think it might be a bad idea to try to port Gunicorn to Python 3 :). It's just not going to work, using Python 2.7 is the better option here.Pauperize
My bad! I missed those words... Sorry :(Tabshey
do you know the exact fix which converts from file to open in 2to3? I was looking for it, but according to the documentation it seems that this part needs to be changed manually because it is not implemented :(Multivibrator
P
5

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.

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

Pauperize answered 24/5, 2013 at 14:4 Comment(1)
(if OP really uses Python 3.x) Gunicorn 0.13.4 requires Python 2.x >= 2.5. Source: "Installation" section at: pypi.python.org/pypi/gunicorn/0.13.4Sutlej
I
1

Search the function file() on your entire code, and replace it with open().

Insnare answered 11/5, 2023 at 8:38 Comment(0)
D
-3

To solve this error, it is enough to add from google.colab import files in your code!

Duplessismornay answered 5/11, 2020 at 8:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.