在运行时,我的项目datapackage的外部依赖项正在寻找一个.json文件,该文件是其自身的一部分,但无法在创建的.exe或单个dir模式目录中找到。
我试图更改规格文件,类似于显示的https://github.com/pyinstaller/pyinstaller/wiki/Recipe-Collect-Data-Files
我还遍历了PyInstallers网站上的所有内容,以查找出现问题时的解决方法。
这是尝试运行应用程序时遇到的初始错误,同样是在同一台计算机上成功构建之后。
Traceback (most recent call last):
File "Izzy.py", line 3, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "EmeraldPassage.py", line 8, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "Petey.py", line 4, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\datapackage\__init__.py", line 10, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\datapackage\package.py", line 19, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\tableschema\__init__.py", line 10, 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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\tableschema\schema.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\ghost\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\tableschema\profile.py", line 78, in <module>
File "site-packages\tableschema\profile.py", line 73, in _load_profile
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Ghost\\AppData\\Local\\Temp\\_MEI24802\\tableschema\\profiles\\table-schema.json'
[18180] Failed to execute script Izzy
在遵循PyInstallers网站的建议之后,我将.spec文件调整为:
# -*- mode: python -*-
block_cipher = None
a = Analysis(['Izzy.py'],
pathex=['C:\\Docs\\PycharmProjects\\Chores'],
binaries=[],
datas=[('C:\\Docs\\PycharmProjects\\Chores\\Montserrat-Black.otf', '.')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
def get_pandas_path():
import pandas
pandas_path=pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(),prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
def Datafiles(*filenames, **kw):
import os
def datafile(path, strip_path=True):
parts = path.split('/')
path = name = os.path.join(*parts)
if strip_path:
name = os.path.basename(path)
return name, path, 'DATA'
strip_path = kw.get('strip_path', True)
return TOC(
datafile(filename, strip_path=strip_path)
for filename in filenames
if os.path.isfile(filename))
datapackageFile = Datafiles('C:\\Users\\Ghost\\AppData\\Local\\Programs\\Python\\Python36-32\\Lib\\site-packages\\tableschema\\profiles\\table-schema.json', strip_path=False) # keep the path of this file
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
datapackageFile,
name='Izzy',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
然后错误变为:
C:\Users\Ghost\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\tableschema\profiles\table-schema.json could not be extracted!
fopen: Invalid argument
据我所知,我需要能够钩住这个.json文件,以便PyInstaller可以将其作为成品的一部分。我只是看不到该怎么做。