簡體   English   中英

pip 安裝 Pygame 后無法導入 Pygame

[英]Unable to import Pygame after pip install Pygame

我試圖在 Python 中制作一個簡單的蛇游戲,所以我使用 pip 安裝 Pygame 安裝 ZC1687207793A103。 安裝成功后,我嘗試導入 Pygame 但出現此錯誤:

ModuleNotFoundError:沒有名為“pygame”的模塊

我是 python 的新手,所以我真的被卡住了。 我通過代碼導入了模塊。

import pygame

如果您在 windows:

打開 cmd 然后輸入:

    cd\

    cd /d C:\Windows

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

然后輸入命令:

    pip install pygame

如果你在 Mac 上:試試python -m pip install pygame

如果您使用的是 linux:

    pip install pygame 

如果您使用 pycharm 或 sublime,請確保將 pygame 安裝到項目的“venv”文件夾中。 如果您使用的是 IDLE,請按住 windows+R 打開命令提示符,然后搜索 cmd,或者如果您在 mac 上:cmd+space 並搜索終端。 then type pip install pygame for windows, and python -m install pygame for mac.

If you are using Pycharm and your stuck goto settings and then proceed to python interpreter you will see a page listing installed modules in your Pycharm project click the small plus sign and search for pygame after that click Install Package. 如果您仍然看到錯誤消息,請重復這些步驟,如果這不起作用,請嘗試使用 Internet 連接。 我不擅長命令提示符,但有辦法。 注意:我還是這個領域的新手,所以我不知道你是否會認為我的想法有用謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM