what!!!pygame不能用???
Tofloor
poster avatar
yunqi_zhang
deepin
2020-11-30 03:10
Author

sudo python3 ./shooter/index.py
pygame 1.9.4.post1
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "./shooter/index.py", line 37, in
e1.append(pygame.image.load("images/enemy1.png"))
pygame.error: Couldn't open images/enemy1.png

Reply Favorite View the author
All Replies
SamLukeYes
deepin
2020-11-30 03:35
#1

应该不是 pygame 的问题。脚本里面是用的相对路径,你的工作目录不对吧?

Reply View the author
wtz
deepin
2020-11-30 03:37
#2

把sudo去掉试试?

Reply View the author
yunqi_zhang
deepin
2020-11-30 04:31
#3
SamLukeYes

应该不是 pygame 的问题。脚本里面是用的相对路径,你的工作目录不对吧?

以前是用win的初次使用lin不懂???

Reply View the author
SamLukeYes
deepin
2020-11-30 05:05
#4
yunqi_zhang

以前是用win的初次使用lin不懂???

Windows 上也是一样的。你是不是没用命令行运行过 python 程序?注意你当时用的工作目录不是 python 程序所在的目录,可能需要先 cd 过去。

Reply View the author
无名
deepin
2020-11-30 07:45
#5

看起来,可能你运行时,所处的目录不对,导致找不到图片?

你的命令要正确运行,目录结构可能需要这样:

. <-- 你在这个目录运行"./shooter/index.py"
├── shooter
│   └── index.py
└── images
└── enemy1.png

但我猜,你的目录结构应该是这样:

.
└── shooter
├── index.py
└── images └── enemy1.png

所以,你可能需要这样做:

cd shooter
python3 ./index.py


Reply View the author