Xuefei Lv
Xuefei Lv

Reputation: 37

When I updating my pip,I meet an error:“NameError: name '_main_' is not defined”

When I updating my pip,I meet an error:NameError: name '_main_' is not defined

C:\Users\16214>python -m pip --upgrade pip
File "D:\Python3\lib\runpy.py", line 193, in _run_module_as_main 
 "__main__", mod_spec)
File "D:\Python3\lib\runpy.py", line 85, in _run_code
 exec(code, run_globals)
File "D:\Python3\lib\site-packages\pip\__main__.py", line 18, in <module>
 sys.exit(_main_.main())
NameError: name '_main_' is not defined

Can anybody help me fix this?

Upvotes: 0

Views: 772

Answers (2)

Xuefei Lv
Xuefei Lv

Reputation: 37

I have solved this problem.
There is a mistake in my \pip\__main__.py file.
I found pip's repository on github and compared my __main__.py file.
In my file,there is a piece of code like this:

from pip._internal import main as _main_  # isort:skip # noqa
if __name__ == '__main__':
    sys.exit(_main_._main())

But on github, it is like this:

from pip._internal import main as _main  # isort:skip # noqa

if __name__ == '__main__':
    sys.exit(_main())

After I modified my code, I solved this problem.

Upvotes: 1

Andy_101
Andy_101

Reputation: 1306

Run this in cmd as admin:

python -m pip install --upgrade pip

if not try opening CMD in the python folder like C:\Python27

C:\Python27>python.exe -m pip install --upgrade pip

and then run the above command in cmd as admin.

Upvotes: 0

Related Questions