So I'm using vscode and I installed python, I changed my python interpreter to Python 3.1 which I assumed would change the Python version to 3.1 as well? But when I type python --version it still says 2.7.18... And I also installed pygame using "python3 -m pip install -U pygame --user" in my terminal but still when I try to run this any file that imports pygame it says ImportError: No module named pygame
Other people have said they have the same problem and maybe I'm missing something but their solutions didn't work for me?
Related
I am trying to create a game in python, just a beginner, and I installed pygame using the pip command pip install pygame and it says "requirement already satisfied". So, assuming it is installed, I hop onto VS Code, and the import pygame to check if it is working, and the ImportError: No module named pygame error popped up in the terminal, keep in mind I am on a MacBook. Please help.Here is the image of what the error is
Remember to use pip3 on MacOS, pip is for Python 2.
Try this:
pip3 install pygame
and then run the command:
python3 -c "import pygame"
If the second works, but in VSCode it doesn't, remember to use Python 3, instead of 2 for VSCode.
You shoud try pip3 instead pip because I remembered that osx already have a version of python2.7(which deprecated). And remember to call CLI
python3 game.py
But I prefer using virtual environment ( venv )than install every packages in your user profile.
I made a module named 'calc' and installed it using the following command in cmd:
py -3 -m pip install calc-2.1.tar.gz.
I can import the module and use it when I run python in cmd.
Yet, anywhere else, it doesn't work. Both IDLE and Anaconda raise ModuleNotFoundError.
The same goes for other modules I try to install.
By the way, I'm really new to python, so could you please be a bit more specific with the instructions?
Ok, I figured out what the problem was.
I was using different versions of python (3.7 in IDLE, 3.8 in Spyder, 3.9 in cmd) which is why the module installed by cmd didn't work other places.
I am on MacOS, trying to install pygame but keep getting a "No module named 'pygame'" error.
Started in terminal with
$ python3 -m pip install pygame
it reported error:
command 'gcc' failed with exit status 1
Some answers suggest pygame is incompatible with my current python version 3.8. So I installed python3.7.7 and installed pygame successfully. 1
Ran test with
$ python3 -m pygame.tests
Terminal shows OK. 2
I tried to run a project in pycharm and also import pygram in IDLE, both gave me error: No module named 'pygame'
Also tried to change project interpreter to python 3.7 in Pycharm and installed pygame in pycharm as well. Still getting the same error. 3
I am not sure where went wrong. Appreciate any help! Thank you.
Now that you downgraded your python version, the gcc error isn't showing anymore?
You can try this:
pip install pygame==1.9.2
Also, I don't know if you checked this doc, but it's very helpful: https://www.pygame.org/wiki/MacCompile
import sys
sys.path.append('your python file path /site-packages')
import pygame
I've successfully installed pygame on my computer. When I type "import pygame" there is no error so that means that pygame is installed on my laptop. But, when I type the same thing on Pycharm, I get the following error:
ModuleNotFoundError: No module named 'pygame'
I have initialized pygame, so that's not the problem. I've also tried to install pygame from pycharm and I get this error every time I try to install it:
I've tried everything. The interpreter is correct, too. How can I proceed?
Probably you're using two different python interpreters on your pycharm and on your terminal.
Please,
check the python version on the terminal by python3 --version
And then go to pycharm -> file -> settings -> project -> project
interpreter
and check if both python are the same.
sudo easy_install-3.8 pygame
(This will install the dependencies.)
sudo pip3 install pygame
I have this error when I try to import the pygame module all I did was import Pygame my operating system is Linux Ubuntu 14.04 with python 3.6.9 installed.I think the version i'm running but it's difficult for me to change it, this is the error.
import pygame ModuleNotFoundError: No module named 'pygame'
python refers to Python2, so to install it run python3 -m pip install -U pygame --user and execute your script using python3 yourscript.py.
Make sure everything is done through python3 and pip3! Maybe you want to create an alias.