PyInstaller failing to build exe — cannot find pyproj.libs
Question:
Here’s the traceback:
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas_config.py", line 109, in <module>
File "geopandas_config.py", line 95, in _default_use_pygeos
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas_compat.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "pyproj__init__.py", line 48, in <module>
File "pyproj__init__.py", line 39, in _delvewheel_init_patch_0_0_25
File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\Users\carrier\AppData\Local\Temp\_MEI547922\pyproj.libs'
I’ve tried adding ‘pyproj.libs’ to hiddenimports
but that didn’t change anything. Not sure what to do…
Answers:
Add the pyproj
lib directory to your data files.
For example, in your spec file:
a = Analysis(
['myscript.py'],
pathex=[],
binaries=...,
datas=[('...\Lib\site-packages\pyproj.libs','pyproj.libs')],
hiddenimports=['pyproj', ...],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=['...'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
The reason this happens is the bundling tools (pyinstaller, cxfreeze, py2exe) aren’t aware of pyproj.libs
, because they only contain dynamic libraries (e.g. .dll
files):
Directory: C:UsersuserAppDataLocalpypoetryCachevirtualenvstest-gdal-onnx-Opor2TD1-py3.10l
ibsite-packagespyproj.libs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 21/12/2022 20:53 619008 jpeg62-aa49b59e4c79b6d936d2f4c4d602b0f9.dll
-a---- 21/12/2022 20:53 490496 libcurl-8975b871c76e7d9dda757cb5463c30f7.dll
-a---- 21/12/2022 20:53 154624 liblzma-096abc6d29f3f6caa4ceeaf8481938c5.dll
-a---- 21/12/2022 20:53 571312 msvcp140.dll
-a---- 21/12/2022 20:53 3219968 proj-3feae4f6e6867e7b1da97fbd32eea041.dll
-a---- 21/12/2022 20:53 1011200 sqlite3-ee83b4671ee10b0a425b4a0e38e79fe2.dll
-a---- 21/12/2022 20:53 452096 tiff-959777470b686230774eb18d1b97235f.dll
-a---- 21/12/2022 20:53 89088 zlib1-23ce3850b4e2a3bd64a2634349c2685d.dll
PeaceLeka’s answer is good for PyInstaller. For cxfreeze, use:
site_packages = "C:/Users/sleet/AppData/Local/pypoetry/Cache/virtualenvs/test-gdal-onnx-Opor2TD1-py3.10/lib/site-packages"
pyproj_path = f"{site_packages}/pyproj.libs"
build_options = {
"include_files": [(pyproj_path, "lib/pyproj.libs")]
}
executables = [cx_Freeze.Executable(script = "main.py", base = "Win32GUI")]
cx_Freeze.setup(
name= "Test pyproj",
options = dict(build_exe=build_options),
version = "0.1",
description = "Test pyproj",
executables = executables,
# include_msvcr = True
)
Here’s the traceback:
Traceback (most recent call last):
File "main.py", line 5, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas__init__.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas_config.py", line 109, in <module>
File "geopandas_config.py", line 95, in _default_use_pygeos
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "geopandas_compat.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 499, in exec_module
File "pyproj__init__.py", line 48, in <module>
File "pyproj__init__.py", line 39, in _delvewheel_init_patch_0_0_25
File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\Users\carrier\AppData\Local\Temp\_MEI547922\pyproj.libs'
I’ve tried adding ‘pyproj.libs’ to hiddenimports
but that didn’t change anything. Not sure what to do…
Add the pyproj
lib directory to your data files.
For example, in your spec file:
a = Analysis(
['myscript.py'],
pathex=[],
binaries=...,
datas=[('...\Lib\site-packages\pyproj.libs','pyproj.libs')],
hiddenimports=['pyproj', ...],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=['...'],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
The reason this happens is the bundling tools (pyinstaller, cxfreeze, py2exe) aren’t aware of pyproj.libs
, because they only contain dynamic libraries (e.g. .dll
files):
Directory: C:UsersuserAppDataLocalpypoetryCachevirtualenvstest-gdal-onnx-Opor2TD1-py3.10l
ibsite-packagespyproj.libs
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 21/12/2022 20:53 619008 jpeg62-aa49b59e4c79b6d936d2f4c4d602b0f9.dll
-a---- 21/12/2022 20:53 490496 libcurl-8975b871c76e7d9dda757cb5463c30f7.dll
-a---- 21/12/2022 20:53 154624 liblzma-096abc6d29f3f6caa4ceeaf8481938c5.dll
-a---- 21/12/2022 20:53 571312 msvcp140.dll
-a---- 21/12/2022 20:53 3219968 proj-3feae4f6e6867e7b1da97fbd32eea041.dll
-a---- 21/12/2022 20:53 1011200 sqlite3-ee83b4671ee10b0a425b4a0e38e79fe2.dll
-a---- 21/12/2022 20:53 452096 tiff-959777470b686230774eb18d1b97235f.dll
-a---- 21/12/2022 20:53 89088 zlib1-23ce3850b4e2a3bd64a2634349c2685d.dll
PeaceLeka’s answer is good for PyInstaller. For cxfreeze, use:
site_packages = "C:/Users/sleet/AppData/Local/pypoetry/Cache/virtualenvs/test-gdal-onnx-Opor2TD1-py3.10/lib/site-packages"
pyproj_path = f"{site_packages}/pyproj.libs"
build_options = {
"include_files": [(pyproj_path, "lib/pyproj.libs")]
}
executables = [cx_Freeze.Executable(script = "main.py", base = "Win32GUI")]
cx_Freeze.setup(
name= "Test pyproj",
options = dict(build_exe=build_options),
version = "0.1",
description = "Test pyproj",
executables = executables,
# include_msvcr = True
)