簡體   English   中英

在代碼運行時,在 vs 代碼中使用 Python 無法打印到終端

[英]using Python in vs code cannot print to terminal while the code is running

我確信這在幾天前曾經有效,我認為我沒有改變任何東西,事實上我只是卸載了 anaconda 和 vscode 並重新安裝了它,看看是否有效,但沒有幫助。

但是終端只在代碼運行時在最后打印

例如,如果我運行這個

import time

while True:
    time.sleep(.5)
    print('true')

沒發生什么事。

如果我運行這個

import time

time.sleep(.5)
print('true')
time.sleep(.5)
print('true')
time.sleep(.5)
print('true')

1.5 秒內未打印任何內容,然后全部完成

如果我突出顯示代碼並通過 shift-return 它會在側邊欄 Jupyter Server 中按預期運行。 我搞不清楚了

無論如何,感謝您提供的任何幫助!

好的,抱歉,我剛剛注意到其他事情

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.   
Try the new cross-platform PowerShell https://aka.ms/pscore6

. : File C:\Users\Jasper\Documents\WindowsPowerShell\profile.ps1 cannot b
information, see about_Execution_Policies at https:/go.microsoft.com/fwli
At line:1 char:3
+ . 'C:\Users\Jasper\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
+ conda activate base
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (conda:String) [], CommandNotFoundExceptioneption
    + FullyQualifiedErrorId : CommandNotFoundException

當我運行任何東西時都會打印出來。 我不確定以前是否存在過,似乎有些不正確,但不確定是什么。

這是一個問題,因為在 Python 擴展中使用了conda run 這已在最新版本中恢復,因此現在應該可以正常工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM