簡體   English   中英

使用pyinstaller使其執行后,python腳本不起作用

[英]python script not working after using pyinstaller to make it .exe

path = os.path.realpath(__file__)
try:
    shutil.move(path, "C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup")
except:
    pass  
try:
    if os.path.exists("C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\{}".format(os.path.basename(__file__))):
        os.remove(path)
except:
    pass

使用pyinstaller之后,我在python中的整個代碼塊不再起作用,因此不會將文件移至目標位置。 請記住,它僅通過運行python腳本即可工作,因此我如何使其適應於使用pyinstaller使其成為.exe文件(有效的文件)

__file__仍指向腳本名稱,該名稱已解壓縮到一個臨時目錄中。
PyInstaller和Py2exe都將sys.executable覆蓋到應用程序的路徑,例如: C:\\Programs\\myApplication\\app.exe

您可能需要瀏覽文檔以獲取詳細信息。

暫無
暫無

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

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