如何解决PyInstaller和Google Vision-转换时出错
我用GUI编写了简单的Python脚本,用于使用Google Vision扫描照片中的笔迹。 想法是将代码导入可执行程序,因此我的朋友可以在Windows PC上使用该程序。
我正尝试通过自动py-to-exe将此代码导入.exe,但我一直遇到错误,其中大多数与Django相关的导入有关。
是否可以将此脚本完全转换为.exe?
有我的脚本代码:
from google.cloud import vision
from google.cloud.vision import types
import os
import io
execution_path = os.getcwd()
os.environ['GOOGLE_APPLICATION_CREDENTIALS']=r'XXXXXXXXXXXX.json'
dest = ''
def OCR():
client = vision.ImageAnnotatorClient()
path = dest
image_file = io.open(path,'rb').read()
image1 = vision.types.Image(content = image_file)
response = client.text_detection(image = image1)
global doc_text
doc_text = response.full_text_annotation.text
print(doc_text)
from PyQt5 import uic
import sys
from PyQt5 import QtCore,QtGui,QtWidgets
from PyQt5.QtWidgets import QApplication,QWidget,QInputDialog,QLineEdit,QFileDialog
from PyQt5.QtGui import QIcon
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui,self).__init__()
uic.loadUi('gui.ui',self)
self.show()
self.openb.clicked.connect(self.openFileNameDialog)
self.readb.clicked.connect(self.reading)
def openFileNameDialog(self):
options = QFileDialog.Options()
fileName,_ = QFileDialog.getopenFileName(self,"QFileDialog.getopenFileName()","","All Files (*);;Python Files (*.py)",options=options)
global dest
dest = fileName
print(dest)
if fileName:
#print(fileName)
self.pic.setpixmap(QtGui.Qpixmap(fileName))
def reading(self):
OCR()
self.result.setText(doc_text)
app = QtWidgets.QApplication(sys.argv)
window = Ui()
app.exec_()
这是pyinstaller输出
Running auto-py-to-exe v2.7.6
Building directory: C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny
Provided command: pyinstaller --noconfirm --onedir --console "C:/label reader/label_reader.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --console C:/label reader/label_reader.py --distpath C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny\application --workpath C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny\build --specpath C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny
93640 INFO: PyInstaller: 3.6
93644 INFO: Python: 3.7.7
93647 INFO: Platform: Windows-10-10.0.17763-SP0
93651 INFO: wrote C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny\label_reader.spec
93657 INFO: UPX is not available.
93661 INFO: Extending PYTHONPATH with paths
['C:\\label reader','C:\\Users\\mukanrom\\AppData\\Local\\Temp\\tmp_9eu06ny']
93665 INFO: checking Analysis
93668 INFO: Building Analysis because Analysis-00.toc is non existent
93672 INFO: Initializing module dependency graph...
93683 INFO: Caching module graph hooks...
93695 INFO: Analyzing base_library.zip ...
95908 INFO: Processing pre-find module path hook distutils
95913 INFO: distutils: retargeting to non-venv dir 'c:\\documents\\wpy64-3770\\python-3.7.7.amd64\\lib'
97515 INFO: Caching module dependency graph...
97607 INFO: running Analysis Analysis-00.toc
97628 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\documents\wpy64-3770\python-3.7.7.amd64\python.exe
97700 INFO: Analyzing C:\label reader\label_reader.py
108983 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
109942 INFO: Processing pre-find module path hook site
109948 INFO: site: retargeting to fake-dir 'c:\\documents\\wpy64-3770\\python-3.7.7.amd64\\lib\\site-packages\\PyInstaller\\fake-modules'
124233 INFO: Processing pre-safe import module hook six.moves
134498 INFO: Processing pre-safe import module hook urllib3.packages.six.moves
136163 INFO: Processing pre-find module path hook PyQt5.uic.port_v3
136278 INFO: Processing pre-find module path hook PyQt5.uic.port_v2
136587 INFO: Processing module hooks...
136591 INFO: Loading module hook "hook-certifi.py"...
136596 INFO: Loading module hook "hook-cryptography.py"...
136921 INFO: Loading module hook "hook-distutils.py"...
136926 INFO: Loading module hook "hook-django.core.cache.py"...
137107 INFO: Loading module hook "hook-django.core.mail.py"...
137158 INFO: Loading module hook "hook-django.core.management.py"...
137178 INFO: Import to be excluded not found: 'IPython'
137184 INFO: Excluding import 'tkinter'
137192 INFO: Import to be excluded not found: 'matplotlib'
137195 INFO: Loading module hook "hook-django.db.backends.py"...
138715 WARNING: Hidden import "django.db.backends.__pycache__.base" not found!
138718 INFO: Loading module hook "hook-django.py"...
140567 INFO: Determining a mapping of distributions to packages...
242008 INFO: Packages required by django:
['asgiref','sqlparse','pytz']
259593 INFO: Loading module hook "hook-docutils.py"...
262424 INFO: Loading module hook "hook-encodings.py"...
262547 INFO: Loading module hook "hook-gevent.py"...
262852 WARNING: Unable to find package for requirement zope.event from package gevent.
262857 WARNING: Unable to find package for requirement zope.interface from package gevent.
262860 WARNING: Unable to find package for requirement greenlet from package gevent.
262869 INFO: Packages required by gevent:
['cffi','setuptools']
264109 INFO: Loading module hook "hook-google.api.py"...
264116 INFO: Loading module hook "hook-google.api_core.py"...
264121 INFO: Loading module hook "hook-google.cloud.py"...
An error occurred while packaging
Traceback (most recent call last):
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\auto_py_to_exe\packaging.py",line 131,in package
run_pyinstaller()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\__main__.py",line 114,in run
run_build(pyi_config,spec_file,**vars(args))
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\__main__.py",line 65,in run_build
PyInstaller.building.build_main.main(pyi_config,**kwargs)
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\building\build_main.py",line 734,in main
build(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\building\build_main.py",line 681,in build
exec(code,spec_namespace)
File "C:\Users\mukanrom\AppData\Local\Temp\tmp_9eu06ny\label_reader.spec",line 17,in <module>
noarchive=False)
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\building\build_main.py",line 244,in __init__
self.__postinit__()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\building\datastruct.py",line 160,in __postinit__
self.assemble()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\building\build_main.py",line 422,in assemble
self.graph.process_post_graph_hooks()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\depend\analysis.py",line 311,in process_post_graph_hooks
module_hook.post_graph()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\depend\imphook.py",line 417,in post_graph
self._load_hook_module()
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\depend\imphook.py",line 384,in _load_hook_module
self.hook_module_name,self.hook_filename)
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\compat.py",line 797,in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>",line 407,in _check_name_wrapper
File "<frozen importlib._bootstrap_external>",line 907,in load_module
File "<frozen importlib._bootstrap_external>",line 732,in load_module
File "<frozen importlib._bootstrap>",line 265,in _load_module_shim
File "<frozen importlib._bootstrap>",line 696,in _load
File "<frozen importlib._bootstrap>",line 677,in _load_unlocked
File "<frozen importlib._bootstrap_external>",line 728,in exec_module
File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_removed
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\hooks\hook-google.cloud.py",line 13,in <module>
datas = copy_Metadata('google-cloud-core')
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\PyInstaller\utils\hooks\__init__.py",line 859,in copy_Metadata
dist = pkg_resources.get_distribution(package_name)
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\pkg_resources\__init__.py",line 482,in get_distribution
dist = get_provider(dist)
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\pkg_resources\__init__.py",line 358,in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\pkg_resources\__init__.py",line 901,in require
needed = self.resolve(parse_requirements(requirements))
File "c:\documents\wpy64-3770\python-3.7.7.amd64\lib\site-packages\pkg_resources\__init__.py",line 787,in resolve
raise distributionNotFound(req,requirers)
pkg_resources.distributionNotFound: The 'google-cloud-core' distribution was not found and is required by the application
Project output will not be moved to output folder
Complete.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。