![](/img/trans.png)
[英]Python script doesn't work properly when ran through terminal, but works fine in Jupyter and Visual Studio
[英]Python script only working when ran in Visual Studio Code
我的 python 代碼只有在放入 Visual Studio Code 時才會運行。 該代碼仍然有效,但是當我單擊腳本運行它時,它不起作用,當我使用命令運行它時,它也不起作用。
# 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 (;)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.