我已經為 Python3 安裝了 pygame(在 Windows 上)
但是現在我想運行一個用 Python2.7 撰寫的源代碼,
當我運行代碼時它給出了這個錯誤:
ImportError:沒有名為 pygame 的模塊
我如何在 python2.7 中使用 pygame?(我該如何修復它?)
謝謝
uj5u.com熱心網友回復:
我剛剛做到了,這很簡單。我相信它在任何作業系統中都是相似的,因為我們談論的是 python。但我在 Linux 上做過,因為它是我大部分時間使用的作業系統。
- 已安裝 Python 2(在 Windows 上,您可以在此處獲取安裝程式:https ://www.python.org/download/releases/2.7/ ),在 Linux 上(類似 Debian):
sudo apt-get update
sudo apt-get install python2.7
- 安裝了 pip(可能在 Windows 上,它將與安裝程式上的 python 2 一起安裝,如果沒有,您也可以按照下面的說明進行操作)。
但是在 Linux 上,有你的終端,然后:
- 運行此程式以下載 Python 2.7 的 pip 安裝程式(在 Windows 上,wget 可能僅適用于 powershell,或者將 url 粘貼到瀏覽器中,您可以下載它)
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
- 然后安裝它:
sudo python2 get-pip.py
- 最后你可以有效地安裝它:
pip2 install pygame
最后在終端中檢查它是否在 python 中匯入:
$ python2.7
您將能夠看到 python 2 打開:
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
然后嘗試匯入pygame:
import pygame
你應該看到:
pygame 2.0.3 (SDL 2.0.16, Python 2.7.18)
Hello from the pygame community. https://www.pygame.org/contribute.html
uj5u.com熱心網友回復:
我通過將 pip 用于不同版本的 Python 解決了我的問題
> py -2 -m pip install pygame
> py -3 -m pip install pygame
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/443967.html
標籤:Python python-2.7 游戏
上一篇:執行緒阻塞主執行緒
