You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python导入freegames模块失败求助(已尝试多种排查操作)

freegames模块导入失败排查求助

问题现象

  • 运行Python游戏代码时,Pylance提示:Import "freegames" could not be resolved - Pylance (reportMissingImports)
  • 运行时触发错误:ModuleNotFoundError: No module named 'freegames',错误位于文件C:\Users\my_name\OneDrive\Documents\Other Code Stuff\Python\Tron.py第2行:from freegames import square, vector

已尝试的解决方法

  • 安装、卸载重装freegames模块
  • 修改Python路径
  • 重启IDE
  • 在Stack Overflow搜索解决方案,均无效

环境信息

pip show freegames输出

Name: freegames
Version: 2.5.3
Summary: Free Python Games
Home-page:
Author:
Author-email: Grant Jenks <contact@grantjenks.com>
License: Apache 2.0
Location: C:\Users\skent\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires:
Required-by:

当前Python路径

['C:\\Users\\name\\OneDrive\\Documents\\Other Code Stuff\\Python', 
 'c:\\Users\\name\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip', 
 'c:\\Users\\name\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 
 'c:\\Users\\name\\AppData\\Local\\Programs\\Python\\Python312\\Lib', 
 'c:\\Users\\name\\AppData\\Local\\Programs\\Python\\Python312', 
 'c:\\Users\\name\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages']

可复现代码片段

from turtle import *
from freegames import square, vector

redxy = vector(-100, 0)
redaim = vector(4, 0)
redbody = set()
 
bluexy = vector(100, 0)
blueaim = vector(-4, 0)
bluebody = set()

def inside(head):
    return -200 < head.x < 200 and -200 < head.y < 200
def draw():
    redxy.move(redaim)
    redhead = redxy.copy()

    bluexy.move(blueaim)
    bluehead = bluexy.copy()

解决方案

  1. 核对IDE解释器与pip环境
    打开IDE的Python解释器选择面板,确认当前使用的解释器路径是C:\Users\skent\AppData\Local\Programs\Python\Python312\python.exe,如果不是,切换到该路径的解释器。

  2. 解决用户目录不一致问题
    注意到pip show显示模块安装在skent用户目录下,但代码和Python路径使用的是name/my_name用户,可能是多用户或权限问题:

    • 以管理员身份启动IDE,重新运行代码
    • 或者打开命令提示符,执行python -m pip install freegames(确保该python命令指向Python312),将模块安装到当前用户环境。
  3. 手动验证模块状态

    • 打开命令提示符,输入python进入交互环境,执行import freegames:
      • 若成功,说明模块本身正常,问题出在IDE配置
      • 若失败,执行pip install --force-reinstall freegames强制重装模块

内容的提问来源于stack exchange,提问作者GP22248

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 04:57:17