Having issues with PyInstaller and the Python-Keystoneclient package

52 Views Asked by At

---Relevant Info--- Custom Hook

# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_submodules
from PyInstaller.utils.hooks import copy_metadata
from PyInstaller.utils.hooks import collect_data_files

import sys
from os import path
site_packages = next(p for p in sys.path if 'site-packages' in p)

hiddenimports = collect_submodules("python-swiftclient")


datas = collect_data_files('os_service_types',subdir='data')
datas += collect_data_files('keystoneauth1')
datas += collect_data_files('keystoneclient')

added_files = [
    (path.join(site_packages,'python_keystoneclient-5.3.0.dist-info'), 'python_keystoneclient-5.3.0.dist-info'),
]
added_files += copy_metadata('python-keystoneclient')
added_files += copy_metadata('keystoneauth1')
added_files += copy_metadata('fixtures')

Command

pyinstaller --add-data 'bootstrap.yml:.' \
    --additional-hooks-dir='custom_hooks' \
    --python .venv/bin/python \
    --clean \
    --onefile resourceuploader.py

After seeing several posts about this, i don't have a clear idea how to solve it and the custom hook is a mere try to make it work. For being specific. Im triying to run my pyinstaller compiled binary into a docker container with the next dockerfile

FROM debian:trixie-slim
ENV PYTHONUNBUFFERED=1
RUN mkdir /mnt/FTP
ADD dist/resourceuploader /resourceuploader
ADD dist/dev_config.yml /dev_config.yml
ENTRYPOINT ["/bin/bash"]
# ENTRYPOINT ["/resourceuploader"]

The second entry point was the real entry point and the first just a mere test to try to get some information.

The case is. If i execute it like ./dist/resourceuploader like this on my machine, it works well and spawn all the threads an the application. But at the moment to execute it on my docker container it just fails with the next error

Traceback (most recent call last):
  File "pbr/version.py", line 475, in _get_version_from_importlib_metadata
  File "importlib/metadata/__init__.py", line 969, in distribution
  File "importlib/metadata/__init__.py", line 548, in from_name
importlib.metadata.PackageNotFoundError: No package metadata was found for python-keystoneclient

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "resourceuploader.py", line 14, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "resourceuploader_handler.py", line 9, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "swiftclient/__init__.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "swiftclient/client.py", line 51, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "PyInstaller/loader/pyimod02_importers.py", line 419, in exec_module
  File "keystoneclient/__init__.py", line 36, in <module>
  File "pbr/version.py", line 505, in version_string
  File "pbr/version.py", line 498, in semantic_version
  File "pbr/version.py", line 482, in _get_version_from_importlib_metadata
  File "pbr/packaging.py", line 866, in get_version
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name python-keystoneclient was given, but was not able to be found.
[8] Failed to execute script 'resourceuploader' due to unhandled exception!

I readed a lot of info about pbr, and the metadata and i tried a lot of combinations on the hook-pbr.py custom hook but still i am not unable to make it work

Im working with python3.10 and venv. I'll add the pip list output

Package                   Version
------------------------- ------------
altgraph                  0.17.4
aniso8601                 9.0.1
annotated-types           0.6.0
anyio                     4.2.0
blinker                   1.7.0
certifi                   2023.11.17
cffi                      1.16.0
charset-normalizer        3.3.2
click                     8.1.7
cryptography              41.0.7
debtcollector             2.5.0
decorator                 5.1.1
dnspython                 2.4.2
dogpile.cache             1.2.2
eventlet                  0.34.3
exceptiongroup            1.2.0
fixtures                  4.1.0
flagsmith                 3.5.0
flagsmith-flag-engine     5.1.0
Flask                     3.0.0
Flask-RESTful             0.3.10
greenlet                  3.0.2
h11                       0.14.0
httpcore                  1.0.2
httpx                     0.25.2
idna                      3.6
iso8601                   2.1.0
itsdangerous              2.1.2
Jinja2                    3.1.2
jmespath                  1.0.1
jsonpatch                 1.33
jsonpointer               2.4
keystoneauth1             5.5.0
lxml                      5.1.0
markdown-it-py            3.0.0
MarkupSafe                2.1.3
mdurl                     0.1.2
msgpack                   1.0.7
netaddr                   0.10.1
netifaces                 0.11.0
Nuitka                    1.9.7
openstacksdk              2.0.0
ordered-set               4.1.0
os-service-types          1.7.0
oslo.config               9.3.0
oslo.i18n                 6.2.0
oslo.serialization        5.3.0
oslo.utils                6.3.0
packaging                 23.2
PasteDeploy               3.1.0
pbr                       6.0.0
pika                      1.3.2
pip                       23.3.2
platformdirs              4.1.0
psutil                    5.9.7
pycparser                 2.21
pydantic                  2.5.3
pydantic-collections      0.5.2
pydantic_core             2.14.6
pyeclib                   1.6.1
Pygments                  2.17.2
pyinstaller               6.3.0
pyinstaller-hooks-contrib 2023.12
PyMySQL                   1.1.0
pyparsing                 3.1.1
python-keystoneclient     5.3.0
python-swiftclient        4.4.0
pytz                      2023.3.post1
PyYAML                    6.0.1
requests                  2.31.0
requests-futures          1.0.1
requestsexceptions        1.4.0
rfc3986                   2.0.0
rich                      13.7.0
semver                    3.0.2
setuptools                65.5.0
six                       1.16.0
sniffio                   1.3.0
SQLAlchemy                2.0.23
stevedore                 5.1.0
swift                     2.32.0
typing_extensions         4.9.0
tzdata                    2023.4
urllib3                   2.1.0
Werkzeug                  3.0.1
wrapt                     1.16.0
xattr                     1.0.0
zstandard                 0.22.0

Any advice will be gratefull because im running out of ideas. I have 3 more apps working well with pyinstaller and this is the only that I have issues with because the python-kestoneclient package.

I'm using this because i need it to work with the python-swiftclient that is the real library that I want to use.

Regards

Tried: Multiples combination of the hook-pbr.py to try to make it work and import the metadata succesfully but without result.

Expected: The app should run without that issue

0

There are 0 best solutions below