I am getting this problem too.
System | Specification |
---|---|
CPUs | Intel(R) Core(TM) i7-3540M CPU @ 3.00GHz (4 x 2990) |
Memory (System) | 15.91GB (5.16GB free) |
Terminal | ConEmu Build 191012 (preview) |
Shell | cmd::Cmder |
Python | 3.9.0a5 |
λ pip install -U pygame --no-input
Collecting pygame
Using cached pygame-1.9.6.tar.gz (3.2 MB)
ERROR: Command errored out with exit status 1:
command: 'c:python39python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\MavaddatJavid\AppData\Local\Temp\pip-install-1ry68fti\pygame\setup.py'"'"'; __file__='"'"'C:\Users\MavaddatJavid\AppData\Local\Temp\pip-install-1ry68fti\pygame\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygamepip-egg-info'
cwd: C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygame
Complete output (17 lines):
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x64"? [Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygamesetup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygamebuildconfigconfig.py", line 210, in main
deps = CFG.main(**kwds)
File "C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygamebuildconfigconfig_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:UsersMavaddatJavidAppDataLocalTemppip-install-1ry68ftipygamebuildconfigdownload_win_prebuilt.py", line 302, in ask
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Posted by Marta on October 4, 2021 Viewed 37483 times
Hey there! In this article I will show you why you might encounter the error modulenotfounderror: no module named ‘pygame’ when you are creating a game using the python library pygame. You will also learn how to fix this error so you can continue working on your game.
The pygame module provides functionality to create a graphical display, work with graphics, and read from input devices, like mouse and keyboard, on multiple platforms.
This module is a third-party module; therefore, the Python installation doesn’t include it by default. As a result, you need to install it separately. It is quite simple to install; you can find how in one of the sections below. Without further to do, let’s get started!
How to check pygame is installed.
Probably you are facing the following situation. You wrote a small program using pygame, included all imports, installed python; however, when you execute the program, you see the error:
Traceback (most recent call last): File line 1, in <module> import random, pygame, sys ModuleNotFoundError: No module named 'pygame'
This error means that the pygame module is not installed. Another option is that you have several python versions installed on your machine. It could be installed in a different python installation(python SDK) and not installed in the python installation you are using to execute the game.
Therefore, the first thing to tackle this problem is finding out if the module is installed. Whether you are using Mac or Windows, you can check if a module is installed using the pip
tool. Pip is the package manager that python uses to keep track of all libraries installed. To check the list of installed libraries, you can run the following:
Output:
py==1.8.1 pyasn1==0.4.5 pygame==1.9.4 pygubu==0.9.8.6 pyparsing==2.4.7 pytest==5.4.1
After running the pip freeze
command, you will see the list of all python libraries installed on your machine. Now you can double-check if the pygame library is installed.
How to install pygame on mac
Let’s say you check your installed libraries using pip freeze
, and you noticed the library list doesn’t include the pygame library. What’s next? You need to install the module using pip
. All you need to do is executing the command below:
How to Fix When working from an IDE
Another possible scenario. It could be that you installed the module from the terminal; however, when you execute the game from your IDE, such as PyCharm, you still get the error.
In case you are working on mac, one possible reason is that your IDE is set up to use python 2. Python 2 is installed on the Mac operating system by default.
As a result, if you installed python 3, you have two python installations(python SDKs) in your machine. And your IDE should be set up to use python3, which includes pip
as the “module/package manager.” Or the python SDK where the module is installed. Let’s see how to do that.
In Pycharm, go to File->Project Structure and check the project SDK. The project SDK indicates the Python installation that pycharm uses to execute your python scripts.
If there is “No SDK” selected, make sure you coose python 3. If python3 is not available in the dropdown, click on “New …” and add the Python SDK( or installation), using the path where you have installed python earlier.
In other words, you need to make your IDE point to the same python SDK, where you have installed the module.
Where is your python SDK?
In case you don’t know or don’t remember where you installed python, no problem. Pretty simple to find out. You can check just by executing the following command from your terminal:
Output:
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
The above line indicates where python is installed on your machine. The Python SDK will access any module through the pip
manager that is part of the SDK. As a result, you should make sure your python command and pip
are in the same location/path, which means they are part of the same SDK
Where is pip installed?
You can find out where pip is installed using the which
command as well. As I mentioned earlier, make sure python
and pip
are in the same location, meaning they belong to the same SDK. Check the pip location using the command below:
Output:
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip
The above output means the pip
command is installed in the location above, and it is part of the python version 3.7.
Conclusion
In conclusion, you will encounter the error Modulenotfounderror: no module named ‘pygame’ for two main reasons. One is that the module is not installed. The other reason is that you installed the module in a different python SDK to the one you are using to executing your game.
I hope you enjoy the article, and thank you so much for reading and supporting this blog. Happy Coding!
More Interesting articles
ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host=’files.pythonhosted.org’, port=443): Max retries exceeded with url:…
- Спрос: Используйте PyCharm к программе в Win10, где требуется сторонняя библиотека Pygame.
- Предварительное решение: Установка сторонних библиотек с программным обеспечением PyCharm.
- шаг:
- Нажмите на PyCharm Программное обеспечение в строке меню: Файл -> Настройки
image-20200729130433587
- Нажмите, в свою очередь: Проект: Plane_Battle -> Project Переводчик -> Список плагинов+«Открыть библиотеку программного обеспечения страницу поиска сторонних производителей.
Потому что мой проект называется Plane_Battle, список слева меню показывает Project Plane_Battle. Вы можете быть-> Проект: Ваше имя проекта
image-20200729130410515
-
Введите «Pygame» Enter «Pygame» в окне поиска, искать сторонние библиотеки
- Следующие советы могут появиться в случае неудобной скорости сети:
<img src=»https://cdn.jsdelivr.net/gh/Leon1023/leon_pics/img/20200729151048.png» alt=»image-20200729132919968″ style=»zoom:67%;» />
Не паникуйте, просто еще несколько раз!
-
Программное обеспечение находит позже, нажмите кнопку установки кнопки в левом нижнем углу, ожидая, чтобы установить …
image-20200729132736538
Но, к сожалению, установка имеет ошибку!
image-20200729130330838
Нажмите на оперативное сообщение об ошибке, чтобы получить следующее сообщение:
image-20200729130042536
-
Возможная причина:
- Загрузите исходную сеть слишком медленно, то соединение не подключен к серверу;
- Версия PIP является слишком низкой и должна быть повышена.
-
Процесс решения:
-
Изменить загруженный адрес источника:
Нажмите на нижний левый угол управления, а затем всплывают на следующей странице, нажмите справа плюс, добавить новый источник:
Aliyuan:http://mirrors,aliyun.com/pypi/simple/
Douban источник:http://pypi.douban.com/simple
Официальный источник:https://pypi.python.org/simple
-
image-20200729133145018
После выбора нового источника, нажмите кнопку OK, чтобы обновить, а затем нажмите кнопку Установить Установить пакет.
К несчастью! Еще об ошибке! Действительно Действительно
-
Обновление версии PIP:
В соответствии с модулем импорта, ошибка проворная информацию можно увидеть, мой PyCharm путь
D:liangplanes_battlevenvScripts
Следовательно, терминал для Windows входит в путь выше и обновляет PIP в рамках этого пути.
Шаги: «WIN кнопка + г» -> CMD -> d: -> d: лян planes_battle venv Scripts ->
python.exe -m pip install --upgrade pip -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
image-20200729144108600
После завершения обновления, вернитесь к шагу 4, найти Pygame после выбора, нажмите кнопку Установить в нижнем левом углу, чтобы установить пакет, продолжить установку …
К сожалению, может быть, вы можете также установить неудачными! Действительно Действительно
- Окончательный большой трюкТак как он не может быть установлен с помощью программного обеспечения, то сообщения об ошибке, мы можем также попытаться установить в терминальной среде:
Точно так же, как и обновление метод PIP, сначала введите путь окружения проекта PyCharm и введите команду следующую строку:
python.exe -m pip install pygame -i http://pypi.douban.com/simple --trusted-host pypi.douban.com`
Источник Douban используется, конечно, вы можете также изменить его на официальный источник Али или Ubuntu
image-20200729145023181
Таким образом, библиотека Pygame успешно.D:liangplanes_battlevenvScripts
Он устанавливается в среде Конечно, необходимо помнить, что проект выбирает только интерпретатор для ссылки на библиотеку Pygame.:
image-20200729145625090
Получите больше знаний, пожалуйста, нажмите Следовать:
Embedded Linux и ARM
CSDN Blog
Краткая книга блог
колонка Know
I’m on Windows 10 on an Asus. I’m using python 3.8. I installed successfully pygame on another computer (lenovo yoga, same OS) and worked fine. Then I tried to install the same package on this computer (the Asus) using pip and worked just fine. The issue is that when I try to import pygame
in PyCharm
the module seems not to exits
Traceback (most recent call last):
File "C:/Users/nicho/PycharmProjects/test/pygame_/2d pvm game/game.py", line 2, in <module>
import pygame ModuleNotFoundError: No module named 'pygame'
Importing on the python console or using the default IDLE works fine.
I also tried to import the package from Pycharm both using the quick fixes and going to File > settings > Project: name of my project > Project Interpreter and i clicked the + icon to add pygame. This worked fine for all packages but pygame. When I try to install it using Pycharm I get the error
Error occurred when installing package ‘pygame’. Details…
Then I get the details
Collecting pygame Using cached https://files.pythonhosted.org/packages/0f/9c/78626be04e193c0624842090fe5555b3805c050dfaa81c8094d6441db2be/pygame-1.9.6.tar.gz
Complete output from command python setup.py egg_info:
WARNING, No "Setup" File Exists, Running "buildconfig/config.py"
Using WINDOWS configuration...
Download prebuilts to "prebuilt_downloads" and copy to "./prebuilt-x86"? [Y/n]Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:UsersnichoAppDataLocalTemppycharm-packagingpygamesetup.py", line 194, in <module>
buildconfig.config.main(AUTO_CONFIG)
File "C:UsersnichoAppDataLocalTemppycharm-packagingpygamebuildconfigconfig.py", line 210, in main
deps = CFG.main(**kwds)
File "C:UsersnichoAppDataLocalTemppycharm-packagingpygamebuildconfigconfig_win.py", line 576, in main
and download_win_prebuilt.ask(**download_kwargs):
File "C:UsersnichoAppDataLocalTemppycharm-packagingpygamebuildconfigdownload_win_prebuilt.py", line 302, in ask
reply = raw_input(
EOFError: EOF when reading a line
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:UsersnichoAppDataLocalTemppycharm-packagingpygame
Could someone please tell me how to solve this issue?
NOTE: Every package works but pygame