0

I am trying to execute an old (python 2.7, tensorflow 1.3) program . conda list tensorflow shows tensorflow is installed. But the program cannot import tensorflow.

>python train.py

Traceback (most recent call last): File "train.py", line 5, in import tensorflow as tf ImportError: No module named tensorflow

I read Python error "ImportError: No module named" and import error: 'No module named' *does* exist

I think the permisson of file is okay.

>ls -al ./anaconda/envs/py2_env/lib/python2.7/site-packages/opt_einsum/backends/tensorflow.py
    -rw-rw-r-- 2 myid myid 3797 Oct 11  2019 ./anaconda/envs/py2_env/lib/python2.7/site-packages/opt_einsum/backends/tensorflow.py

After reading other answers when same error was encountered , I think I need to include the path for tensorflow to $PATH or $PYTHONPATH.
I am not sure which folder needs to be included. How to find the folder that needs to be included?

>find . -name tensorflow.py
./anaconda/envs/py2_env/lib/python2.7/site-packages/opt_einsum/backends/tensorflow.py
./anaconda/pkgs/opt_einsum-2.3.2-py_0/site-packages/opt_einsum/backends/tensorflow.py  
qqqqq
  • 837
  • 12
  • 31

1 Answers1

0

Looks like virtual environment is not activated before executing the train.py

#Activate the Environment
source activate py2_env

# Verify the tensorflow installation
py2_env$python
>import tensorflow as tf
>tf.__version__

#Execute your code
py2_env$ python train.py