Trying to distribute a program that relies on tensorflow...
Using tensorflow it works nicely both as script and with pyinstaller.
Using tensorflow-gpu it works as script but not with pyinstaller.
The cuda and cudnn dlls have been copied into the bundle folder by pyinstaller.
I use python 3.6.5 and tensorflow 1.7.0. (Can change version if it helps...)
Error message:
Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
File "importlib__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "interface.py", line 14, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow__init__.py", line 24, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python__init__.py", line 49, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in
ImportError: Traceback (most recent call last):
File "site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in
File "c:\users\aleks\appdata\local\programs\python\python36\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.dict)
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in
File "site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in swig_import_helper
File "importlib__init__.py", line 126, in import_module
ModuleNotFoundError: No module named 'tensorflow.python._pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
[10816] Failed to execute script interface
Make sure you are also packaging MSVCP140.DLL, as missing this from the %PATH% can throw this error.
I tend to use cx_Freeze instead of pyinstaller when distributing tensorflow applications. Once you overcome the error cx_Freeze has with scipy, it's simpler overall.
Maybe this can help. I manually rename the file _pywrap_tensorflow_internal.pyd to tensorflow.python._pywrap_tensorflow_internal.pyd in the dist folder. Everything works.
I fixed this problem by making dirs as ".../dist/[MmyPyName]/tensorflow/python/_pywrap_tensorflow_internal.pyd"
tensorflow-gpu = 1.10.0
python = 3.6.2
cuda = 9.0
cudnn = 7.3.0
When installing it with pyinstaller, make sure that in the .spec file include this as hidden import:
hiddenimports=['tensorflow.python._pywrap_tensorflow_internal',],
This will include the missing module in the correct path.
Related
When I run the command import requests, I get this:
Traceback (most recent call last):
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 89, in _tempfile
os.write(fd, reader())
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\importlib\abc.py", line 371, in read_bytes
with self.open('rb') as strm:
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\importlib\_adapters.py", line 54, in open
raise ValueError()
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\__init__.py", line 118, in <module>
from . import utils
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\utils.py", line 25, in <module>
from . import certs
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\certs.py", line 15, in <module>
from certifi import where
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 170, in exec_module
notify_module_loaded(module)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\site-packages\certifi\core.py", line 37, in where
_CACERT_PATH = str(_CACERT_CTX.__enter__())
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 95, in _tempfile
os.remove(raw_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\user1\\AppData\\Local\\Temp\\tmpz9h1wrjd'
If I delete the file at the bottom of the error, it generates a new random file and the new file comes up in the error code.
Are you on Visual Studio Code?
If the answer is yes, than it might be the problem. Try reinstalling it and the PYTHON extension.
More info here.
Fixed, baruch Hashem! I:
Uninstalled python
Deleted the Lib folder in C:/User/user1/AppData/Local/Programs/Python/Python39 and C:/User/user1/AppData/Local/Programs/Python/Python310
Re-installed python.
It works!
No need to delete and reinstall Python completely when you are using virtual environments.
This is very useful to keep python environment separated from one project to another.
Just (re)create a new Python venv. Tested successfully. You can use Anaconda Navigator on Windows to do that easily.
On Linux, just run the following commands of a terminal: conda create --name py35 python=3.5 (here we specify the name of the venv to be py35 and we select Python 3.5 as default Python in the venv. Then run source activate py34 to activate the venv and source deactivate to go back to default one. More commands and info here | cheatsheet.
More info here: Creation of virtual environments
I'm new to both Python and ArcGIS Pro; I'm just getting started and I'm trying to install a couple of Python packages in order to read, modify, and write Feature Class files using a Spatially Enabled DataFrame (SEDF). To do that, I need to install a couple of packages first. I've created a virtual environment in PyCharm, and was able to install a few packages, however, now when I try to install or uninstall any new packages, I get this error:
Traceback (most recent call last):
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 89, in _tempfile
os.write(fd, reader())
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\importlib\abc.py", line 371, in read_bytes
with self.open('rb') as strm:
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\importlib\_adapters.py", line 54, in open
raise ValueError()
ValueError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\packaging_tool.py", line 114, in main
do_install(pkgs)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\packaging_tool.py", line 59, in do_install
run_pip(['install'] + pkgs)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2021.3.3\plugins\python-ce\helpers\packaging_tool.py", line 73, in run_pip
runpy.run_module(module_name, run_name='__main__', alter_sys=True)
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 209, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\cli\main.py", line 9, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\cli\autocompletion.py", line 10, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\cli\main_parser.py", line 8, in <module>
from pip._internal.cli import cmdoptions
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\cli\cmdoptions.py", line 23, in <module>
from pip._internal.cli.parser import ConfigOptionParser
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\cli\parser.py", line 12, in <module>
from pip._internal.configuration import Configuration, ConfigurationError
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\configuration.py", line 20, in <module>
from pip._internal.exceptions import (
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_internal\exceptions.py", line 13, in <module>
from pip._vendor.requests.models import Request, Response
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_vendor\requests\__init__.py", line 135, in <module>
from . import utils
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\pip\_vendor\requests\utils.py", line 27, in <module>
from . import certs
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\importer.py", line 170, in exec_module
notify_module_loaded(module)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\certifi_win32\wrapt_pip.py", line 35, in apply_patches
import certifi
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\importer.py", line 170, in exec_module
notify_module_loaded(module)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\decorators.py", line 470, in _synchronized
return wrapped(*args, **kwargs)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\wrapt\importer.py", line 136, in notify_module_loaded
hook(module)
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\certifi_win32\wrapt_certifi.py", line 20, in apply_patches
certifi_win32.wincerts.CERTIFI_PEM = certifi.where()
File "C:\Users\alexis\Documents\Wardrobe\Testvenv1\lib\site-packages\certifi\core.py", line 37, in where
_CACERT_PATH = str(_CACERT_CTX.__enter__())
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
return next(self.gen)
File "C:\Users\alexis\AppData\Local\Programs\Python\Python310\lib\importlib\_common.py", line 95, in _tempfile
os.remove(raw_path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\alexis\\AppData\\Local\\Temp\\tmp0nrmgsas'
So far I've tried:
~Giving PyCharm Administrator permissions
~Used pip in the terminal (I always get the same error message back regardless of how I try to install/uninstall packages)
~Tried downloading other packages (same error message)
~Restarting the computer/PyCharm
~Using ArcGIS Pro to create a cloned environment GDAL, Fiona, and other packages can be installed on. However Fiona never seems to install properly, so now I'm trying to use a virtual environment in PyCharm to run the packages necessary for a Spatially Enabled DataFrame
It seems like the computer is trying to say that somehow a file is open somewhere and must be closed before it can install/uninstall anything else. However, I'm not really sure how to do that, or what that file would even be.
Despite the ValueError and PermissionError, scripts still run just fine; I just can't install or uninstall anything.
In short, I have two problems at once: (1) the package Fiona never seems to install properly, and (2) now I'm stuck with a ValueError and PermissonError that keeps me from installing/uninstalling other packages.
I'm using Python 3.10.2, PyCharm 2021.3.3, and Windows 10, 64 bit.
I've been stuck on this problem for a while now. Any advice would be much appreciated!
I've had contact with the helpdesk of Esri and they recommended using conda instead of pip to install the package. That seems to have worked for me.
Since I also would like to get it working with just pip I was able to determine that the minimal install is an option although you need to install cachetools, lxml, and requests-oauthlib even though they aren't mentioned in the instructions. That allowed me to import arcgis so it seems to have worked. I haven't had a chance to take more time with it, but perhaps this solves it for you too.
Just as a reminder, in order to fix your installation of Python you'd need to reinstall Python, but remove the Lib folder in between the un- and re-installation. (Or delete and remake the virtual environment if you used that.)
So this is the error it's throwing in cmd windows 10. Seems to be something to do with pynput? Not really sure what I can do to fix this and appreciate any help.
C:\Users\Michael\Desktop\herprogram\dist\beeb>beeb.exe
Traceback (most recent call last):
File "C:\Users\Michael\Desktop\herprogram\beeb.py", line 5, in <module>
import pynput
File "c:\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pynput\__init__.py", line 40, in <module>
File "c:\python38\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[11880] Failed to execute script beeb
Many thanks
I switched to a different module pywinauto which is officially supported by pyinstaller and used:
import pywinauto
pywinauto.mouse.double_click(button='left', coords=(0, 0))
This solved the issue. Thanks guys
I have poured about 6 hours into this issue now and I'm getting farther and farther. Here's what happened.
I am using a shared Linux machine that has both Python 2.7 and Python 3.5 and I don't have admin privileges. I was using Python 3.5 and I wanted to use the package seaborn and I found out the specific labeling feature I wanted was only available in a newer version. So no problem "pip3 install seaborn --upgrade".
Everything was happening so fast but something went wrong and by the suggestion of the internet, I ended up upgrading a few other packages like matplotlib, setuptools, and eventually pip itself.
Here's where it really went wrong. Pip just broke. This happens when I run pip3 --version:
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'
The first line in the call stack is "from pip import main" so I tried running pip --version instead of pip3 and now I get:
Traceback (most recent call last):
File "/usr/bin/pip", line 9, in <module>
from pip import main
ImportError: cannot import name main
This error is all over the internet as a bug in pip itself but all every solution involves something that I don't have permission to do. I tried to uninstall and reinstall an older version of pip using "python -m pip ..." but this did not help with the pip3 error, which prompted the same error a few lines later. And I can't use this shortcut with pip3 (python3 -m pip...) because this error occurs anyway.
Worst part is that my original program is now completely dead. I can't even import seaborn at all without crashing.
Traceback (most recent call last):
File "/u/hailey/.local/lib/python3.5/site-packages/matplotlib/__init__.py", line 861, in __setitem__
cval = self.validate[key](val)
KeyError: 'axes.color_cycle'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "nn.py", line 9, in <module>
import seaborn as sns
File "/usr/lib/python3/dist-packages/seaborn/__init__.py", line 13, in <module>
set()
File "/usr/lib/python3/dist-packages/seaborn/rcmod.py", line 98, in set
set_palette(palette, color_codes=color_codes)
File "/usr/lib/python3/dist-packages/seaborn/rcmod.py", line 491, in set_palette
mpl.rcParams["axes.color_cycle"] = list(colors)
File "/u/hailey/.local/lib/python3.5/site-packages/matplotlib/__init__.py", line 868, in __setitem__
'list of valid parameters.' % (key,))
KeyError: 'axes.color_cycle is not a valid rc parameter. See rcParams.keys() for a list of valid parameters.'
At this point, I decided everything would be easier if I just downloaded my own clean version of Python in a local directory where I have privileges. So I downloaded and set up a new version of Python 3.6 in a local directory. Then I ran my original program with this and I was told I had no module named 'numpy'. Reasonable. Let's try to install numpy.
Obtaining file:///u/hailey/python36/Python-3.6.0
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/u/hailey/python36/Python-3.6.0/setup.py", line 4, in <module>
import sys, os, importlib.machinery, re, optparse
ImportError: No module named machinery
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /u/hailey/python36/Python-3.6.0/
Now I'm led to a page that recommends running "setup.py install", which sounds simple enough. But nope.
bash: /u/hailey/python36/Python-3.6.0/setup.py: Permission denied
Now I'm giving up because evidently I know nothing about Python. I would really appreciate some help with this. At this point, even just recovering the state I had yesterday would be fine as I can live without the extra label on my seaborn graph. Thanks everyone!
I wrote a program using PyQt4.QtGui and QtCore,I packaged it into exe,and it works good on my computer,but it can't run on others' computer
The error is this:
cx_Freeze: Python error in main script
---------------------------
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 27, in <module>
File "baidu.py", line 6, in <module>
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1607, in _handle_fromlist
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 313, in _call_with_frames_removed
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1558, in _find_and_load
File "C:\Python\32-bit\3.3\lib\importlib\_bootstrap.py", line 1525, in _find_and_load_unlocked
File "ExtensionLoader_PyQt4_QtGui.py", line 11, in <module>
ImportError: DLL load failed: 找不到指定的模块。
The packaged files are:
├─_bz2.pyd
├─_hashlib.pyd
├─_socket.pyd
├─_ssl.pyd
├─baidu.exe
├─icudt49.dll
├─icuin49.dll
├─icuuc49.dll
├─LIBEAY32.dll
├─libGLESv2.dll
├─lxml.etree.pyd
├─PyQt4.QtCore.pyd
├─PyQt4.QtGui.pyd
├─PyQt4.QtNetwork.pyd
├─python33.dll
├─Qt5Core.dll
├─Qt5Gui.dll
├─Qt5Network.dll
├─Qt5PrintSupport.dll
├─Qt5Widgets.dll
├─sip.pyd
├─SSLEAY32.dll
└─unicodedata.pyd
I just used "cxfreeze baidu.py --base-name=Win32GUI --target-dir d:\123" to package it.
I wonder if I missed some arguments when using cxfreeze result in this problem,and how to package it to exe.Thank you
d3dcompiler_43.dll is needed to run pyqt