pygame error: “ImportError: No module named 'pygame'”

旧街凉风 提交于 2020-05-29 02:30:15

问题


This is my situation:

enter image description here

I tried importing pygame in both python 3.4.2 and python 3.6.3 using both pip and pip3 respectively.

In the python 3.4.2 shell:

Traceback (most recent call last) is:
File "", line 1, in
import pygame
ImportError: No module named 'pygame'

In the python 3.6.3 shell:

Traceback (most recent call last):
File "", line 1, in
import pygame
File "C:\Users\aditya dand\AppData\Local\Programs\Python\Python36\lib\site-packages\pygame__init__.py", line 141, in from pygame.base import *
ModuleNotFoundError: No module named 'pygame.base'

Those are the errors that occurred.

I also used pygame-1.9.2a0-hg_5974ff8dae3c%2B.win32-py3.4.msi.
It's showing the header's file of pygame, but it's not importing something.

What can I do to solve this?


回答1:


Step1:

check http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame to find a Windows installer that matches the version of Python you're running. The current version of pygame is : pygame-1.9.4-cp37-cp37m-win_amd64.whl

Move this file to the folder C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

=========================================

Step2:

open cmdand then type:

cd\
cd /d C:\Windows
cd /d C:\Users\username\AppData\Local\Programs\Python\Python37\Scripts

and then type the command:

pip install pygame

Now you have successfully installed pygame package.

=========================================

Step3:

open PyCharm File >> setting make sure the "Project Interpreter" has the "pygame" package like the following:

File>>Setting>> make sure the "pygame" package is there.




回答2:


ans done if any one need help delete all python version from system and install python 3.5.2 from https://www.python.org/downloads/release/python-352/

then go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame

and search pygame and download pygame‑1.9.3‑cp35‑cp35m‑win_amd64.whl

then go to C:\Users\"your username"\AppData\Local\Programs\Python\Python35\Scripts> in this location in cmd ( command prompt )

type this line and done " pip3 install pygame-1.9.3-cp35-cp35m-win_amd64.whl "

hope this help you




回答3:


Edit - pygame only works in python >= 3.6.*

If you are using Windows i had the same problem and i know how to fix it, follow the steps:

  1. Go to the pygame website, then go to the downloads page
  2. Once there scroll down to the windows section and copy the bit that it says to put into pip It should start with py
  3. Once this short piece of code is copied, open command prompt (search it on start, it is nothing to do with python)
  4. Open it and paste the line of code, it should say downloading and then installing and just wait a bit for it to finish. Then in the command prompt paste the example.aliens thing in and it should work.
  5. Now the complicated part, open file explorer, go to this pc and search pygame once it has fully loaded, look near the top if the list of things it came up with. There should be 2 thing that are called pygame.
  6. Now leave this open and hold the windows button and press r
  7. Then type %appdata% and press enter
  8. This will open the appdata roming file

    Look at the bit at the top that says Appdata > roaming and click on app data

  9. Then click local, then programs, then python, then python36 then go to scripts
  10. Now go back to the pygame search. Click and drag the 2nd thing called pygame into the scripts folder and you should be good to go.

Pls comment if this doesnt make sense or you would like further details



来源:https://stackoverflow.com/questions/51107319/pygame-error-importerror-no-module-named-pygame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!