I already installed pygame for Python3 (on windows)
But now I want to run a source code written with Python2.7
It gives this error when I run the code:
ImportError: No module named pygame
how can i use pygame for python2.7?(how can i fix it?)
thanks
I just did it, it is pretty straight forward. I believe it is similar in any OS since we're talking about python. But I did on Linux, since it is the OS I use most part of the time.
sudo apt-get update
sudo apt-get install python2.7
But on Linux, have your terminal, then:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py
pip2 install pygame
Finally check it importing in python, in the terminal:
$ python2.7
You'll be able to see python 2 open:
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
Then try importing pygame:
import pygame
and you should see:
pygame 2.0.3 (SDL 2.0.16, Python 2.7.18)
Hello from the pygame community. https://www.pygame.org/contribute.html
I solved my problem by using pip for different versions of Python
> py -2 -m pip install pygame
> py -3 -m pip install pygame
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.