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
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.
I was finally able to get python 3.9.0 installed(was using 3.4.2) on my raspberry pi, however I cannot use pygame now stating "ModuleNotFoundError: no module named 'pygame'. I know where pygame is located, but I have no idea how to get python 3.9.0 to see where it is to read it.
You have to re-install all of your packages when you upgrade to a new major version of Python. You'll need to pip3 install xxxx again.
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.
I'm trying to install Pygame for my students. I'm using PIP to install the Windows 64 binaries .WHL file. Unfortunately, I'm finding that although it installs for myself (the administrator), for all other users of the computer, they receive an AttributeError: 'module' object has no attribute 'init' when they try to call pygame.init()
To install pygame,
I'm calling
c:Python34/scripts/ pip install pygame‑1.9.2a0‑cp34‑none‑win_amd64.whl
Okay I have found out why its not working - nothing to do with pygame or pip. It seems the issue is permissions. The init.py files isnt able to be read by student users. If i manual change their permissions for the pygame lib folder it seems to work.
I had installed python 2.7.3 on windows 7 and now I want pygame for it. I even installed pygame 1.92 a0 but it doesn't seem to be working . Could anybody help to solve this problem? I had also tried with pygame 1.9.1 but when I am typing "import pygame' on gui, I get an error message:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import pygame
ImportError: No module named pygame
Do I need to set any path while installing?
You will want to download the version pygame-1.9.2a0.win32-py2.7.msi. You can search for it at this website, or download directly from this page by clicking here. If you download properly, it should run fine. Be sure to uninstall the old versions of pygame first.
Just follow the instructions. Hope it helps you.
Source: https://inventwithpython.com/pygame/chapter1.html
Installing Pygame
Pygame does not come with Python. Like Python, Pygame is available for free. You will have to download and install Pygame, which is as easy as downloading and installing the Python interpreter. In a web browser, go to the URL https://www.pygame.org/download.shtml. These instructions assume you have the Windows operating system, but Pygame works the same for every operating system. You need to download the Pygame installer for your operating system and the version of Python you have installed.
You do not want to download the "source" for Pygame, but rather the Pygame "binary" for your operating system. For Windows, download the pygame-1.9.1.win32-py3.2.msi file. (This is Pygame for Python 3.2 on Windows. If you installed a different version of Python (such as 2.7 or 2.6) download the .msi file for your version of Python.) The current version of Pygame at the time this book was written is 1.9.1. If you see a newer version on the website, download and install the newer Pygame.
For MacOS, download the .zip or .dmg file for the version of Python you have and run it.
For Linux, open a terminal and run: sudo apt-get install python-pygame.
On Windows, double-click on the downloaded file to install Pygame.
To check that Pygame installed correctly, type the following into the interactive shell:
>>> import pygame
If nothing appears after you hit the Enter key, then you know Pygame has successfully been
installed. If the error ImportError: No module named pygame appears, then try to install Pygame again (and make sure you typed import pygame correctly.