欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pyinstaller打包遇到的問題解決

 更新時間:2023年02月17日 08:30:51   作者:一世繁華行  
本文主要介紹了pyinstaller打包遇到的問題解決,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

1、ModuleNotFoundError: No module named ‘scipy.spatial.transform_rotaion_groups’

解決辦法:–hidden-import scipy.spatial.transform._rotation_groups

2、FileNotFoundError:[Errno 2] No such file or directory:‘C:\Users\Gw0021\AppData\Local\Temp\_MEI149922\matplotlib\npl-data\matplotlibrc’

解決辦法:
pip uninstall matplotlib
pip install matplotlib==3.1.3

3、Failed to execute script ‘app‘ due to unhandled exception已解決

參考解決方法:[Failed to execute script ‘app‘ due to unhandled exception](https://blog.csdn.net/qq_25262697/article/details/127991930?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2~default~OPENSEARCH~Rate-2-127991930-blog-122015848.pc_relevant_3mothn_strategy_and_data_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~OPENSEARCH~Rate-2-127991930-blog-122015848.pc_relevant_3mothn_strategy_and_data_recovery&utm_relevant_index=3)

一、說明

關于Pyinstaller,可以查看Python打包發(fā)布1(基于Pyinstaller打包多目錄項目)

Pyinstaller可以將資源文件一起打包到exe中,當exe在運行時,會生成一個臨時文件夾,程序可通過sys._MEIPASS訪問臨時文件夾中的資源。
程序打包成exe的時,會將一個變量frozen注入到sys中,這里使用判斷,檢測sys是否有frozen這個變量,如果有,就使用sys._MEIPASS訪問臨時文件夾路徑,如果沒有,就使用當前路徑,當程序不管是以PyInstaller打包后形式運行,還是本地測試,都能找到正確的資源路徑。

二、測試

本項目,目錄為:

- MyProject
	- In
	- Out
	- App
		- __init__.py
		- app.py
		- MainProgram
			- __init__.py
			- 1.py
			- 2.py
			- main.py

可以修改main.py,添加

import os,sys
print(sys)
print(sys.executable)

未打包時運行,打印結果分別為:
sys加粗樣式

['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '__unraisablehook__', '_base_executable', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_enablelegacywindowsfsencoding', '_framework', '_getframe', '_git', '_home', '_xoptions', 'addaudithook', 'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth', 'getallocatedblocks', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info', 'warnoptions', 'winver']

sys.executable

C:\ProgramData\Anaconda3\envs\nuitka\python.exe

pyinstaller打包后,打印結果分別為:

['_MEIPASS', '__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '__unraisablehook__', '_base_executable', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_enablelegacywindowsfsencoding', '_framework', '_getframe', '_git', '_xoptions', 'addaudithook', 'api_version', 'argv', 'audit', 'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder', 'call_tracing', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'frozen', 'get_asyncgen_hooks', 'get_coroutine_origin_tracking_depth', 'getallocatedblocks', 'getdefaultencoding', 'getfilesystemencodeerrors', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'platlibdir', 'prefix', 'pycache_prefix', 'set_asyncgen_hooks', 'set_coroutine_origin_tracking_depth', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'unraisablehook', 'version', 'version_info', 'warnoptions', 'winver']

可以看到多了’_MEIPASS’,‘frozen’
sys.executable
此時路徑為app.exe

\APP\dist\app.exe

三、解決思路

根據(jù)自己目錄的相對位置進行修改
pyinstaller打包后運行時,輸出sys.executable的路徑。py運行時輸出__file__

# pyinstaller
def app_path():
    # Returns the base application path.
    if hasattr(sys, 'frozen'):
        # Handles PyInstaller
        return sys.executable  #使用pyinstaller打包后的exe目錄
    return os.path.dirname(__file__)     #沒打包前的py目錄

自行調整項目路徑

pj_path = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(app_path()))))
print(f"================Project dir is '{pj_path}'===============")

到此這篇關于pyinstaller打包遇到的問題解決的文章就介紹到這了,更多相關pyinstaller打包內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • 通過實例了解python__slots__使用方法

    通過實例了解python__slots__使用方法

    這篇文章主要介紹了通過實例了解python__slots__使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-09-09
  • Python中的流程控制詳解

    Python中的流程控制詳解

    這篇文章主要介紹了Python中的流程控制的相關資料,幫助大家更好的理解和學習使用python,感興趣的朋友可以了解下
    2021-02-02
  • Python查找第n個子串的技巧分享

    Python查找第n個子串的技巧分享

    今天小編就為大家分享一篇Python查找第n個子串的技巧心得,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • Selenium向iframe富文本框輸入內容過程圖解

    Selenium向iframe富文本框輸入內容過程圖解

    這篇文章主要介紹了Selenium向iframe富文本框輸入內容過程圖解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-04-04
  • python實現(xiàn)五子棋算法

    python實現(xiàn)五子棋算法

    這篇文章主要為大家詳細介紹了python實現(xiàn)五子棋算法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • 對python當中不在本路徑的py文件的引用詳解

    對python當中不在本路徑的py文件的引用詳解

    今天小編就為大家分享一篇對python當中不在本路徑的py文件的引用詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Opencv實現(xiàn)眼睛控制鼠標的實踐

    Opencv實現(xiàn)眼睛控制鼠標的實踐

    本文主要介紹了Opencv實現(xiàn)眼睛控制鼠標的實踐,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • django靜態(tài)文件加載的方法

    django靜態(tài)文件加載的方法

    本篇文章主要介紹了django靜態(tài)文件加載的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • 針對Pandas的總結以及數(shù)據(jù)讀取_pd.read_csv()的使用詳解

    針對Pandas的總結以及數(shù)據(jù)讀取_pd.read_csv()的使用詳解

    這篇文章主要針對Pandas總結以及數(shù)據(jù)讀取_pd.read_csv()的使用詳解做出了實例,講解非常全面,值得收藏,需要的朋友可以參考下
    2023-03-03
  • 從0開始的Python學習016異常

    從0開始的Python學習016異常

    這篇文章主要介紹了Python異常,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04

最新評論