19

Running the following command gives me the following error:

pip install pygame

Error Stack:

Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
    from typing import List, Optional
ImportError: No module named 'typing'
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Rydex
  • 395
  • 1
  • 3
  • 9
  • 7
    Python 3.4 was released over 7 years ago and has already reached end-of-life. Current versions of `pip` might not support Python 3.4 anymore. – Matthias Apr 27 '21 at 06:41
  • On what version of Windows? What Python "distribution"? [Anaconda](https://en.wikipedia.org/wiki/Anaconda_(Python_distribution))? What version? – Peter Mortensen Sep 10 '21 at 05:35

9 Answers9

35

Running this line in a Mac terminal fixed it for me:

/usr/local/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip

I had the same issue. I also first tried the pip3 install pygame which was previously mentioned, before running this line. You may have to do that first. For the individual who said to try

pip install typing

that line of code will simply produce the same error. To fix it, you have to use to the aforementioned command(s).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
gatorcoder
  • 371
  • 2
  • 5
  • been having this issue for few days pip complaining the same error for everything. `/usr/local/opt/python@3.9/bin/python3.9 -m pip install --upgrade pip` worked for me. – Dami Jun 26 '21 at 05:43
15

I also ran into the same problem, because I made the foolish mistake of upgrading pip as suggested by Python.

I fixed this by downloading get_pip.py for python3.4 at https://bootstrap.pypa.io/pip/3.4/get-pip.py and running it:

python get_pip.py

It will automatically download the latest compatible version of pip (19.1.1 in this case).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
toti08
  • 2,448
  • 5
  • 24
  • 36
  • 1
    `curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py` download and then `python get_pip.py` – Radzor Jul 19 '21 at 01:32
9

Try to:

  1. wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
  2. python get-pip.py
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hj Fg
  • 99
  • 1
  • 4
    Welcome to Stack Overflow! While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch Jun 09 '21 at 10:27
  • that helped me, but with python3.6 instead of 2.7 – qba-dev Oct 25 '21 at 22:50
8

Do the following:

sudo apt update
sudo apt-get upgrade

If there is a problem, do:

sudo apt --fix-broken install
sudo apt-get upgrade

If there is still a problem, remove and recreate your venv. And Reinstall your requirements:

rm -rf venv
python3.9 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ADf
  • 91
  • 1
  • 3
1

I encountered the same error on Ubuntu 20.04 when using python3.9, I tried to run sudo apt update && sudo apt upgrade.

The output advised me to run sudo apt --fix-broken install, which had solved my problem and python3.9 is running fine now.

ustni_voda
  • 11
  • 1
0

I have also met this problem. Any command that starts with pip have the same error, ImportError: No module named 'typing'.

Finally, python -m pip install typing solved it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Instein
  • 2,484
  • 1
  • 9
  • 14
0

I had this error using pip because my Ubuntu installation with Python 2.7 and Python 3.5 were crossed using the versions and pip.

My solution was to uninstall Python 2.7 and pip 2.7. I also uninstalled Python 3.5 and pip 3.

I then installed Python 3.7 using these directions: Installing the latest Python 3.7 on Ubuntu 16.04 and 18.04

I'm not sure if uninstalling 3.5 and adding 3.7 is necessary. You may just be able to remove 2.7 and be good, but this is what worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • You don't need to uninstall, you can specify the version of `pip` that corresponds to the Python version that you want to use, for example `python3.7 -m pip install some_package` – snakecharmerb Jun 24 '21 at 05:12
-3

Try this one:

pip3 install pygame
Shaido
  • 27,497
  • 23
  • 70
  • 73
Dragoslav
  • 19
  • 1
  • Why does 'pip3' vs. 'pip' make a difference? – Peter Mortensen Sep 10 '21 at 05:37
  • @PeterMortensen This is because, in operating systems Mac or Linux, They have Python 2.7 built-in (i think, for the most part) So, if you run ```pip``` The command line is gonna run Python 2.7 pip interpreter. When you do ```pip3``` It tells the command line to run the Python 3.9 pip interpreter. – Rydex Oct 26 '21 at 02:32
-5

It looks like you are importing from the package 'typing' but you do not have it installed. Try installing the package:

pip install typing
S. A.
  • 123
  • 1
  • 7
  • 8
    A much better fix is to upgrade to a recent Python version which has it included in the standard library. Chances are the library you are trying to use won't work very well in 3.4 either. – tripleee Apr 27 '21 at 07:37
  • 6
    in the question pip itself is failing as it tries to import typing and typing is not installed. so you cannot run pip install to fix this. e.g. redhat run `yum install python-typing` However, the real problem might be that python packages are upgraded to python3.? and pip is running python2 so ... heh, ... – gaoithe May 18 '21 at 11:28
  • 2
    @gaoithe I had the same issue for my python2 pip. Turns out that I needed to downgrade pip. https://stackoverflow.com/a/65871131/5195136 – AMVaddictionist Jun 13 '21 at 21:41