I'm currently doing a project on my school pc and I want to use pygame, since I have experience with pygame. I have downloaded pygame using this line in the command prompt python -m pip install -U pygame --user when I try this line python3 -m pygame.examples.aliens that is used to see if pygame is downloaded right, it works fine.
But, when I import it in the project I get this error message
File "C:/Users/user/Documents/Programming/test.py", line 10, in
import pygame
ModuleNotFoundError: No module named 'pygame'
extra info:
I use Spyder
It is a Windows pc
Thanks in advance :)
If you have used pygame before this, then have a look if you have any files named pygame.py as I had the same problem as you and my problem was naming a file the same as a core module so check that.
I have done the commands that you put and on the python3 -m pygame.examples.aliens. I got a ModuleNotFoundError: No module named 'pygame'.
When I changed the second command to python instead of python3 it worked after I installed pygame like this pip install pygame to uninstall pygame from how you did it when you install pygame change it to uninstall then try this version.
Related
I am trying to import pygame for an adventure game project in PyCharm. However, when I try to run the main file, this error appears:
File "/Users/########/PycharmProjects/adventure game /main.py", line 1, in <module>
import pygame
File "/Users/########/Library/Python/3.10/lib/python/site-packages/pygame/__init__.py", line 83, in <module>
from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import]
ImportError:
dlopen(/Users/########/Library/Python/3.10/lib/python/site-packages/pygame/base.cpython-310-darwin.so, 2): no suitable image found. Did find:
/Users/########/Library/Python/3.10/lib/python/site-packages/pygame/base.cpython-310-darwin.so: mach-o, but wrong architecture
/Users/########/Library/Python/3.10/lib/python/site-packages/pygame/base.cpython-310-darwin.so: mach-o, but wrong architecture
I have used pygame before on IDLE and it works just fine. On PyCharm I use a Python 3.10 interpreter "/usr/local/bin/python3", with a virtual environment. The Python versions I have are 2.7.16 and 3.10.5, but I cannot use sudo commands to remove the older version. Why can I import pygame on IDLE but not PyCharm, and how can I fix this error?
Make sure you have installed pygame first. When downloading python, did you make sure to enable "ADD PYTHON TO PATH"? If so, enter this into your command prompt:
pip install pygame
If that doesn't work:
pip3 install pygame
If that doesn't work:
python -m pip install pygame
If none of these work, try reinstalling python and make sure to enable "ADD PYTHON TO PATH" when installing. Once installed, try the commands above. This error may be caused by something other than pygame's installation, but I suspect it is because python was installed incorrectly.
After typing SnakeGame.py I am getting the error:
Traceback (most recent call last):
File "SnakeGame.py", line 1, in
import pygame
ImportError: No module named pygame).
Pls give me a solution on how to solve this, I have installed pygame also.
thanks in advance.
That error means that the python interpreter isn't able to find the pygame module.
Are you using a virtual environment? If you are using an IDE like PyCharm, try to install the pygame module inside the IDE console.
pip install pygame
install pygame in CMD write pip install pygame
if you use visual studio code go to market and type pygame then install it ...
enter image description here
visual studio code
I had this same problem a few days ago. My solution was to use a virtual environment. To do this, open a terminal in your folder and use the following commands: 1.) pip install pipenv 2.) pipenv shell 3.) pipenv install pygame
After this, you need to select the correct python interpreter. In VS Code, hit ctrl+shift+p Then click the correct interpreter (should have the name of the folder). Then try to run the file. If that doesn't work, try to run this in the terminal: pipenv run {name of the python file, example: app.py}
Hope that works for you
So pygame is definitely on my computer, and I can call it through the Python terminal that was installed when I downloaded Python 3.8. However, I can't get Spyder to import the pygame module. When I do, it gives me this error message:
ModuleNotFoundError: No module named 'pygame'
Could someone please walk me through how I set up pygame so that Spyder can recognize the pygame module? Thanks!
You've only installed pygame into a different python editor. If you want it to work on spyder, you should install it via the pip that belongs to spyder.
i'm trying import pygame on anaconda. I have try it by open spyder, type code as follows:
import pygame
Then something happens as follows:
Traceback (most recent call lasat):
file "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pygame'
I have done some research on google about this. i think it has something to do with this link: https://anaconda.org/CogSci/pygame.
I have download file on this link. but i don't know what to do about it.
Why can't i import pygame? How can i solve this problem?
The command listed earlier:
conda install -c cogsci pygame
will install pygame 1.9.2a0 which is an older package. I was able to find 1.9.5 at this channel:
conda install -c delichon pygame
But, since that version might be old by the time you read this, you might be better off going to https://anaconda.org/anaconda/repo and searching for pygame there. That way you'll be able to see which versions are available on which channel (like cogsci or delichon).
Forget about my last answer. I got what you're doing wrong. The modules/packages installations must happen in a cmd, not from the python shell. You're trying to install it from the python shell directly. Just open a cmd window and type
conda install pygame
and it should work.
Activate your environment
conda activate myenv
Install Pygame in Conda
conda install -c cogsci pygame
Go to the start menu > anaconda3 > anaconda prompt
in there type pip install pygame
I tried many solutions and this was the only one that worked for me.
I'm using Python 3.5, and the version of pygame designed for it. I have now installed pygame, by converting to zip and moving the files like in this video here. However when I run the command import pygame, the error ImportError: No module named 'pygame.base' appears.
Using this method of installation has worked fine in the past, but ever since getting a new PC, isn't working. What is wrong, and how do I fix the problem?
Edit:
I tried using the answer found on Game Dev SE, however this gave me the error: not a supported wheel on this platform
The version of pygame I'm trying to install is: pygame-1.9.2a0-cp35-none-win_amd64.whl. Which can be found here.
This is for windows 10 64 bit. Run the 64 bit python as administrator it should import pygame without problem. It worked for me
Make sure pygame folder is copied under C:\Program Files\Python35\Lib\site-packages\ before you start python
try usin pip3 install pygames to install pygames
pip3 install pygame