Created exe from .py using pyinstaller has issues with tensorflow path - python-3.x

Using pyinstaller I have created an exe from python script.
The script has dependency on tensorflow. The package is created perfectly.
The issue is when I run the exe.
Python 3.6.5
Pyinstaller 3.3.1
Build platform : Win 8.1 64bit
Running platform Win 7 64bit
C:\Program Files\test\FaceDetectionPackageBeta1\dist\FaceDetection>FaceDetection.exe
Using TensorFlow backend.
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_inter
nal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <modu
le>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17,
in <module>
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 714, in load_module
ImportError: DLL load failed with error code -1073741795
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "TELFaceDetection.py", line 12, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\__init__.py", line 3, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\utils\__init__.py", line 6, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\utils\conv_utils.py", line 9, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\backend\__init__.py", line 89, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\keras\backend\tensorflow_backend.py", line 5, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\__init__.py", line 24, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\__init__.py", line 49, in <module>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <modu
le>
ImportError: Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_inter
nal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <modu
le>
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 631, in exec_module
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17,
in <module>
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16,
in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "c:\program files\python36\lib\site-packages\PyInstaller\loader\pyimod03_
importers.py", line 714, in load_module
ImportError: DLL load failed with error code -1073741795
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_probl
ems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
[4988] Failed to execute script TELFaceDetection
Below is the spec file
# -*- mode: python -*-
block_cipher = None
a = Analysis(['FaceDetection.py'],
pathex=['D:\\FaceDetectionSetup\\FaceDetectioPackageSource'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='FaceDetection',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='FaceDetection')
I have tried the solution in link, but that does not work either. when I execute the exe, No module named tensorflow.python.framework.load_library error is received.
How do I set the path so that relative path is picked.
The same worked without any issues on Win 7 64bit desktop system.So working on one system and not on the other.Any help appreciated.
Thanks
-Megha

if getattr(sys, 'frozen', False):
appPath = os.path.dirname(sys.executable)
else:
appPath = os.path.dirname(os.path.realpath(__file__))
Using this code you can specify your application directory path variable for executable as well as when running .py directly.

Related

Buildozer fail to compile .apk because 'xrange' is not defined

i've a sort of issue with python3 pip or hmac during buildozer compiling process.
The error says 'xrange is not defined', but this happen only if I compile on a previous buildozer folder (.buildozer).
If I make a clean build removing the .buildozer folder it works as expected and also the .apk works good.
I have already added 'xrange = range' in my main.py
Any help will be appreciated. Thanx in advance.
This is the complete buildozer error:
[INFO]: *** PYTHON PACKAGE / PROJECT INSTALL STAGE ***
[INFO]: The requirements (kivy-garden.qrcode, kivy-garden.xcamera, kivy-garden.zbarcam, unix-time) don't have recipes, attempting to install them with pip
[INFO]: If this fails, it may mean that the module has compiled components and needs a recipe.
[INFO]: -> directory context /home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build
[INFO]: -> running python3 -m venv venv
[INFO]: Upgrade pip to latest version
[INFO]: -> running bash -c source venv/bin/activate && pip install -U pip
Exception in thread background thread for pid 27840:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 1633, in wrap
fn(*rgs, **kwargs)
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 2557, in background_thread
handle_exit_code(exit_code)
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 2261, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 861, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /bin/bash -c 'source venv/bin/activate && pip install -U pip'
STDOUT:
Traceback (most recent call last):
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/bin/pip", line 10, in <module>
sys.exit(main())
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 105, in create_command
module = importlib.import_module(module_path)
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Lib/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
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 "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 17, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 18, in <module>
from pip._internal.index.collector import LinkCollector
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/index/collector.py", line 14, in <module>
from pip._vendor import html5lib, requests
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/requests/__init__.py", line 43, in <module>
from pip._vendor import urllib3
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 13, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 11, in <module>
from .connection import (
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/connection.py", line 15, in <module>
from .util.proxy import create_proxy_ssl_context
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/util/__init__.py", line 8, in <module>
from .ssl_ import (
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/util/ssl_.py", line 3, in <module>
import hmac
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/bitcodepro/hmac.py", line 8, in <module>
trans_5C = "".join ([chr (x ^ 0x5C) for x in xrange(256)])
NameError: name 'xrange' is not defined
STDERR:
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1231, in <module>
main()
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
ToolchainCL()
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 688, in __init__
getattr(self, command)(args)
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 154, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 208, in build_dist_from_args
args, "ignore_setup_py", False
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 598, in build_recipes
ignore_setup_py=ignore_project_setup_py
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 772, in run_pymodules_install
), _env=copy.copy(base_env))
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
for line in output:
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 907, in next
self.wait()
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 837, in wait
self.handle_command_exit_code(exit_code)
File "/home/ciko/.local/lib/python3.7/site-packages/sh.py", line 861, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_1:
RAN: /bin/bash -c 'source venv/bin/activate && pip install -U pip'
STDOUT:
Traceback (most recent call last):
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/bin/pip", line 10, in <module>
sys.exit(main())
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/commands/__init__.py", line 105, in create_command
module = importlib.import_module(module_path)
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/Lib/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
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 "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/commands/install.py", line 17, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/cli/req_command.py", line 18, in <module>
from pip._internal.index.collector import LinkCollector
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_internal/index/collector.py", line 14, in <module>
from pip._vendor import html5lib, requests
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/requests/__init__.py", line 43, in <module>
from pip._vendor import urllib3
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/__init__.py", line 13, in <module>
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/connectionpool.py", line 11, in <module>
from .connection import (
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/connection.py", line 15, in <module>
from .util.proxy import create_proxy_ssl_context
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/util/__init__.py", line 8, in <module>
from .ssl_ import (
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/venv/lib/python3.7/site-packages/pip/_vendor/urllib3/util/ssl_.py", line 3, in <module>
import hmac
File "/home/ciko/Scrivania/bitCodePro-App/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/bitcodepro/hmac.py", line 8, in <module>
trans_5C = "".join ([chr (x ^ 0x5C) for x in xrange(256)])
NameError: name 'xrange' is not defined
Edit:
The issue is with hmac because it's made for python2.
The problem is in hmac.py at lines 8 and 9:
trans_5C = "".join ([chr (x ^ 0x5C) for x in xrange(256)])
^
trans_36 = "".join ([chr (x ^ 0x36) for x in xrange(256)])
^
in python3 'xrange' has been removed and replaced by 'range'. So i'm trying to add 'xrange = range' in my main.py but it works only with buildozer clean build process and not if .buildozer folder is already present, even if I build a new .apk, it works on the clean build but fails during the 2nd build.
Surfing the net i founded a different way to solve the issue by downloading 'future' package via pip and adding the following line to the main.py
from past.builtins import xrange
but as i said, it works on clean build and fails during the following one.
My target is to not make a clean build every time because the process is too long. Any idea?
I have the solution!
Remove 'hmac' from buildozer.spec requirements;
Download official python3.7 hmac.py from here
Put the hmac.py into your buildozer folder maybe in a dedicated subfolder called i.e. 'my_pkgs' and import it directly from your main.py in this way:
from my_pkgs import hmac
It works perfectly during the first clean build and also for all other builds released with the same .buildozer folder.
Exactly what i'm searching for.
[SOLVED] by me!

Could not import flask_api.parsers.JSONParser for API setting DEFAULT_PARSERS

I have a flask project with multiple scripts ,templates and static folder.
I am using multiple flask modules like flask_pymongo,flask_cors and flask_api.
I'm trying to build executable windows program in .EXE format with PyInstaller.
I run the following command
`python -m PyInstaller -F --add-data "templates;templates" --add-data "static;static"`
and it builds successfully.
62 INFO: PyInstaller: 3.5
62 INFO: Python: 3.6.0
62 INFO: Platform: Windows-8.1-6.3.9600-SP0
64 INFO: wrote C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.spec
65 INFO: UPX is not available.
66 INFO: Extending PYTHONPATH with paths
['C:\\Users\\mohammadreza\\PycharmProjects\\nobina\\nobina_exe',
'C:\\Users\\mohammadreza\\PycharmProjects\\nobina\\nobina_exe\\nobina']
66 INFO: checking Analysis
119 INFO: Appending 'datas' from .spec
123 INFO: checking PYZ
152 INFO: checking PKG
158 INFO: Building because toc changed
159 INFO: Building PKG (CArchive) PKG-00.pkg
2676 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
2711 INFO: Bootloader C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
2711 INFO: checking EXE
2719 INFO: Building because toc changed
2719 INFO: Building EXE from EXE-00.toc
2720 INFO: Appending archive to EXE C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\dist\__init__.exe
3310 INFO: Building EXE from EXE-00.toc completed successfully.
But when i try to run my program in dist folder i get the following error:
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\mohammadreza>cd C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe
\nobina\dist
C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\dist>__init__.exe
Traceback (most recent call last):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 25, in import_from_string
module = importlib.import_module(module_path)
File "C:\Users\mohammadreza\AppData\Local\Programs\Python\Python36\lib\importl
ib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 948, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'flask_api.parsers'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.
py", line 22, in <module>
from nobina.installation import install
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\__init__.
py", line 22, in <module>
from nobina.installation import install
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\installat
ion.py", line 3, in <module>
from nobina.Models.Admin import Admin
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\Models\Ad
min.py", line 1, in <module>
from nobina.Models.Base import BaseModel, AggregateQuery
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\Models\Ba
se.py", line 1, in <module>
from nobina.utility import load_class, dump_class
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\nobina\utility.p
y", line 2, in <module>
from flask_api import status
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\__init__.py", line 1, in <module>
from flask_api.app import FlaskAPI
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\app.py", line 6, in <module>
from flask_api.request import APIRequest
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\request.py", line 13, in <module>
class APIRequest(Request):
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\request.py", line 14, in APIRequest
parser_classes = default_settings.DEFAULT_PARSERS
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 45, in DEFAULT_PARSERS
return perform_imports(val, 'DEFAULT_PARSERS')
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 13, in perform_imports
return [perform_imports(item, setting_name) for item in val]
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 13, in <listcomp>
return [perform_imports(item, setting_name) for item in val]
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 11, in perform_imports
return import_from_string(val, setting_name)
File "C:\Users\mohammadreza\PycharmProjects\nobina\nobina_exe\venv\lib\site-pa
ckages\flask_api\settings.py", line 30, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'flask_api.parsers.JSONParser' for API setting 'DE
FAULT_PARSERS'. No module named 'flask_api.parsers'.
[6808] Failed to execute script __init__
I tried downgrading flask-api to v1.0 and it didn't work out either.
Any help will be appreciated.
i added --hidden-import=flask_api.parsers & --hidden-import=flask_api.renderers and it works

error in running exe made by using pyinstaller having sklearn packages and xgboost

i have made a exe file from a python file which have multiple import from our own files and have package sklearn, xgboost, pandas and other sklaern packages. during exe preparation thier is no error while running it it throw error
Traceback (most recent call last):
File "probability_score_engine.py", line 16, in <module>
import sklearn.ensemble
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\__init__.py", line 76, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\base.py", line 16, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\__init__.py", line 20, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\validation.py", line 21, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\sklearn\utils\fixes.py", line 18, in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\__init__.py", line 113, in
<module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6,
in <module>
File "C:\Users\ShubhamSingh\PycharmProjects\cfna_scoring\venv\lib\site-
packages\PyInstaller\loader\pyimod03_importers.py", line 627, in
exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 10,
in <module>
ImportError: DLL load failed: The specified module could not be found.
[10668] Failed to execute script probability_score_engine
i have use add data for xgboost when it throw error in not finding dll files for xgboost but it throw error for sklearn. i have made a exe of one file but that file call other other python files function by using import.
Both sklearn and xgboost needs special care when using with Pyinstaller. I'm skipping importing xgboost but here is a useful answer about using it with Pyinstaller.
It seems that when you add xgboostPyinstaller can't handle some modules like scipy. A simple approach is to add the whole scipy in Python's sit-package to your executable as data. So edit your spec file and add this after Analysis:
# -*- mode: python -*-
block_cipher = None
a = Analysis(
datas=[('./env/xgboost/*', 'xgboost/'), ('./env/Lib/site-packages/xgboost/VERSION', 'xgboost/')],
...
)
# add here
a.datas += Tree('<path_to_scipy_in_python_dir>', prefix='scipy')
...
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
And finally, generate your executable with pyinstaller script.spec.

ImportError while installing tensorflow in Ubuntu 16.04

I am trying to install tensorflow using the following command
sudo -H pip3 install --upgrade tensorflow
But I am facing the following error-
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
__import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13, in <module>
from pip.exceptions import InstallationError, CommandError, PipError
File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>
from pip._vendor.six import iteritems
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
vendored("pkg_resources")
File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
__import__(modulename, globals(), locals(), level=0)
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 "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2927, in <module>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2913, in _call_aside
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribe
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in <lambda>
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2515, in activate
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespace
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_ns
File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'.
I have both the version of python 2.7 & python 3.5 installed. Please suggest a solution to get rid of this error.

Running Tensorflow on CMD Line Error

I am trying to run MNIST prediction using tensorflow.
Files:
https://github.com/niektemme/tensorflow-mnist-predict/
CMD Line Code:
python predict_1.py ‘number1.png’
I can execute the program in PyCharm without an error, but when I try executing the script through the command line, I get an error.
Traceback (most recent call last):
File "predict_1.py", line 29, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I checked pip3 list to confirm installed:
tensorflow (1.0.1)
Update1:
I ran this test in both environments:
import os
print(os.file)
PyCharm:
C:\Users\\AppData\Local\Programs\Python\Python35\python.exe
C:/Users//AppData/Local/Programs/Python/Python35/Scripts/tensorflow-mnist-predict-master/tensorflow-mnist-predict-master/test.py
C:\Users\\AppData\Local\Programs\Python\Python35\lib\os.py
CMD Line:
C:\ProgramData\Anaconda3\lib\os.py
Update2:
I removed Anaconda3 from the environment variables, and
CMD Line now reads:
C:\Users\\AppData\Local\Programs\Python\Python35\lib\os.py
This is the error I get trying to run tensorflow through the CMD line:
Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
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 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\__init__.py", line 54, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in <module>
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow')
File "C:\Users\\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "predict_1.py", line 29, in <module>
import tensorflow as tf
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\__init__.py", line 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
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 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\__init__.py", line 54, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 21, in <module>
_pywrap_tensorflow = swig_import_helper()
File "C:\Users\\AppData\Local\Programs\Python\Python35\Lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow')
File "C:\Users\\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow'
Error importing tensorflow. Unless you are using bazel,
you should not try to import tensorflow from its source directory;
please exit the tensorflow source tree, and relaunch your python interpreter from there.
Judging from your edits, you have two separate python installations, one in Users\AppData and one in ProgramData\Anaconda3. Your PyCharm uses the first one, but when you just run python command from CLI you get the second one. There are two ways to resolve this, you can adjust your PATH variable to point to the first installation, so python from CLI is the same as your PyCharm or you can install TensorFlow on the second install (this might lead to further confusion if there are other libraries your code depends on). Here is a link with directions on editing your PATH variable (https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/). You want to make sure that C:\Users\\AppData\Local\Programs\Python\Python35 is in there and C:\ProgramData\Anaconda3 is not.

Resources