Error: Unable to run code with xmlschema after build with pyinstaller

问题描述 投票:0回答:3

我是 xmlschema 和 pyinstaller 的新手,需要一些帮助来解决我遇到的错误。

我已经在 Python 3.6.8 中下载了 xmlschema (1.9) 和 pyinstaller (4.7)。 在我的 python 脚本中,我添加了 import xmlschema 以便使用它。 之后,我使用 `pyinstaller --onefile --windowed schema_check_xsd_11.py 编译我的代码来创建一个 Windows exe 应用程序。

编译成功:

D:\Project\WA_Schema\Schema_Check>pyinstaller --onefile --windowed schema_check_xsd_11.py
82 INFO: PyInstaller: 4.7
82 INFO: Python: 3.6.8
84 INFO: Platform: Windows-10-10.0.17763-SP0
90 INFO: wrote D:\Project\WA_Schema\Schema_Check\schema_check_xsd_11.spec
92 INFO: UPX is not available.
93 INFO: Extending PYTHONPATH with paths
['D:\\Project\\WA_Schema\\Schema_Check']
346 INFO: checking Analysis
361 INFO: Building because D:\Project\WA_Schema\Schema_Check\schema_check_xsd_11.py changed
362 INFO: Initializing module dependency graph...
364 INFO: Caching module graph hooks...
380 INFO: Analyzing base_library.zip ...
2806 INFO: Caching module dependency graph...
2939 INFO: running Analysis Analysis-00.toc
2941 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\python36\python.exe
3006 INFO: Analyzing D:\Project\WA_Schema\Schema_Check\schema_check_xsd_11.py
4478 INFO: Processing module hooks...
4479 INFO: Loading module hook 'hook-difflib.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4481 INFO: Loading module hook 'hook-encodings.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4621 INFO: Loading module hook 'hook-heapq.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4622 INFO: Loading module hook 'hook-pickle.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4624 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4628 INFO: Loading module hook 'hook-xml.py' from 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks'...
4675 INFO: Looking for ctypes DLLs
4676 INFO: Analyzing run-time hooks ...
4678 INFO: Including run-time hook 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
4683 INFO: Including run-time hook 'c:\\python36\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
4689 INFO: Looking for dynamic libraries
4806 INFO: Looking for eggs
4806 INFO: Using Python library c:\python36\python36.dll
4807 INFO: Found binding redirects:
[]
4815 INFO: Warnings written to D:\Project\WA_Schema\Schema_Check\build\schema_check_xsd_11\warn-schema_check_xsd_11.txt
4855 INFO: Graph cross-reference written to D:\Project\WA_Schema\Schema_Check\build\schema_check_xsd_11\xref-schema_check_xsd_11.html
4862 INFO: checking PYZ
4878 INFO: Building because toc changed
4878 INFO: Building PYZ (ZlibArchive) D:\Project\WA_Schema\Schema_Check\build\schema_check_xsd_11\PYZ-00.pyz
5355 INFO: Building PYZ (ZlibArchive) D:\Project\WA_Schema\Schema_Check\build\schema_check_xsd_11\PYZ-00.pyz completed successfully.
5366 INFO: checking PKG
5379 INFO: Building because toc changed
5380 INFO: Building PKG (CArchive) schema_check_xsd_11.pkg
6725 INFO: Building PKG (CArchive) schema_check_xsd_11.pkg completed successfully.
6727 INFO: Bootloader c:\python36\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
6727 INFO: checking EXE
6746 INFO: Building because toc changed
6747 INFO: Building EXE from EXE-00.toc
6758 INFO: Copying bootloader EXE to D:\Project\WA_Schema\Schema_Check\dist\schema_check_xsd_11.exe
6763 INFO: Copying icon to EXE
6764 INFO: Copying icons from ['c:\\python36\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-windowed.ico']
6769 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
6769 INFO: Writing RT_ICON 1 resource with 3752 bytes
6773 INFO: Writing RT_ICON 2 resource with 2216 bytes
6774 INFO: Writing RT_ICON 3 resource with 1384 bytes
6774 INFO: Writing RT_ICON 4 resource with 38188 bytes
6775 INFO: Writing RT_ICON 5 resource with 9640 bytes
6775 INFO: Writing RT_ICON 6 resource with 4264 bytes
6776 INFO: Writing RT_ICON 7 resource with 1128 bytes
6779 INFO: Copying 0 resources to EXE
6783 INFO: Emedding manifest in EXE
6784 INFO: Updating manifest in D:\Project\WA_Schema\Schema_Check\dist\schema_check_xsd_11.exe
6787 INFO: Updating resource type 24 name 1 language 0
6790 INFO: Appending PKG archive to EXE
8145 INFO: Building EXE from EXE-00.toc completed successfully.

运行Windows应用程序时出错(schema_check_xsd_11.exe):

Traceback (most recent call last):
  File "urllib\request.py", line 1474, in open_local_file
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\test\\AppData\\Local\\Temp\\_MEI169402\\xmlschema\\schemas\\XSD_1.0\\XMLSchema.xsd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "schema_check_xsd_11.py", line 1, 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 "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "xmlschema\__init__.py", line 20, 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 "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "xmlschema\dataobjects.py", line 27, 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 "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "xmlschema\validators\__init__.py", line 38, 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 "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "xmlschema\validators\schemas.py", line 2126, in <module>
  File "xmlschema\validators\schemas.py", line 148, in __new__
  File "xmlschema\validators\schemas.py", line 764, in create_meta_schema
  File "xmlschema\validators\schemas.py", line 357, in __init__
  File "xmlschema\resources.py", line 508, in __init__
  File "xmlschema\resources.py", line 742, in parse
  File "urllib\request.py", line 223, in urlopen
  File "urllib\request.py", line 526, in open
  File "urllib\request.py", line 544, in _open
  File "urllib\request.py", line 504, in _call_chain
  File "urllib\request.py", line 1452, in file_open
  File "urllib\request.py", line 1491, in open_local_file
urllib.error.URLError: <urlopen error [WinError 3] The system cannot find the path specified: 'C:\\Users\\test\\AppData\\Local\\Temp\\_MEI169402\\xmlschema\\schemas\\XSD_1.0\\XMLSchema.xsd'>

如果我从我的代码中删除 import xmlschema 并重新构建,我可以运行窗口应用程序而不会出现任何错误。感谢您的任何建议或帮助。 安装好的xmlschema位于C:\Python36\Lib\site-packages\xmlschema\schemas\XSD_1.0.

xsd pyinstaller
3个回答
1
投票

只需将

--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\XSD_1.0;xmlschema/schemas/XSD_1.0
添加到您的 PyInstaller 命令中即可。


1
投票

使用xmlschema将python脚本构建为windows应用程序时添加以下文件。

pyinstaller --onefile --windowed ^
--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\XML\xml_minimal.xsd;xmlschema/schemas/XML ^
--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\VC\XMLSchema-versioning.xsd;xmlschema/schemas/VC ^
--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\XSD_1.1;xmlschema/schemas/XSD_1.1 ^
--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\XSI\XMLSchema-instance_minimal.xsd;xmlschema/schemas/XSI ^
--add-data=C:\Python36\Lib\site-packages\xmlschema\schemas\XSD_1.0;xmlschema/schemas/XSD_1.0 schema_check_xsd_11.py

-1
投票

我在尝试使用 pyinstaller 和 xmlschema 模块创建可执行文件时遇到了这个错误。 有什么想法可以帮助我吗?

代码是: main.py

import xmlschema
if __name__ == '__main__':
    fichero = '4SCT_CdtTrfTxInf_CtgyPurp_NoAT-45.xml'
    schema = 'pain.001.001.03.xsd'
    esquema = xmlschema.XMLSchema(schema)
    resultado = esquema.is_valid(fichero)
    print(resultado)

规格文件包含:

block_cipher = None
a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=[],
    datas=[('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas\\XSD_1.0\\XMLSchema.xsd', 'xmlschema/schemas/XSD_1.0'), ('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas\\XSD_1.1\\XMLSchema.xsd', 'xmlschema/schemas/XSD_1.1'), ('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas/XML/xml_minimal.xsd', 'xmlschema/schemas'), ('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas/XLINK/xlink.xsd', 'xmlschema/schemas'), ('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas/HFP/XMLSchema-hasFacetAndProperty_minimal.xsd', 'xmlschema/schemas'), ('C:\\Users\\angel\\anaconda3\\envs\\kkk\\Lib\\site-packages\\xmlschema\\schemas/XSI/XMLSchema-instance_minimal.xsd', 'xmlschema/schemas')],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='kkk',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)

如果我在命令行上运行这个命令

pyinstaller --onefile --console --name kkk --clean main.py --add-data="C:\Users ngel naconda3 nvs\kkk\Lib\site-packag es\xmlschema\schemas\XSD_1.0\XMLSchema.xsd;xmlschema/schemas/XSD_1.0" --add-data="C:\Users ngel naconda3 nvs\kkk\Lib\site-packages\xmlschema\schemas\XSD_1.1\XMLSc hema.xsd;xmlschema/schemas/XSD_1.1" --add-data="C:\Users ngel naconda3 nvs\kkk\Lib\site-packages\xmlschema\schemas/XML/xml_minimal.xsd;xmlschema/schemas" --add-da ta="C:\Users ngel naconda3 nvs\kkk\Lib\site-packages\xmlschema\schemas/XLINK/xlink.xsd;xmlschema/schemas" --add-data="C:\Users ngel naconda3 nvs\kkk\Lib\site-p ackages\xmlschema\schemas/HFP/XMLSchema-hasFacetAndProperty_minimal.xsd;xmlschema/schemas" --add-data="C:\Users ngel naconda3 nvs\kkk\Lib\site-packages\xmlschema
模式/XSI/XMLSchema-instance_minimal.xsd;xmlschema/模式“

运行编译后的程序得到同样的结果

xmlschema.exceptions.XMLResourceError: 无法访问资源 'file:///C:/Users/angel/AppData/Local/Temp/_MEI34682/xmlschema/schemas/XML/xml_minimal.xsd': [WinError 3] El sistema no puede encontrar la ruta especificada: 'C:\Users ngel\AppData\Local\Temp\_MEI34682\xmlschema\schemas\XML\xml_minimal.xsd'

我将 Pycharm IDE 与 windows 10 和以下模块一起使用

  • 打包版本最新版本
  • ca-证书 2023.01.10 2023.01.10
  • openssl 1.1.1t 1.1.1t
  • 点 23.0.1 23.0.1
  • 蟒蛇 3.9.16 3.11.3
  • 设置工具 66.0.0 66.0.0
  • sqlite 3.41.2 3.41.2
  • tzdata 2023c 2022g
  • 风投 14.2 14.2
  • vs2015_runtime 14.27.29016 14.27.29016
  • 轮 0.38.4 0.38.4

提前致谢,对不起我的英语

© www.soinside.com 2019 - 2024. All rights reserved.