简体   繁体   中英

How to include path of tensorflow on ubuntu, python 2.7

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  

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM