I created a python executable by using pyinstaller, but the module imported to my .py script is not present when I execute executable

一个人想着一个人 提交于 2021-01-29 04:27:15

问题


I created a python executable by using pyinstaller, but the jira module imported to my .py script is not present when I execute executable

Traceback (most recent call last):

 File "myfile.py", line 7, in <module>
 File "<frozen importlib._bootstrap>", line 969, in _find_and_load
 File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
 File "<frozen importlib._bootstrap>", line 634, in      _load_backward_compatible
 File "c:\users\rajivkum\appdata\local\continuum\anaconda3\lib\site-packages\Py
 Installer\loader\pyimod03_importers.py", line 389, in load_module
 exec(bytecode, module.__dict__)
 File "site-packages\jira\__init__.py", line 6, in <module>
 File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
 558, in get_distribution
 File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
 438, in get_provider
 File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
 959, in require
 File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
 846, in resolve
 pkg_resources.DistributionNotFound: The 'jira' distribution was not found and is
 required by the application

回答1:


PyInstaller (and also cx_Freeze and Py2exe) have problems with including jira. What you have to do is to create, preferably in the same directory as your project a "hook file" for PyInstaller. Name the file "hook-jira.py". Content of the file should look like that:

from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata('jira')

This will assure that PyInstaller will include jira. Then, you just have to run in the directory where myfile.py and hook file are located:

PyInstaller myfile.py --additional-hooks-dir=.

to tell PyInstaller that it should look for hook files in the current directory. This should solve the problem.



来源:https://stackoverflow.com/questions/39838701/i-created-a-python-executable-by-using-pyinstaller-but-the-module-imported-to-m

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!