简体   繁体   English

为什么当我尝试导入turtle时没有找到名为pygame的模块?

[英]Why does it say that no module named pygame was found when I try to import turtle?

Basically, i'm trying to use the turtle module at home as I have been using it in school and it's quite fun to use. 基本上,就像我在学校里使用它一样,我试图在家中使用turtle模块,使用起来很有趣。 However, when I try to import it and run the code, it says that there is an error in line 1 of the code and says that no module named pygame was found. 但是,当我尝试导入它并运行代码时,它说代码的第1行有错误,并且说没有找到名为pygame的模块。 I didn't write pygame, I specifically wrote 我没有写pygame,我专门写了

from turtle import *

which at school works perfectly fine. 在学校工作正常。 Both my computer and the school computers use Python 3.6 but the turtle module will just not work at home. 我的计算机和学校计算机都使用Python 3.6,但是turtle模块在家里无法正常工作。 Any ideas why this might be happening? 任何想法为什么会发生这种情况? If it helps, I've tried to install pygame in the past but it wouldn't work so I stopped trying to install it, and just now I tried deleting and uninstalling pygame but it still shows up with the error. 如果有帮助,我过去曾尝试安装pygame,但无法正常工作,因此我停止尝试安装pygame,而现在我尝试删除并卸载pygame,但仍然显示错误。 Thanks for taking your time to read my question. 感谢您抽出宝贵时间阅读我的问题。

The error that comes up is as follows: 出现的错误如下:

Traceback (most recent call last):
File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32/jsjs.py", line 1, in <module>
    from turtle import *
  File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32\turtle.py", line 1, in <module>
    import pygame
ModuleNotFoundError: No module named 'pygame'
>>> 

Also, pip install pygame comes up with an error saying invalid syntax 另外,pip install pygame出现错误,提示语法无效

  • First, you need to download the version of pygame suitable for your version of python. 首先,您需要下载适合您的python版本的pygame版本。 Here's a link to their download page: https://pypi.python.org/pypi/Pygame/1.9.3 这是他们下载页面的链接: https : //pypi.python.org/pypi/Pygame/1.9.3
  • Next, open the command prompt. 接下来,打开命令提示符。 This technique works provided that you have pip installed and you have the required environmental variables. 如果您已安装pip并具有所需的环境变量,则此技术有效。
  • Now, type in the following into the command prompt: 'python -m pip install "Path/To/Downloaded/File.py"' 现在,在命令提示符下键入以下内容:'python -m pip install“ Path / To / Downloaded / File.py”
  • Here's a real-life example: 'python -m pip install "C:/Users/danie/Downloads/pygame-1.9.3-cp36-cp36m-win_amd64.whl"' 这是一个真实的示例:“ python -m pip install“ C:/Users/danie/Downloads/pygame-1.9.3-cp36-cp36m-win_amd64.whl”“

If you have any errors, it would most likely because: - (A) You don't have pip installed properly. 如果有任何错误,很可能是因为:-(A)您没有正确安装点子。 - (B) You gave an invalid directory branch. -(B)您提供了无效的目录分支。 - (C) You spelled something in the command wrong. -(C)您在命令中拼写错误。 - (D) You forgot to download the Pygame module. -(D)您忘记下载Pygame模块。

I hope this helps. 我希望这有帮助。

Pygame should be a dependency of turtle. Pygame应该是乌龟的依赖。 Try to download pygame with pip. 尝试用pip下载pygame。

More information about the installation: 有关安装的更多信息:

https://www.pygame.org/wiki/GettingStarted https://www.pygame.org/wiki/GettingStarted

You've been working inside a Python standard library directory, placing your own files there and clobbering Python's insides. 您一直在Python标准库目录中进行工作,在其中放置自己的文件并破坏Python的内部。 The error you're seeing is because you've edited or replaced the turtle.py from the standard library. 您看到的错误是因为您已经编辑或替换了标准库中的turtle.py At this point, there's no telling how much damage has occurred, and manually fixing things isn't going to be practical. 在这一点上,尚无法确定发生了多少损坏,并且手动修复问题不切实际。

Uninstall and reinstall Python to restore things to normal, and stop putting your own work in that directory. 卸载并重新安装Python,以恢复正常状态,并停止将自己的工作放在该目录中。

Seeing the error code you've posted, it seems that some files placed in the python directory have been messed with or there must have been some changes. 看到您发布的错误代码,似乎放置在python目录中的某些文件已被弄乱,或者必须进行了一些更改。 Nevertheless, You can try doing an uninstall and then doing a clean install of python. 不过,您可以尝试进行卸载,然后进行python的全新安装。 Then proceed to download pygame by: 然后通过以下方式下载pygame:

pip install pygame

and then turtle module. 然后是乌龟模块。 You may have to look up for the Tkinter module too. 您可能还需要查找Tkinter模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM