我使用pyinstaller创建了python可执行文件,但是执行可执行文件时不存在导入到我的.py脚本中的模块 [英] I created a python executable by using pyinstaller, but the module imported to my .py script is not present when I execute executable

查看:228
本文介绍了我使用pyinstaller创建了python可执行文件,但是执行可执行文件时不存在导入到我的.py脚本中的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用pyinstaller创建了python可执行文件,但是执行可执行文件时,导入到.py脚本的jira模块不存在

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

推荐答案

PyInstaller(以及cx_Freeze和Py2exe)在包含jira时遇到问题.您要做的是创建一个PyInstaller的挂钩文件",最好在与您的项目相同的目录中.命名文件" hook-jira.py ".文件内容应如下所示:

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:

导入copy_metadata

数据= copy_metadata('jira')

这将确保PyInstaller包含jira.然后,您只需要在myfile.py和hook文件所在的目录中运行:

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 =.

告诉PyInstaller它应该在当前目录中查找钩子文件.这应该可以解决问题.

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

这篇关于我使用pyinstaller创建了python可执行文件,但是执行可执行文件时不存在导入到我的.py脚本中的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆