ImportError while installing tensorflow in Ubuntu 16.04 - python-3.x

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.

Related

cant install pandas on a previously well run build

Had a setup on ubuntu with python3.9 and pandas working perfectly. Things were perfect until.. pandas just stopped working. I removed all python versions and reinstalled python3.9 from scratch. Now I am getting this:
userA#serverB:/somefolder$ python3.9 -m pip install --no-cache-dir pandas
Collecting pandas
Downloading https://files.pythonhosted.org/packages/f4/00/2de395c769335956b8650f990ef2a15e860be83b544c408ff95713446329/pandas-1.4.3.tar.gz (4.9MB)
100% |████████████████████████████████| 4.9MB 79.6MB/s
Exception:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 215, in main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 342, in run
requirement_set.prepare_files(finder)
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 376, in prepare_files
discovered_reqs.extend(self._prepare_file(
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 634, in _prepare_file
abstract_dist.prep_for_dist()
File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 129, in prep_for_dist
self.req_to_install.run_egg_info()
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 412, in run_egg_info
self.setup_py, self.name,
File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 387, in setup_py
import setuptools # noqa
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/setuptools-39.0.1-py2.py3-none-any.whl/setuptools/__init__.py", line 14, in <module>
from setuptools.dist import Distribution, Feature
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/setuptools-39.0.1-py2.py3-none-any.whl/setuptools/dist.py", line 24, in <module>
from setuptools.depends import Require
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/setuptools-39.0.1-py2.py3-none-any.whl/setuptools/depends.py", line 7, in <module>
from .py33compat import Bytecode
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 627, in _load_backward_compatible
File "<frozen zipimport>", line 259, in load_module
File "/usr/share/python-wheels/setuptools-39.0.1-py2.py3-none-any.whl/setuptools/py33compat.py", line 54, in <module>
unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)
AttributeError: 'HTMLParser' object has no attribute 'unescape'
This is some further detail on the pandas or numpy errors
python3.9
Python 3.9.13 (main, May 23 2022, 22:02:02)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/pandas/__init__.py", line 18, in <module>
raise ImportError(
ImportError: Missing required dependencies ['numpy']
>>> import numpy as np
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 16, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/numpy/__init__.py", line 142, in <module>
from . import add_newdocs
File "/usr/lib/python3/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python3/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python3/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python3/dist-packages/numpy/core/__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name 'multiarray' from partially initialized module 'numpy.core' (most likely due to a circular import) (/usr/lib/python3/dist-packages/numpy/core/__init__.py)
>>>
No luck with other solutions online such as upgrading the pip3 or no cache. any thoughts?

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!

tensorflow 1.8 with python 3.6 in windows64

I am trying to install tensorflow 1.8 cpu version with python 3.6 on my windows 64 bit os. Anyone konw that whether the tensorflow 1.8 support python 3.6 in windows 64 bit system? The table here TF install guide didn't mention it. I had met the same problems bofore and it seems that the tensorflow version is too new for python 3.x to support on windows.
here are the issues:
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "D:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "D:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\python36\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "D:\python36\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "D:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: 动态链接库(DLL)初始化例程失败。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "D:\python36\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "D:\python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_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.
Tragedy. It turns out that my computer with a Intel(R) Celeron(R) cpu N2940 and it doesn't support AVX instructions. TF version >= 1.6 will need AVX. That's it.

ERROR in importing tensorflow. DLL load failed

I installed tensorflow 1.8.0 using the command
pip3 install --upgrade tensorflow
It was installed properly, but when I typed the command
`import tensorflow as tf`
the following errors came:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: %1 is not a valid Win32 application.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
import tensorflow as tf
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 74, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
File "<frozen importlib._bootstrap>", line 571, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 922, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: %1 is not a valid Win32 application.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 58, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 17, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 16, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
I searched a lot. I even installed tensorflow once more, but in vain.
I could not find any solution in internet. Can someone help me? Thank you in advance. :)
The TensorFlow Windows packages will only work with 64-Bit Python. It appears that your Python installation is 32-Bit. Install a 64-Bit Python version and you should be able to install TensorFlow without a problem.
I had exactly the same problem in my Windows 7 64 bits. In my case, TensorFlow 2.1 for Python 3.7.6 has installed OK. When I run a small demo gives this error. So I've installed the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019, X64 version and everything works as charm.

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