Repository navigation
pyinstaller executable can't find package info #1187
Copy link
Copy link
Closed
pyinstaller/pyinstaller
#2637Labels
Description
The pyinstaller complains the error with the following line:
from gcloud.pubsub.client import ClientThe module is installed correctly in /usr/local/lib/python2.7/dist-packages. I run setup.py (build/ install) in addition pip install --upgrade cloud too.
Traceback (most recent call last):
File "<string>", line 267, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 271, in load_module
exec(bytecode, module.__dict__)
File "/home/mtwu/gce/cloudn/cloudx-local/gce/gce_pubsub.py", line 6, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller-2.1.1dev_-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 271, in load_module
exec(bytecode, module.__dict__)
File "/home/mtwu/gce/cloudn/install/build/cloudx_cli/out00-PYZ.pyz/gcloud", line 19, in <module>
File "/home/mtwu/gce/cloudn/install/build/cloudx_cli/out00-PYZ.pyz/pkg_resources", line 551, in get_distribution
The following import will cause the following pyinstaller error.
from gcloud.pubsub.client import Client
File "/home/mtwu/gce/cloudn/install/build/cloudx_cli/out00-PYZ.pyz/pkg_resources", line 431, in get_provider
File "/home/mtwu/gce/cloudn/install/build/cloudx_cli/out00-PYZ.pyz/pkg_resources", line 952, in require
File "/home/mtwu/gce/cloudn/install/build/cloudx_cli/out00-PYZ.pyz/pkg_resources", line 839, in resolve
pkg_resources.DistributionNotFound: The 'gcloud' distribution was not found and is required by the applicationmtwu@ubuntu:/usr/local/lib/python2.7/dist-packages$ ls -l gcloud
total 360
drwxr-sr-x 2 root staff 4096 Oct 16 09:13 bigquery
drwxr-sr-x 3 root staff 4096 Oct 16 09:13 bigtable
-rw-r--r-- 1 root staff 7564 Oct 16 09:13 client.py
-rw-r--r-- 1 root staff 8038 Oct 16 09:13 client.pyc
-rw-r--r-- 1 root staff 12949 Oct 16 09:13 connection.py
-rw-r--r-- 1 root staff 12304 Oct 16 09:13 connection.pyc
-rw-r--r-- 1 root staff 14075 Oct 16 09:13 credentials.py
-rw-r--r-- 1 root staff 13661 Oct 16 09:13 credentials.pyc
drwxr-sr-x 3 root staff 4096 Oct 16 09:13 datastore
-rw-r--r-- 1 root staff 4036 Oct 16 09:13 demo.py
-rw-r--r-- 1 root staff 4010 Oct 16 09:13 demo.pyc
drwxr-sr-x 2 root staff 4096 Oct 16 09:13 dns
-rw-r--r-- 1 root staff 1418 Oct 16 09:13 environment_vars.py
-rw-r--r-- 1 root staff 647 Oct 16 09:13 environment_vars.pyc
-rw-r--r-- 1 root staff 5819 Oct 16 09:13 exceptions.py
-rw-r--r-- 1 root staff 9026 Oct 16 09:13 exceptions.pyc
-rw-r--r-- 1 root staff 8048 Oct 16 09:13 _helpers.py
-rw-r--r-- 1 root staff 10032 Oct 16 09:13 _helpers.pyc
-rw-r--r-- 1 root staff 736 Oct 16 09:13 __init__.py
-rw-r--r-- 1 root staff 333 Oct 16 09:13 __init__.pyc
-rw-r--r-- 1 root staff 4957 Oct 16 09:13 iterator.py
-rw-r--r-- 1 root staff 5210 Oct 16 09:13 iterator.pyc
drwxr-sr-x 2 root staff 4096 Oct 16 09:13 pubsub
drwxr-sr-x 2 root staff 4096 Oct 16 09:13 resource_manager
drwxr-sr-x 2 root staff 4096 Oct 16 09:13 search
drwxr-sr-x 3 root staff 4096 Oct 16 09:13 storage
-rw-r--r-- 1 root staff 7021 Oct 16 09:13 test_client.py
-rw-r--r-- 1 root staff 9101 Oct 16 09:13 test_client.pyc
-rw-r--r-- 1 root staff 13090 Oct 16 09:13 test_connection.py
-rw-r--r-- 1 root staff 15451 Oct 16 09:13 test_connection.pyc
-rw-r--r-- 1 root staff 22622 Oct 16 09:13 test_credentials.py
-rw-r--r-- 1 root staff 28116 Oct 16 09:13 test_credentials.pyc
-rw-r--r-- 1 root staff 2844 Oct 16 09:13 test_exceptions.py
-rw-r--r-- 1 root staff 3664 Oct 16 09:13 test_exceptions.pyc
-rw-r--r-- 1 root staff 12177 Oct 16 09:13 test__helpers.py
-rw-r--r-- 1 root staff 19874 Oct 16 09:13 test__helpers.pyc
-rw-r--r-- 1 root staff 1143 Oct 16 09:13 _testing.py
-rw-r--r-- 1 root staff 1212 Oct 16 09:13 _testing.pyc
-rw-r--r-- 1 root staff 6781 Oct 16 09:13 test_iterator.py
-rw-r--r-- 1 root staff 8076 Oct 16 09:13 test_iterator.pycReactions are currently unavailable
Activity
dhermes commentedon Oct 18, 2015
I'm not familiar with PyInstaller (I presume it is http://www.pyinstaller.org/).
Can you elaborate and maybe explain how you expect this to work?
The problem you describe seems to be a bug in part of PyInstaller. It is a chicken-and-egg problem. The
get_distribution()check occurs only after the library is installed. It is used to set the__version__.mtwu-aviatrix commentedon Oct 21, 2015
We have installed quite a few new modules from github lately. This is the first time we bump into the executable build issue. We do expect the module can work with pyinstaller after it is built and installed. I can run the client in the python native mode. We have reinstalled the module and pyinstaller few times without any luck.
mtwu-aviatrix commentedon Oct 21, 2015
This issue should be related to the version compatibility between pyinstaller and setuptools. Please advise the correct versions used in your environment which the executable can be built from pyinstaller.
dhermes commentedon Oct 23, 2015
We don't have any version requirements on
setuptools. The latest version should work just fine.mtwu-aviatrix commentedon Oct 27, 2015
Your code has to consider the run-time environment when it is bundled to an executable. In this case, pkg_resources can't work in the bundled executable though it works in native python mode. The following workaround diffs make the executable work.
dhermes commentedon Oct 27, 2015
If we were to hardcode it we'd replace
get_distribution('gcloud').versionwith__version__ingcloud/__init__.py.However, we intentionally haven't hardcoded it so we can rely on
setuptools(a great part of the Python ecosystem) to get the version from the package info.It seems strange to me that a bundler would ignore
setuptools, a core part of Python packaging. When was the bundler last updated?setuptoolshas been the de facto way to distribute packages for years now (@tseaver probably has a better sense of this than I do).mtwu-aviatrix commentedon Oct 27, 2015
I am not sure if the setuptools can help much in this case. An executable has no visibility of the package info. At the setup time, it is a different story. I have used pyinstaller 2.x and 3.0 and they all ended up the same run-time error.
dhermes commentedon Oct 29, 2015
Yes, I'm saying a binary installer worth it's salt should work seemlessly with
setuptools, even while running the packaged executable.We may just do a
try ... except. It seemspkg_resourcesimports just fine in your packaged environment but none of the package info. ISTM thatpkg_resourcesjust searchessys.path/PYTHONPATHuntil it finds the distributionmtwu-aviatrix commentedon Oct 29, 2015
Have you tried to bundle gcloud to an executable file and run the file?
In the native python interpreter, it always works. Once it is in an executable, can the external path search work?
dhermes commentedon Oct 29, 2015
No I haven't tried it. I've not had a use for one of these installers and am trying to understand how they work, who uses them and where they use them.
mtwu-aviatrix commentedon Oct 29, 2015
We build an executable file to support our solution.
[-]pkg_resources.DistributionNotFound: The 'gcloud' distribution was not found[/-][+]pyinstaller executable can't find package info[/+]dhermes commentedon Dec 31, 2015
@mtwu-aviatrix I am trying to reproduce this error with PyInstaller and am not having luck.
I made a bogus file (
bogus.py):and then ran
without any issues. What am I missing?
dhermes commentedon Jan 14, 2016
@mtwu-aviatrix Closing this out since I can't reproduce. Feel free to reopen if it's still an issue.
16 remaining items
bloxofcodes commentedon Aug 2, 2018
Hi doing datas += copy_metadata('google-api-core') doesnt solve my error about gcloud...what particular steps you do to make it work?
Vonisoa commentedon Aug 8, 2018
@bloxofcodes Maybe you should look at C:\Python27\Lib\site-packages\PyInstaller\hooks or somewhere else according to your OS. And find if there is a hook for hook-.py, so in your case
hook-google.cloud.py. If it exists but pyinstaller can't find it, you should import it in your code like this:import google.cloud,but if it doesn't exists, create this hook in the hook directory of Pyinstaller and add this inside:
from PyInstaller.utils.hooks import copy_metadatadatas = copy_metadata('google-cloud-core')Vonisoa commentedon Aug 8, 2018
@srkn , thanks for your advice, I will try this and give feedback!
Rahuld753 commentedon Apr 18, 2019
murtuzamdahod commentedon May 21, 2019
Thanks alot this worked for me :)
murtuzamdahod commentedon May 21, 2019
first of all find the root.pem file from gcrp package then copy the file to your cwd and build using --add-data "root.pem:/grpc/_cython/_credentials/"
fix: disambiguate method names that are reserved in transport classes (…
chore(main): release 0.63.1 (#1189)
chore(python): remove noxfile.py from templates (#1187)
feat: add data model for client side metrics (#1187)
fix(deps): restore dependency on python-dateutil (#1187)
chore(main): release 3.0.1 (#1189)
feat: Add support for Python 3.12 (#1187)
chore: librarian release pull request: 20260402T161941Z (#16539)