Python脚本只有在Visual Studio代码中运行时才能工作



我的python代码只有放在Visual Studio代码中才能运行。代码仍然有效,但当我单击脚本运行它时,它不起作用,当我使用命令运行它时也不起作用。

# importing the module
import time
import wikipedia
import io
# looks for a random page and stores the topic in random
random = wikipedia.random(pages=1)
#searches for the topic and stores it in wiki
wiki = wikipedia.summary((random), sentences = 1) 
# print the output of wiki
file = open("test.txt", "w")
file.write(wiki)
file.close

我也有一个AutoHotkey脚本来运行它,但这也不起作用。

这可能意味着您没有将python添加到路径中。

这就是如何将python添加到路径:

1. Start the Run box and enter sysdm.cpl
2. In the System Properties window go to the Advanced tab and 
click the Environment Variables button
3. In the System variable window, find the Path variable and 
click Edit
4. Position your cursor at the end of the Variable value line 
and add the path to the python.exe file, preceeded with 
the semicolon character (;)

相关内容

最新更新