I am trying out tensorflow on my Mac. I use python 3.7 in a virtual environment.
I installed TensorFlow using pip install tensorflow successfully.
But now when I try to import it import tensorflow, it gives the following error
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow/__init__.py", line 98, in <module>
from tensorflow_core import *
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 40, in <module>
from tensorflow.python.tools import module_util as _module_util
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 959, in _find_and_load_unlocked
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow_core/python/__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/tensorflow_core/core/framework/graph_pb2.py", line 7, in <module>
from google.protobuf import descriptor as _descriptor
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/google/protobuf/__init__.py", line 37, in <module>
__import__('pkg_resources').declare_namespace(__name__)
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/__init__.py", line 84, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/_vendor/packaging/requirements.py", line 9, in <module>
from pkg_resources.extern.pyparsing import stringStart, stringEnd, originalTextFor, ParseException
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 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/extern/__init__.py", line 43, in load_module
__import__(extant)
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 4756, in <module>
_escapedPunc = Word( _bslash, r"\[]-*.$+^?()~ ", exact=2 ).setParseAction(lambda s,l,t:t[0][1])
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1284, in setParseAction
self.parseAction = list(map(_trim_arity, list(fns)))
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1066, in _trim_arity
this_line = extract_stack(limit=2)[-1]
File "/Users/sourabh/virtualenvs/ml/lib/python3.7/site-packages/pkg_resources/_vendor/pyparsing.py", line 1050, in extract_stack
frame_summary = traceback.extract_stack(limit=-offset+limit-1)[offset]
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 211, in extract_stack
stack = StackSummary.extract(walk_stack(f), limit=limit)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 363, in extract
f.line
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/traceback.py", line 285, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 48, in getlines
for mod in sys.modules.values():
RuntimeError: dictionary changed size during iteration
I've encountered the exact same problem, according https://github.com/tensorflow/tensorflow/issues/33183 this is an os-x catalina issue. However I found you can simply use python 3.7.6 to get rid of the problem, i.e. os-x catalina's python3 is version 3.7.3, with brew you can install python 3.7.6, backwards compatible and solves the problem :)
Related
() isikkaplan#iamhere# python3 manage.py loadfixtures -s=testing fixture fixtures/knock/0_ct.json -v3
Traceback (most recent call last):
File "/Users/isikkaplan/Desktop/code/---/-/--/manage.py", line 21, in <module>
main()
File "/Users/isikkaplan/Desktop/code/---/-/--/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
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 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/alphashape/__init__.py", line 6, in <module>
from .alphashape import alphashape
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/alphashape/alphashape.py", line 15, in <module>
import geopandas
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/geopandas/__init__.py", line 1, in <module>
from geopandas._config import options # noqa
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/geopandas/_config.py", line 126, in <module>
default_value=_default_use_pygeos(),
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/geopandas/_config.py", line 112, in _default_use_pygeos
import geopandas._compat as compat
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/geopandas/_compat.py", line 202, in <module>
import rtree # noqa
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/rtree/__init__.py", line 9, in <module>
from .index import Rtree, Index # noqa
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/rtree/index.py", line 6, in <module>
from . import core
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/site-packages/rtree/core.py", line 77, in <module>
rt.Error_GetLastErrorNum.restype = ctypes.c_int
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/ctypes/__init__.py", line 395, in __getattr__
func = self.__getitem__(name)
File "/opt/homebrew/Caskroom/miniforge/base/envs/--/lib/python3.9/ctypes/__init__.py", line 400, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, Error_GetLastErrorNum): symbol not found
Almost all of the answers online leads to installing spatialindex which I already have and I have no idea how can I fix this.
If you are using a conda environment like I am, which is basically a necessity if you are on an m1 and not using docker, then you need to install the system libraries for the current environment via conda also.
conda install -c conda-forge libspatialindex
I am using python3.8.8 in windows10. I just typed pip list in
venv(CMD) which showed a big error. I was using this venv for pip
installing tensorflow which also showed this similar error
## Heading ## (venv) C:\Users\HP>pip list Traceback (most recent
call last): File
"c:\users\hp\appdata\local\programs\python\python38\lib\runpy.py",
line 194, in _run_module_as_main
return _run_code(code, main_globals, None, File "c:\users\hp\appdata\local\programs\python\python38\lib\runpy.py",
line 87, in _run_code
exec(code, run_globals) File "C:\Users\HP\venv\Scripts\pip.exe\__main__.py", line 7, in <module>
File "c:\users\hp\venv\lib\site-packages\pip\_internal\cli\main.py",
line 71, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args)) File
"c:\users\hp\venv\lib\site-packages\pip\_internal\commands\__init__.py",
line 96, in create_command
module = importlib.import_module(module_path) File "c:\users\hp\appdata\local\programs\python\python38\lib\importlib\__init__.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen
importlib._bootstrap_external>", line 783, in exec_module File
"<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed File "c:\users\hp\venv\lib\site-packages\pip\_internal\commands\list.py",
line 5, in <module>
from pip._internal.cli.req_command import IndexGroupCommand File
"c:\users\hp\venv\lib\site-packages\pip\_internal\cli\req_command.py",
line 16, in <module>
from pip._internal.index.collector import LinkCollector File "c:\users\hp\venv\lib\site-packages\pip\_internal\index\collector.py",
line 16, in <module>
from pip._vendor import html5lib, requests File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\__init__.py",
line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\html5parser.py",
line 6, in <module>
from . import _inputstream File "c:\users\hp\venv\lib\site-packages\pip\_vendor\html5lib\_inputstream.py",
line 10, in <module>
from pip._vendor import webencodings ImportError: cannot import name 'webencodings' from 'pip._vendor'
(c:\users\hp\venv\lib\site-packages\pip\_vendor\__init__.py)
I'm trying to list pip packages, but when I run pip list, I get this error message
Traceback (most recent call last):
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\Ben\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe\__main__.py", line 7, in <module>
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\commands\list.py", line 9, in <module>
from pip._internal.cli.req_command import IndexGroupCommand
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\cli\req_command.py", line 16, in <module>
from pip._internal.index.collector import LinkCollector
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_internal\index\collector.py", line 14, in <module>
from pip._vendor import html5lib, requests
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\__init__.py", line 25, in <module>
from .html5parser import HTMLParser, parse, parseFragment
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\html5parser.py", line 6, in <module>
from . import _inputstream
File "c:\users\ben\appdata\local\programs\python\python38-32\lib\site-packages\pip\_vendor\html5lib\_inputstream.py", line 10, in <module>
from pip._vendor import webencodings
ValueError: source code string cannot contain null bytes
I thought it was just a problem with the list command and forgot about it, so I installed a pip package. However, when I put the command in, I still got the same error message. Pip was working fine before so I don't know if there's a problem with a piece of code I need to fix or something.
when i tried to install netfilterqueue this error came up.
even i can't uninstall/check/install using pip.
And i searched over the stackoverflow and one of those said use :
sudo pip install -U setuptools
And again this error came up.
Traceback (most recent call last):
File "/usr/bin/pip", line 33, in <module>
sys.exit(load_entry_point('pip==20.1.1', 'console_scripts', 'pip')())
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 24, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/usr/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 20, in <module>
from pip._internal.operations.prepare import RequirementPreparer
File "/usr/lib/python3.8/site-packages/pip/_internal/operations/prepare.py", line 15, in <module>
from pip._internal.distributions import (
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/__init__.py", line 2, in <module>
from pip._internal.distributions.wheel import WheelDistribution
File "/usr/lib/python3.8/site-packages/pip/_internal/distributions/wheel.py", line 5, in <module>
from pip._internal.utils.wheel import pkg_resources_distribution_for_wheel
File "/usr/lib/python3.8/site-packages/pip/_internal/utils/wheel.py", line 12, in <module>
from pip._vendor.six import PY2, ensure_str
ImportError: cannot import name 'ensure_str' from 'six' (/usr/lib/python3.8/site-packages/six.py)
Thanks in advance.
I was able to make this work by copying six.py from https://github.com/benjaminp/six.git into /usr/lib/python3.8/six.py ... you'll need sudo to create or update this file.
Code: import tensorflow
Gives the following error
ERROR:root:Internal Python error in the inspect module.
Below is the traceback from this internal error.
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-d6579f534729>", line 1, in <module>
import tensorflow
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 99, in <module>
from tensorflow_core import *
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "<frozen importlib._bootstrap>", line 1019, in _handle_fromlist
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\python\__init__.py", line 52, in <module>
from tensorflow.core.framework.graph_pb2 import *
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 16, in <module>
from tensorflow.core.framework import node_def_pb2 as tensorflow_dot_core_dot_framework_dot_node__def__pb2
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\core\framework\node_def_pb2.py", line 16, in <module>
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\core\framework\attr_value_pb2.py", line 16, in <module>
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\core\framework\tensor_pb2.py", line 16, in <module>
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\core\framework\resource_handle_pb2.py", line 92, in <module>
__module__ = 'tensorflow.core.framework.resource_handle_pb2'
TypeError: expected bytes, Descriptor found
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2033, in showtraceback
stb = value._render_traceback_()
AttributeError: 'TypeError' object has no attribute '_render_traceback_'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 1095, in get_records
return _fixed_getinnerframes(etb, number_of_lines_of_context, tb_offset)
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 313, in wrapped
return f(*args, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\ultratb.py", line 347, in _fixed_getinnerframes
records = fix_frame_records_filenames(inspect.getinnerframes(etb, context))
File "C:\ProgramData\Anaconda3\lib\inspect.py", line 1502, in getinnerframes
frameinfo = (tb.tb_frame,) + getframeinfo(tb, context)
File "C:\ProgramData\Anaconda3\lib\inspect.py", line 1460, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "C:\ProgramData\Anaconda3\lib\inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "C:\ProgramData\Anaconda3\lib\inspect.py", line 733, in getmodule
if ismodule(module) and hasattr(module, '__file__'):
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 50, in __getattr__
module = self._load()
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow\__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "C:\ProgramData\Anaconda3\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 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
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 "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\__init__.py", line 32, in <module>
from tensorflow._api.v1 import app
File "C:\Users\hp\AppData\Roaming\Python\Python37\site-packages\tensorflow_core\_api\v1\app\__init__.py", line 14, in <module>
from tensorflow.python.util import module_wrapper as _module_wrapper
ImportError: cannot import name 'module_wrapper' from 'tensorflow.python.util' (C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\__init__.py)
I have installed tensorflow using the following command:
pip install --ignore-installed --upgrade tensorflow-gpu==1.15.0
Same issue occurs while importing keras too. Also note that I am new to tensorflow and keras
Try installing tensorflow with conda.
conda install -c anaconda tensorflow-gpu==1.15.0
If you still have problems you can delete the environment and install with conda the first time.