最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pyinstaller打包遇到的問題解決

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

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)

一、說明

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

Pyinstaller可以將資源文件一起打包到exe中,當(dāng)exe在運行時,會生成一個臨時文件夾,程序可通過sys._MEIPASS訪問臨時文件夾中的資源。
程序打包成exe的時,會將一個變量frozen注入到sys中,這里使用判斷,檢測sys是否有frozen這個變量,如果有,就使用sys._MEIPASS訪問臨時文件夾路徑,如果沒有,就使用當(dāng)前路徑,當(dāng)程序不管是以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)

未打包時運行,打印結(jié)果分別為:
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打包后,打印結(jié)果分別為:

['_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目錄

自行調(diào)整項目路徑

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

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

相關(guān)文章

  • 使用PySide多線程處理圖形界面卡頓問題詳解

    使用PySide多線程處理圖形界面卡頓問題詳解

    這篇文章主要介紹了使用PySide多線程處理圖形界面卡頓問題,在制作圖形界面時,只用一個線程很容易導(dǎo)致卡頓無響應(yīng),一旦主線程被阻塞,那么整個圖形界面都會無法繼續(xù)使用,為了解決這個問題,就得使用多線程,需要的朋友可以參考下
    2025-04-04
  • Pycharm新手使用教程(圖文詳解)

    Pycharm新手使用教程(圖文詳解)

    這篇文章主要介紹了Pycharm新手使用教程(圖文詳解),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • Python實現(xiàn)求解一元二次方程的方法示例

    Python實現(xiàn)求解一元二次方程的方法示例

    這篇文章主要介紹了Python實現(xiàn)求解一元二次方程的方法,涉及Python基于math包進行數(shù)值運算相關(guān)操作技巧,需要的朋友可以參考下
    2018-06-06
  • Python 創(chuàng)建TCP服務(wù)器的方法

    Python 創(chuàng)建TCP服務(wù)器的方法

    這篇文章主要介紹了Python 創(chuàng)建TCP服務(wù)器的方法,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • python實現(xiàn)三階魔方還原的示例代碼

    python實現(xiàn)三階魔方還原的示例代碼

    這篇文章主要介紹了python實現(xiàn)三階魔方還原的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • 利用PyCharm Profile分析異步爬蟲效率詳解

    利用PyCharm Profile分析異步爬蟲效率詳解

    這篇文章主要給大家介紹了關(guān)于如何利用PyCharm Profile分析異步爬蟲效率的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用PyCharm具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05
  • 利用Python批量循環(huán)讀取Excel的技巧分享

    利用Python批量循環(huán)讀取Excel的技巧分享

    這篇文章主要為大家詳細介紹了何用Python批量循環(huán)讀取Excel,文中的示例代碼講解詳細,對我們的學(xué)習(xí)或工作有一定的幫助,感興趣的可以了解一下
    2023-07-07
  • Python中FastAPI項目使用 Annotated的參數(shù)設(shè)計的處理方案

    Python中FastAPI項目使用 Annotated的參數(shù)設(shè)計的處理方案

    FastAPI 是一個非?,F(xiàn)代化和高效的框架,非常適合用于構(gòu)建高性能的 API,FastAPI 是一個用于構(gòu)建 API 的現(xiàn)代、快速(高性能)web 框架,基于 Python 類型提示,這篇文章主要介紹了Python中FastAPI項目使用 Annotated的參數(shù)設(shè)計,需要的朋友可以參考下
    2024-08-08
  • Python面向?qū)ο蟮膬?nèi)置方法梳理講解

    Python面向?qū)ο蟮膬?nèi)置方法梳理講解

    面向?qū)ο缶幊淌且环N編程方式,此編程方式的落地需要使用“類”和 “對象”來實現(xiàn),所以,面向?qū)ο缶幊唐鋵嵕褪菍?nbsp;“類”和“對象” 的使用,今天給大家介紹下python 面向?qū)ο箝_發(fā)及基本特征,感興趣的朋友一起看看吧
    2022-10-10
  • python 中的列表生成式、生成器表達式、模塊導(dǎo)入

    python 中的列表生成式、生成器表達式、模塊導(dǎo)入

    這篇文章主要介紹了python中的列表生成式、生成器表達式、模塊導(dǎo)入 ,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06

最新評論

榆林市| 敦化市| 嘉兴市| 东海县| 舒城县| 康乐县| 上犹县| 秦安县| 都昌县| 清远市| 太和县| 射洪县| 广安市| 清原| 武定县| 杂多县| 河南省| 莎车县| 正宁县| 辽宁省| 怀仁县| 河北区| 天水市| 伊吾县| 炉霍县| 长沙市| 改则县| 忻州市| 华阴市| 永川市| 德清县| 宁夏| 扶沟县| 米脂县| 南漳县| 兴仁县| 宁化县| 鄂托克旗| 福海县| 宜都市| 临沭县|