python - 无法将 xgboost 添加到 pyinstaller
问题描述
我的 Python 代码涉及xgboost
库,我现在尝试使用pyinstaller
. 环境是:
68 INFO: PyInstaller: 4.0.dev0+8196c57ab
69 INFO: Python: 3.6.9 (conda)
70 INFO: Platform: Windows-10-10.0.17763-SP0
我已经在这个环境中测试了从命令行运行 .py。
我在 env: dll
、VERSION
和文件夹中找到了相关文件,并手动添加了它们:(在此之后)(为了便于阅读,我将命令分成了新行)
(py36_PP) C:\Users\MarkZ\G_project\Model>pyinstaller PPP_2_main.py -F
--add-data "C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Lib\site-packages\xgboost\*;xgboost/"
--add-data "C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Lib\site-packages\xgboost\VERSION;xgboost/"
--add-data "C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Library\mingw-w64\bin\xgboost.dll;xgboost/"
我如何找到这些路径:
在python中导入这个库并查看它的属性
(py36_PP) C:\Users\MarkZ\GRS-PP-churn-project\Model>python Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import xgboost >>> print(xgboost.__file__) C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\lib\site-packages\xgboost\__init__.py
搜索:
(base) C:\Users\MarkZ\AppData\Local\Continuum\anaconda3>dir /s *xgboost* Volume in drive C is OSDisk Volume Serial Number is F0FE-4464 Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\conda-meta 09/16/2019 01:58 PM 11,072 libxgboost-0.90-0.json 09/16/2019 01:58 PM 11,048 py-xgboost-0.90-py37_0.json 09/16/2019 01:58 PM 1,134 _py-xgboost-mutex-2.0-cpu_0.json 3 File(s) 23,254 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\conda-meta 09/27/2019 01:45 AM 11,022 libxgboost-0.90-0.json 09/27/2019 01:45 AM 10,998 py-xgboost-0.90-py36_0.json 09/27/2019 01:45 AM 1,084 _py-xgboost-mutex-2.0-cpu_0.json 3 File(s) 23,104 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Lib\site-packages 09/27/2019 01:45 AM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Library\mingw-w64\bin 06/07/2019 02:23 PM 4,128,032 xgboost.dll 06/07/2019 02:23 PM 4,218,018 xgboost.exe 2 File(s) 8,346,050 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Library\mingw-w64\include 09/27/2019 01:45 AM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\envs\py36_PP\Library\mingw-w64\lib 06/07/2019 02:23 PM 7,035,268 libxgboost.a 1 File(s) 7,035,268 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\Lib\site-packages 09/16/2019 01:58 PM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin 06/07/2019 02:23 PM 4,128,032 xgboost.dll 06/07/2019 02:23 PM 4,218,018 xgboost.exe 2 File(s) 8,346,050 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\Library\mingw-w64\include 09/16/2019 01:58 PM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\Library\mingw-w64\lib 06/07/2019 02:23 PM 7,035,268 libxgboost.a 1 File(s) 7,035,268 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs 09/27/2019 01:45 AM <DIR> libxgboost-0.90-0 09/16/2019 01:58 PM 1,913,797 libxgboost-0.90-0.conda 09/27/2019 01:45 AM 4,050,208 libxgboost-0.90-0.tar.bz2 09/27/2019 01:45 AM <DIR> py-xgboost-0.90-py36_0 09/27/2019 01:45 AM 78,382 py-xgboost-0.90-py36_0.tar.bz2 09/16/2019 01:58 PM <DIR> py-xgboost-0.90-py37_0 09/16/2019 01:58 PM 76,618 py-xgboost-0.90-py37_0.conda 09/27/2019 01:45 AM <DIR> _py-xgboost-mutex-2.0-cpu_0 09/16/2019 01:58 PM 9,208 _py-xgboost-mutex-2.0-cpu_0.conda 09/27/2019 01:45 AM 9,140 _py-xgboost-mutex-2.0-cpu_0.tar.bz2 6 File(s) 6,137,353 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\libxgboost-0.90-0\info\recipe 05/28/2019 11:57 AM 959 install-libxgboost.sh 1 File(s) 959 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\libxgboost-0.90-0\info\recipe\parent 06/06/2019 04:41 PM 2,814 0001-conda-Unbundle-libxgboost.-dll-dylib-so.patch 05/28/2019 11:57 AM 959 install-libxgboost.sh 05/28/2019 11:57 AM 159 install-py-xgboost.sh 06/07/2019 02:06 PM 292 install-r-xgboost.sh 05/28/2019 11:57 AM 736 test-py-xgboost.py 05/28/2019 11:57 AM 1,601 test-r-xgboost.r 6 File(s) 6,561 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\libxgboost-0.90-0\Library\mingw-w64\bin 06/07/2019 02:23 PM 4,128,032 xgboost.dll 06/07/2019 02:23 PM 4,218,018 xgboost.exe 2 File(s) 8,346,050 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\libxgboost-0.90-0\Library\mingw-w64\include 09/27/2019 01:45 AM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\libxgboost-0.90-0\Library\mingw-w64\lib 06/07/2019 02:23 PM 7,035,268 libxgboost.a 1 File(s) 7,035,268 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py36_0\info\recipe 05/28/2019 11:57 AM 159 install-py-xgboost.sh 1 File(s) 159 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py36_0\info\recipe\parent 06/06/2019 04:41 PM 2,814 0001-conda-Unbundle-libxgboost.-dll-dylib-so.patch 05/28/2019 11:57 AM 959 install-libxgboost.sh 05/28/2019 11:57 AM 159 install-py-xgboost.sh 06/07/2019 02:06 PM 292 install-r-xgboost.sh 05/28/2019 11:57 AM 736 test-py-xgboost.py 05/28/2019 11:57 AM 1,601 test-r-xgboost.r 6 File(s) 6,561 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py36_0\Lib\site-packages 09/27/2019 01:45 AM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py37_0\info\recipe 05/28/2019 11:57 AM 159 install-py-xgboost.sh 1 File(s) 159 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py37_0\info\recipe\parent 06/06/2019 04:41 PM 2,814 0001-conda-Unbundle-libxgboost.-dll-dylib-so.patch 05/28/2019 11:57 AM 959 install-libxgboost.sh 05/28/2019 11:57 AM 159 install-py-xgboost.sh 06/07/2019 02:06 PM 292 install-r-xgboost.sh 05/28/2019 11:57 AM 736 test-py-xgboost.py 05/28/2019 11:57 AM 1,601 test-r-xgboost.r 6 File(s) 6,561 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\py-xgboost-0.90-py37_0\Lib\site-packages 09/16/2019 01:58 PM <DIR> xgboost 0 File(s) 0 bytes Directory of C:\Users\MarkZ\AppData\Local\Continuum\anaconda3\pkgs\_py-xgboost-mutex-2.0-cpu_0\info\recipe\parent 06/28/2018 06:15 PM 2,500 0001-conda-Unbundle-libxgboost.-dll-dylib-so.patch 06/28/2018 06:15 PM 959 install-libxgboost.sh 06/28/2018 06:15 PM 159 install-py-xgboost.sh 06/28/2018 06:15 PM 521 install-r-xgboost.sh 06/28/2018 06:15 PM 736 test-py-xgboost.py 06/28/2018 06:15 PM 1,601 test-r-xgboost.r 6 File(s) 6,476 bytes Total Files Listed: 48 File(s) 52,355,101 bytes 11 Dir(s) 34,365,415,424 bytes free
它仍然无法加载 xgboost:
(py36_PP) C:\Users\MarkZ\G_project\Model>dist\PPP_2_main
Traceback (most recent call last):
File "PPP_2_main.py", line 28, in <module>
import xgboost as xgb
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\MarkZ\appdata\local\continuum\anaconda3\envs\py36_pp\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 621, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\xgboost\__init__.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\MarkZ\appdata\local\continuum\anaconda3\envs\py36_pp\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 621, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\xgboost\core.py", line 161, in <module>
File "site-packages\xgboost\core.py", line 123, in _load_lib
File "site-packages\xgboost\libpath.py", line 52, in find_lib_path
xgboost.libpath.XGBoostLibraryNotFound: Cannot find XGBoost Library in the candidate path, did you install compilers and run build.sh in root path?
List of candidates:
C:\Users\MarkZ\AppData\Local\Temp\_MEI234002\Library\mingw-w64\bin\xgboost.dll
C:\Users\MarkZ\AppData\Local\Temp\_MEI234002\xgboost\../../windows/x64/Release/xgboost.dll
C:\Users\MarkZ\AppData\Local\Temp\_MEI234002\xgboost\./windows/x64/Release/xgboost.dll
[18264] Failed to execute script PPP_2_main
看起来pyinstaller
找不到xgboost
- 我应该添加VERSION
文件路径还是dll
?
解决方案
捆绑应用程序需要VERSION
和文件。DLL
在 avirtualenv
中,xgboost
文件位于<python_path>/xgboost
且VERSION
文件位于<python_path>/Lib/site-packages/xgboost
.
所以我认为你需要的命令是:
(py36_PP) > pyinstaller myscript.py -F --add-data "C:/Users/MarkZ/AppData/Local/Continuum/anaconda3/envs/py36_PP/xgboost/*;xgboost/" --add-data "C:/Users/MarkZ/AppData/Local/Continuum/anaconda3/envs/py36_PP/Lib/site-packages/xgboost/VERSION;xgboost/"
推荐阅读
- spring-batch - Spring Batch:在实体内设置实体
- javascript - Javascript中字符串中的数字数组
- python - (fast_executemany = True) 错误“[ODBC Driver 17 for SQL Server]强制转换规范 (0) (SQLExecute)'的字符值无效)”
- r - 使用 jsonlite 序列化 mgcv gam 模型时出错
- python - 发出 API 请求时出现 JSONDecodeError
- bash - BASH 提示符中的正确返回值
- sql - 如何在 App Engine 中使用 Python3 连接到 Google Cloud Platform 中的 SQL 实例
- flutter - 将数据从可重用的小部件传递到活动。(扑)
- azure-devops-rest-api - Azure Devops 2019 在使用 REST 读取用户配置文件图像时返回 NonAuthoritativeInformation
- javascript - 如何获取动态加载到div中的html