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

pyinstaller打包遇到的問題解決

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

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

二、測試

本項(xiàng)目,目錄為:

- 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)

未打包時(shí)運(yùn)行,打印結(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
此時(shí)路徑為app.exe

\APP\dist\app.exe

三、解決思路

根據(jù)自己目錄的相對(duì)位置進(jìn)行修改
pyinstaller打包后運(yùn)行時(shí),輸出sys.executable的路徑。py運(yùn)行時(shí)輸出__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)整項(xiàng)目路徑

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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

最新評(píng)論

礼泉县| 南充市| 沈阳市| 江山市| 甘肃省| 桐柏县| 海林市| 浑源县| 贵定县| 深水埗区| 夏河县| 崇信县| 榆树市| 留坝县| 郁南县| 密山市| 江山市| 彭阳县| 当雄县| 麻城市| 肥东县| 吉隆县| 开平市| 德令哈市| 青阳县| 化德县| 鲁山县| 通许县| 屏南县| 西藏| 石渠县| 梧州市| 佳木斯市| 涞源县| 得荣县| 宁波市| 文化| 金昌市| 贵港市| 呼和浩特市| 肇东市|