Home > Blockchain >  Tensorflow version mismatch
Tensorflow version mismatch

Time:03-03

I use Windows 10 and Anaconda to manage all my environments and I have a few different environments that work with Tensorflow.

I have one environment with a working 1.14 version. I have another environment with a working 2.5 version. I just created another environment where I installed 1.15 version.

# Name                    Version                   Build  Channel
tensorflow                1.15.0          gpu_py37hc3743a6_0
tensorflow-base           1.15.0          gpu_py37h1afeea4_0
tensorflow-estimator      2.6.0              pyh7b7c402_0
tensorflow-gpu            1.15.0               h0d30ee6_0

However when I run python, it still loads tensorflow 2.5

(tf1p37) C:\Users\mazat>conda list tensorflow
# packages in environment at C:\Users\name\anaconda3\envs\tf1p37:
#
# Name                    Version                   Build  Channel
tensorflow                1.15.0          gpu_py37hc3743a6_0
tensorflow-base           1.15.0          gpu_py37h1afeea4_0
tensorflow-estimator      2.6.0              pyh7b7c402_0
tensorflow-gpu            1.15.0               h0d30ee6_0

(tf1p37) C:\Users\name>python
Python 3.7.11 (default, Jul 27 2021, 09:42:29) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2022-03-02 11:29:51.314557: I tensorflow/stream_executor/platform/default/dso_loader.cc:53] Successfully opened dynamic library cudart64_110.dll
>>> tf.__version__
'2.5.0'
>>>

So looks like even though I have the correct version installed in this env it still loads the version from a different environment. What could be the cause of that? The exact same thing is happening with Keras versions.

Update1: Here's the output of sys.path

>>> import sys
>>> sys.path
['', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\python37.zip',
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\DLLs', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37', 
'C:\\Users\\name\\AppData\\Roaming\\Python\\Python37\\site-packages', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages\\locket-0.2.1-py3.7.egg', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages\\win32',
 'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages\\win32\\lib', 
'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages\\Pythonwin'
]
>>>

CodePudding user response:

This continues on the discussion we had in the comments.

When you import sys and then print(sys.path), you can see all the paths where your interpreter will look for packages, in that order. The packages that you installed in your environment tf1p37 are located in 'C:\\Users\\name\\anaconda3\\envs\\tf1p37\\lib\\site-packages'. This is also where tensorflow 1.15 is installed.

However, there is also a tensorflow installed (i.e. version 2.5) in 'C:\\Users\\name\\AppData\\Roaming\\Python\\Python37\\site-packages' , which is earlier in the list. What happens is that your python interpreter searches for the first tensorflow that it finds, which is this global-installed version. After that, it does not look any further for another installation. By deleting this item from sys.path, the first occurrence (and probably the only one) is then tensorflow 1.15.

  • Related