pygame installed in pycharm but still showing no module named pygame - python

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

Related

Can't install pygame on macos

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?

ImportError: No module named pygame, how do you fix this on a mac?

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.

Python: ModuleNotFoundError despite module being installed

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.

Can't install pygame on pycharm

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

Python error no module named pygame eventhough it's installed

I installed pygame with pip and it successfully installed.I even add it to the path.when I check it in cmd with py -m pip install -U pygame--user it works fine and shows that pygame is installed but when I want to run the code import python in idle it sends back an error that no module named pygame.I tried and figured out that if I write the code import pygame in the shell it works but if I want to try it in idle(or the shell that opens with running ths idle)it doesn't work. Can any one please tell me whats going on here and how can I make it work??
Btw both my python and pygame are for win64 and I'm using windows10
The same things happened to me a few days ago. I fixed it by deleting Homebrew and then reinstalling it. I would go here for context:
https://brew.sh/

Categories

Resources