Reputation: 1190
Normally PyInstaller works fine for me but i saw a problem using the python-module pycountry.
I tried this very simple code:
import pycountry
land="DE"
country = pycountry.countries.get (alpha_2=land)
print(country.name)
Compiled it with pyinstaller:
pyinstaller --onefile xyz.py
But i want to execute the compiled exe i get this error:
Traceback (most recent call last):
File "temp2.py", line 1, in <module>
import pycountry
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "c:\users\polzi\appdata\local\programs\python\python37\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\pycountry\__init__.py", line 12, in <module>
File "site-packages\pkg_resources\__init__.py", line 481, in get_distribution
File "site-packages\pkg_resources\__init__.py", line 357, in get_provider
File "site-packages\pkg_resources\__init__.py", line 900, in require
File "site-packages\pkg_resources\__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'pycountry' distribution was not found and is required by the application
[45548] Failed to execute script temp2
Is there any workaround i can get pycountry functionality to running with pyinstaller?
UPDATE: found a workaround / solution for my problem-
Alternative: compile program before - change spec - an use command <pyInstaller --clean temp2.spec> – Rapid1898 just now Edit
Upvotes: 4
Views: 1173
Reputation: 118
Your update was really helpful to me. But I needed a variation in order for it to work. I would just order the ideas to show clearer the way it must be done for pycountry library to work properly.
pyi-makespec --onefile name-of-your-file.py
to generate a .spec file
with name name-of-your-file.specfrom PyInstaller.utils.hooks import copy_metadata
datas = []
for datas = copy_metadata("pycountry")
PyInstaller --clean name-of-your-file.spec
I hope it is helpful for anyone facing the same error.
You can read the documentation for using spec files.
And you can find the same process in this link.
Upvotes: 5