Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python脚本仅在Visual Studio代码中运行时工作_Python_Python 3.x_Visual Studio Code - Fatal编程技术网

Python脚本仅在Visual Studio代码中运行时工作

Python脚本仅在Visual Studio代码中运行时工作,python,python-3.x,visual-studio-code,Python,Python 3.x,Visual Studio Code,我的python代码只有放在VisualStudio代码中才能运行。代码仍然可以运行,但当我单击脚本运行它时,它不工作,当我使用命令运行它时,它也不工作 # 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

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

# 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

我还有一个自动热键脚本来运行它,但这也不起作用。

这可能意味着您没有将python添加到path中

# 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
以下是如何将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 (;)

您能分享它引发的错误吗?当脚本从命令行运行时,是否有任何消息?它不工作意味着什么?什么都没有,否则你会出错?你的代码看起来不错,我想你的python路径有问题或者类似的问题。谢谢你,这已经解决了。我还必须确保.py扩展是用python打开的,而不是用Visual Code Studio。这意味着您只能使用一个版本的python。