Normally PyInstaller works fine for me but i saw a problem using the python-module pycountry.
I tried this very simple code:
import pycountryPresumably pycountry
uses pkg_resources.get_distribution("pycountry")
somewhere to access its own metadata (usually to set a __version__
attribute). But PyInstaller doesn’t collect that by default. To include it you need to use the spec file. It looks like your code is named temp2.py
so your spec file will be called temp2.spec
. Open temp2.spec
(it’s just a Python script so you can use your Python editor). Then put the following at the top:
from PyInstaller.utils.hooks import copy_metadata
And in the a = Analysis(...)
section change:
datas = [],
to
datas = copy_metadata("pycountry"),
Then rebuild using:
PyInstaller --clean temp2.spec
Umm, yes and no. For your step 1 you can use `pyi-makespec --onefile temp2.py` which will generate the spec file (instant) without launching a build (slow). Then proceed to your step 2. So it's two commands but it only builds once.
--
You received this message because you are subscribed to the Google Groups "PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/3af7dae7-8029-456e-bac9-828652e99762n%40googlegroups.com.
If you want to recycle fixes for a specific library then you can create a hook for it which you can copy between projects. In this case it would be a file called hook-pycountry.py
containing:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata("pycountry")
Put it in the same folder as your main code and add --additional-hooks-dir=.
to your build command. (Note you must always use --clean
when you add/change a hook.) With this you can go back to using PyInstaller my_code.py
and ignore the spec file. If you prefer the spec then add '.'
to the hookspath=[]
.
Once your happy with it you may send the hook to the hooks repo and it’ll be included in the next release. Then all you’d have to do upgrade to the latest release:
pip install -U pyinstaller-hooks-contrib
And you can forget about all of this…
Looks like pycountry
also contains data files (which PyInstaller also doesn’t collect by default). There’s a hook utility for that too (although it’s odd we haven’t seen this sooner). Your hook becomes:
from PyInstaller.utils.hooks import copy_metadata, collect_data_files
datas = copy_metadata("pycountry") + collect_data_files("pycountry")