python NameError: global name '__file__' is not defined

前端 未结 12 857
误落风尘
误落风尘 2020-12-02 08:08

When I run this code in python 2.7, I get this error:

Traceback (most recent call last):
File \"C:\\Python26\\Lib\\site-packages\\pyutilib.subprocess-3.5.4\\         


        
12条回答
  •  情话喂你
    2020-12-02 08:28

    You will get this if you are running the commands from the python shell:

    >>> __file__
    Traceback (most recent call last):
      File "", line 1, in 
    NameError: name '__file__' is not defined
    

    You need to execute the file directly, by passing it in as an argument to the python command:

    $ python somefile.py
    

    In your case, it should really be python setup.py install

提交回复
热议问题