[python] python NameError: name 'file' is not defined

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 Im not sure if thats it.

Thanks.

This question is related to python pip gunicorn

The answer is


file() is not supported in Python 3

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


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.

EDIT: BTW, the project page clearly mentions that

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


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


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


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'

Examples related to gunicorn

(13: Permission denied) while connecting to upstream:[nginx] python NameError: name 'file' is not defined How many concurrent requests does a single Flask process receive? Gunicorn worker timeout error