简体   繁体   English

我的批处理文件无法识别pygame时遇到问题

[英]I'm having trouble with my batch file recognizing pygame

So, I wanted to make a batch file that runs all the python scripts. 因此,我想制作一个运行所有python脚本的批处理文件。 I did it correctly, except that it had a problem with pygame. 我正确地做到了,除了pygame有问题。

The batch file was to run all python scripts in a program folder. 批处理文件用于在程序文件夹中运行所有python脚本。 I started with a test and making the batch file run one script. 我从测试开始,使批处理文件运行一个脚本。

a. 一种。 This is what I have done so far. 到目前为止,这是我所做的。

@echo off
python "C:\Users\Dylan Hawley\Documents\Python Files\TEST_GAMES\test\pygamebase.py" %*
pause

b. I also looked on this website and this is what the code is when I use the solution 我也在该网站上查看了,这是使用解决方案时的代码

@echo off
python -x %0 %* &goto :eof
python "C:\Users\Dylan Hawley\Documents\Python Files\TEST_GAMES\test\pygamebase.py" %*
pause

a. 一种。 I expected for the bat file to run the script, but instead, I get an ImportError, more specifically, 我希望bat文件可以运行脚本,但是我得到了ImportError,更具体地说,

Traceback (most recent call last):
    File"C:\Users\Dylan Hawley\Documents\Python Files\TEST_GAMES\test\pygamebase.py", line 1, in <module>
        import pygame, math, sys
ImportError: No module named pygame

b. For this one, I expected for the solution to fix the error, but instead, when I open the batch file, it closes the command prompt and doesn't open the python file. 对于这个,我期望解决方案可以解决该错误,但是,当我打开批处理文件时,它将关闭命令提示符,并且不会打开python文件。

You did't install pygame module correctly. 您没有正确安装pygame模块。 May refer to the install instructions here : 可以参考这里的安装说明:

Windows installation Make sure you install python3.6 with the "Add python 3.6 to PATH" option selected. Windows安装确保在选择“将python 3.6添加到PATH”选项时安装python3.6。 This means that python, and pip will work for you from the command line. 这意味着python和pip将通过命令行为您工作。 There is documentation with python for the "windows installation steps" 有关于“ Windows安装步骤”的python文档。

py -m pip install -U pygame --user
py -m pygame.examples.aliens

If you get: 如果你得到:

PermissionError: [WinError 5] Access is denied' PermissionError:[WinError 5]访问被拒绝'

before starting the cmd right click on it and "Run as administrator". 在启动cmd之前,右键单击它,然后单击“以管理员身份运行”。

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

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