當我運行并點擊預覽按鈕時,os.system()運行并執行了test.py,但不承認我已經有了PIL,并給出了這樣的錯誤:
Traceback (most recent call last):
檔案 "/Users/adamd/Desktop/psychedelic_euphoria/test.py", line 2, in < module>
from PIL import ImageTk, Image
輸入錯誤。沒有名為PIL的模塊
下面這個是當我按下預覽鍵時打開test.py檔案的腳本。
from tkinter import *
from tkinter import filedialog
import shutil
import os
位置 = '/Users/adamd/Desktop/psychedelic_euphoria'
def UploadAction(event=None)。
filename = filedialog.askopenfilename()
shutil.move(filename, location )
def OpenPreview()。
os.system('python /Users/adamd/Desktop/psychedelic_euphoria/test.py')
root = Tk()
root.title('Phychedelic Euphoria')
root.geometry("300x200")
bt_import = Button(root, text='Open', command=UploadAction)
bt_quit = Button(root, text='Quit', command=root.quit)
bt_preview = Button(root, text= 'preview', command=OpenPreview)
bt_import.pack(padx=20, pady=(20,0))
bt_quit.pack(padx=20, pady=(20,0))
bt_preview.pack(padx=20, pady=(20,0))
root.mainloop()
下面是test.py:
from tkinter import *
from PIL import ImageTk, Image
import cv2
視圖 = Tk()
app = Frame(view, bg="white")
app.grid()
lmain = Label(app)
lmain.grid()
cap = cv2.VideoCapture('output.avi')
def video_stream():
_, frame = cap.read()
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(1, video_stream)
video_stream()
view.mainloop()
如果我單獨運行test.py,它可以正常作業,但是一旦我通過上面的第一個腳本運行它,它就不明白PIL模塊在哪里。
有什么方法可以解決這個問題,或者我必須改變整個事情? 如果有幫助的話,我用的是macos。
uj5u.com熱心網友回復:
在VS代碼中運行一個新的腳本:
import sys
print(sys.executable)
現在在你的os.system()中使用該路徑
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/330574.html
標籤:
