2
C:\Users\jpala\.conda\envs\tf\python.exe C:\Users\jpala\Documents\ML\train.py 
Traceback (most recent call last):
  File "C:\Users\jpala\Documents\ML\train.py", line 5, in <module>
    import tensorflow as tf
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\__init__.py", line 37, in <module>
    from tensorflow.python.tools import module_util as _module_util
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\__init__.py", line 42, in <module>
    from tensorflow.python import data
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\__init__.py", line 21, in <module>
    from tensorflow.python.data import experimental
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\experimental\__init__.py", line 96, in <module>
    from tensorflow.python.data.experimental import service
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\experimental\service\__init__.py", line 419, in <module>
    from tensorflow.python.data.experimental.ops.data_service_ops import distribute
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\experimental\ops\data_service_ops.py", line 25, in <module>
    from tensorflow.python.data.ops import dataset_ops
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\ops\dataset_ops.py", line 29, in <module>
    from tensorflow.python.data.ops import iterator_ops
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py", line 34, in <module>
    from tensorflow.python.training.saver import BaseSaverBuilder
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\training\saver.py", line 32, in <module>
    from tensorflow.python.checkpoint import checkpoint_management
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\checkpoint\__init__.py", line 3, in <module>
    from tensorflow.python.checkpoint import checkpoint_view
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\checkpoint\checkpoint_view.py", line 19, in <module>
    from tensorflow.python.checkpoint import trackable_view
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\checkpoint\trackable_view.py", line 20, in <module>
    from tensorflow.python.trackable import converter
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\trackable\converter.py", line 18, in <module>
    from tensorflow.python.eager.polymorphic_function import saved_model_utils
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\eager\polymorphic_function\saved_model_utils.py", line 36, in <module>
    from tensorflow.python.trackable import resource
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\trackable\resource.py", line 22, in <module>
    from tensorflow.python.eager import def_function
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\eager\def_function.py", line 20, in <module>
    from tensorflow.python.eager.polymorphic_function.polymorphic_function import set_dynamic_variable_creation
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\eager\polymorphic_function\polymorphic_function.py", line 76, in <module>
    from tensorflow.python.eager.polymorphic_function import function_spec as function_spec_lib
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\python\eager\polymorphic_function\function_spec.py", line 25, in <module>
    from tensorflow.core.function.polymorphism import function_type as function_type_lib
  File "C:\Users\jpala\.conda\envs\tf\lib\site-packages\tensorflow\core\function\polymorphism\function_type.py", line 19, in <module>
    from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple, OrderedDict
ImportError: cannot import name 'OrderedDict' from 'typing' (C:\Users\jpala\.conda\envs\tf\lib\typing.py)

Process finished with exit code 1

I got this error while trying to install and run tensorflow for gpu following this tutorial https://www.youtube.com/watch?v=hHWkvEcDBO0 I have python 3.7.4 What am I doing wrong here, is it a version issue?

Jerome Palayoor
  • 31
  • 1
  • 1
  • 9
  • Please add the code that you're running. [\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example). Are you sure about *Python 3.7.**4***? Before `import tensorflow as tf` add `import sys` and `print(sys.version)` and paste the output. – CristiFati Feb 22 '23 at 07:55
  • This [issue in github](https://github.com/python/mypy/issues/6904#issuecomment-496207426) may be helpful for Python 3.7. – Shorn Feb 22 '23 at 07:58
  • when i added that code i got : 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] but when i open python the version shown is 3.7.4, is it because i choose version 3.7 in anaconda that will change the python version? thank you so much – Jerome Palayoor Feb 22 '23 at 08:03
  • btw the code I was using was also from the tutorial: https://github.com/aladdinpersson/Machine-Learning-Collection/blob/master/ML/TensorFlow/Basics/tutorial4-convnet.py – Jerome Palayoor Feb 22 '23 at 08:04
  • This code will not run on Python 3.7.0, you need to be using 3.7.4. – Dr. Snoopy Feb 22 '23 at 08:18
  • What's the output of `python -c "import sys, typing;print(sys.version, \"\n\", \"OrderedDict\" in dir(typing), \"\nDone.\n\")` – CristiFati Feb 22 '23 at 08:18
  • @CristiFati i did that and got "3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]" in cmd and i just updated my anaconda python version to 3.7.4 and now it shows 3.7.4, now this works thanks guys! however now it does not detect my gpu even tho I installed cuda and cdnn – Jerome Palayoor Feb 22 '23 at 08:29
  • Maybe the last *URL* in my answer could help with *GPU*. – CristiFati Feb 22 '23 at 08:42

1 Answers1

4

According to [Python.docs]: class typing.OrderedDict(collections.OrderedDict, MutableMapping[KT, VT]) (emphasis is mine):

New in version 3.7.2.

Example:

(base) [cfati@CFATI-5510-0:e:\Work\Dev\StackOverflow\q075529492]> sopr.bat
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###

[prompt]> conda env list
# conda environments:
#
                         F:\Install\pc032\Intel\OneAPI\Version\intelpython\python3.7
                         F:\Install\pc032\Intel\OneAPI\Version\intelpython\python3.7\envs\2021.1.1
base                  *  f:\Install\pc064\Anaconda\Anaconda\Version
py_pc032_03_06_02        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc032_03_06_02
py_pc064_03_06_02        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc064_03_06_02
py_pc064_03_07_04        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc064_03_07_04
py_pc064_03_08_08        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc064_03_08_08
py_pc064_03_10_00        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc064_03_10_00
py_pc064_03_10_06        f:\Install\pc064\Anaconda\Anaconda\Version\envs\py_pc064_03_10_06


[prompt]>
[prompt]> conda activate py_pc064_03_07_04

(py_pc064_03_07_04) [prompt]>
(py_pc064_03_07_04) [prompt]> python -c "import sys, typing;print(\"{:}\n{:}\nDone.\n\".format(sys.version, \"OrderedDict\" in dir(typing)"))
3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
True
Done.

There it is: Python 3.7.4 from Anaconda, whose typing module has OrderedDict.
The only logical conclusion (well, excluding a broken environment with an messed up typing version) one could draw is that you're actually running Python < v3.7.2.
The fix is running Python >= v3.7.2.

Might want to also check:

CristiFati
  • 38,250
  • 9
  • 50
  • 87