I am using TensorFlow in a Python script that I am trying to freeze. Everything builds fine, but when I try to run it, I get this error:
Traceback (most recent call last):
File "C:\Users\.conda\envs\lib\site-packages\cx_Freeze\initscripts__startup__.py", line 14, in run module.run()
File "C:\Users\.conda\envs\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run exec(code, m.dict)
File "config.py", line 21, in
File "E:\Projects\test.py", line 7, in from google.cloud import vision
ImportError: cannot import name 'vision'
I am using cx_Freeze. The google library has been successfully added in the Setup.py
script. The __init__.py
is also present in the google directory.
Setup.py
:
from cx_Freeze import setup, Executable
import sys
import os
base = None
os.environ['TCL_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(os.getcwd(), "cacert.pem")
if sys.platform == 'win32':
# base = "Win32GUI"
base = 'Console'
if sys.platform == 'win64':
# base = "Win64GUI"
base = 'Console'
include = ['numpy.core._methods', 'numpy.lib.format', 'jinja2', 'jinja2.ext', 'asyncio', 'constants', 'jinja2.debug']
packages = ['asyncio', 'jinja2', 'jinja2.ext', 'flask', 'numpy', 'pandas', 'connect_db', 'pymysql', 'pymysql.cursors',
'multiprocessing', 'multiprocessing.pool','google']
excludes = []
options = {'build_exe': {'packages': packages, 'includes': include, 'include_files': includefiles, 'excludes': excludes}}
flaskapp = Executable(script="config.py",
targetName="test.exe",
icon='test.ico'
)
setup(
name="",
version="1.0",
author="Test",
description="Test",
options={
'build_exe': {
'include_files': includefiles,
'includes': include,
'packages': packages,
'excludes': excludes,
'build_exe': "build"
}
},
executables=[flaskapp]
)
Thank you in advance
Thank you @jpeg I finally found the solution.
__init__.py
in /site-packages/google
also in /site-packages/google/cloud
DistributionNotFound: The 'google-api-core' distribution was not found and is required by the application
edited the /site-packages/google/api_core/__init__.py
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()
import pkg_resources
old_get_distribution = pkg_resources.get_distribution
from pkg_resources import parse_version
def mp_get_distribution(*args, **kwargs):
# print args
# print kwargs
try:
res = old_get_distribution(*args, **kwargs)
except:
class Mock(object):
pass
mock = Mock()
mock.parsed_version = parse_version("2.6.1") #add sensible value
mock.version = parse_version("2.6.1") #add sensible value
return mock
return res
pkg_resources.get_distribution = mp_get_distribution
from google import api_core