0

I want to install pygame on my PC when I type pip in cmd I get this error:

  File "C:\Python34\Scripts\pip3-script.py", line 9, in <module>
    load_entry_point('pip==21.1', 'console_scripts', 'pip3')()
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 558, in load_entry_point
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2682, in load_entry_point
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2355, in load
  File "C:\Python34\lib\site-packages\setuptools-18.1-py3.4.egg\pkg_resources\__
init__.py", line 2361, in resolve
  File "C:\Users\user\AppData\Roaming\Python\Python34\site-packages\pip\__init__
.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named 'typing'
Belal Ahmed
  • 36
  • 2
  • 8
  • 1
    Python 3.4 does not have the `typing` module, upgrade your python to a different version, preferably Python 3.5 or higher – python_user May 01 '21 at 09:15
  • 2
    Does this answer your question? [Pip command line "ImportError: No Module Named Typing"](https://stackoverflow.com/questions/67278017/pip-command-line-importerror-no-module-named-typing) – python_user May 01 '21 at 09:17
  • I have Python 3.5.0a1 but its throwing the same error – Belal Ahmed May 01 '21 at 09:17
  • @python_user it didn't helped – Belal Ahmed May 01 '21 at 09:18
  • 1
    `typing` is from `3.5.0 beta 1` not the alpha version you use, why are you using the alpha version now anyway? when I meant 3.5 or higher I meant the final release – python_user May 01 '21 at 09:20
  • 1
    The `pygame` documentation "https://www.pygame.org/wiki/GettingStarted#Pygame%20Installation says to use Python 3.7.7 or later. I suggest you follow that advice. Python 3.4 dates from 2014. Python 3.5 dates from 2015. Both have reached end-of-life. There is no good reason to use either of them in new code, and it is also not reasonable to expect modules from PyPI to support end-of-life versions. – BoarGules May 01 '21 at 09:51
  • @BoarGules I am not able to install any package, Its not that it is giving error only while installing pygame – Belal Ahmed May 01 '21 at 11:08

3 Answers3

3

If you accidentally upgraded your pip, you are unfortunately unable to use pip to restore your previous version as pip is broken.

If you were on a Linux like Centos you maybe able to reinstall pip using this:

yum reinstall -y python2-pip.noarch python27-python-pip.noarch

But since you are using Windows, maybe try reinstall pip using https://bootstrap.pypa.io/get-pip.py and specify the pip version you want:

https://bootstrap.pypa.io/get-pip.py
1

pip itself is failing as it tries to import typing and typing is not installed. so you cannot run pip install to fix this.

TLDR; 1. use dpkg or yum to install typing (BUT this might not solve the issue with broken pip.

TLDR; 2. I think the problem is a python2.7/python3.x version issue, maybe just use python3.

A similar problem (with same fail to import typing module error) happened me on centos 7.9 after pip was upgraded. Solved for me after a while by just moving to use python3.

pip suggested this:

You are using pip version 8.1.2, however version 21.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I somewhat foolishly rhan that command.

Beware, don't always upgrade things as suggested!

After that pip upgrade pip was broken:

$ pip install httpserver
Traceback (most recent call last):
  File "/bin/pip2", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named typing

So, we can try install the python modules otherwise, e.g. through package manager.

yum install python-typing

That installs fine however another error appears if pip is run.

pip install httpserver
Traceback (most recent call last):
  File "/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 58
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax

So, the real problem might be that some python packages are upgraded to python3.? syntax and pip is running python2, some kind of version mismatch.

So ... well, the solution will vary.

In my case I found that http.server is a python3 only object. python2.7 was the only python installed on this box. The script I wanted to run required python3.

So a workaround for the probhlem is to just use python3:

# check python/pip related packages yum installed:
rpm -qa |grep -E "python|pip"
# install python 3
yum install python3
# now pip3 works, install some libs
pip3 install chevron uuid requests

Python 3 is now installed and working and pip3 for python 3 is working.

After this plain old pip for python2.7 is still broken.

Suggested solution left as an exercise for someone else/the future: Maybe we could fix by completely uninstalling pip and installing an old version again. Please do edit/update answer or add your own if you find out how to fix poor pip.

gaoithe
  • 3,271
  • 1
  • 25
  • 31
  • 1
    You are so correct! Earlier writing 'pip' wasn't giving any error but this annoying error started after updating it! And yes your answer is correct, Now its working fine after reinstalling! Thank you!! finally got an answer in my last question as I am banned anyways thank u again – Belal Ahmed May 19 '21 at 11:03
0

Do pip install typing then retry.

python_ged
  • 496
  • 8
  • 1
    How will i install something if my pip is not only working :,( I mean I will get the same error – Belal Ahmed May 01 '21 at 09:02
  • @BelalAhmed It is not correct to say that your `pip` is not working. It *is* working, and it is telling you quite clearly that the package you are trying to install needs a later version of Python. You cannot fix this by installing `typing` because that is a standard library module, so installing it is neither necessary nor possible if you have the right version of Python. The only way you could install it with `pip` would be if someone had backported it to Python 3.4. They haven't, which is why `pip` won't install it. – BoarGules May 01 '21 at 09:58
  • @BoarGules this problem is not regarding what I am trying to install this problem is maybe because I installed the latest version of pip i.e. 21.1 and I don't have the required build tools but still it build or in other words, I need to install a later version of python (I think), Btw thanks for giving some effort here.. – Belal Ahmed May 01 '21 at 10:56
  • My comment was on the answer that said you should install `typing`. I was explaining why that won't work and why it has nothing to do with the version of `pip`. – BoarGules May 01 '21 at 11:20
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/28878735) – Lucas May 01 '21 at 21:40
  • @BoarGules Sorry for my misunderstanding – Belal Ahmed May 02 '21 at 08:15