Immediately after installing tensorflow, I stumbled. Execute the following command to confirm that the installation was successful (p204).
root@19dc7f4125d1:~# python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'tensorflow'
It seems that the tensorflow module cannot be found. When I checked it with pip list, "tensorflow (0.7.1)" was included properly.
By the way, I didn't know how to start python and python3, but there are the following differences between how to start python and python3.
root@19dc7f4125d1:/# python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Python 2.x will be launched.
root@19dc7f4125d1:~# python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
Python 3.x will be launched.
Then, I will try to import tensorflow with python instead of python3.
>>> import tensorflow as tf
>>> sess = tf.Session()
>>> hello = tf.constant('Hello')
>>> sess.run(hello)
'Hello'
It's okay. I was able to import. Is it a path problem that can be imported with python but not with python3? Let's check the path of tensorflow.
>>> import tensorflow
>>> print tensorflow.__file__
/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.pyc
After all, the execution module of tensowflow was in the path under python2.x. It is OK if you set the path so that tensowflow can be executed even in python3.x.
First check the path of python3.x.
root@19dc7f4125d1:/# python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
>>>
So, you should look at "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.pyc" somewhere below.
This time, create a file called "/usr/local/lib/python3.4/dist-packages/custom.path" under number 5 and create "/usr/local/lib/python2.7/dist-packages" there. /tensorflow/__init__.pyc "has been added.
Now you can import tensorflow even with python3.
: :
After using it several times, I can't import tensorflow in python3 again. I changed my strategy and decided to install tensorflow. I haven't solved anything, but I'll move on.
I want to use it with Python3, so first I will enable pip3.
When I execute the following command when pip3 is not available, nothing is returned.
which pip3
Enable pip3 with the following command.
apt install python3-pip
Reconfirm whether pip3 can be used with the following command.
root@5ca7beea435b:/c/Users/yuki/my_dir/wap_scraping/src/ch5# which pip3
/usr/bin/pip3
The result is returned. Now that you're ready, set the path and install tensorflow.
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp34-cp34m-linux_x86_64.whl
$ pip3 install --upgrade $TF_BINARY_URL
I get the following result using pip3 list.
root@5ca7beea435b:/c/Users/yuki/my_dir/wap_scraping/src/ch5# pip3 list
chardet (2.2.1)
colorama (0.2.5)
html5lib (0.999)
numpy (1.11.3)
pip (1.5.4)
protobuf (3.1.0.post1)
pycurl (7.19.3)
pygobject (3.12.0)
python-apt (0.9.3.5ubuntu2)
requests (2.2.1)
setuptools (32.3.1)
six (1.10.0)
tensorflow (0.12.1)
unattended-upgrades (0.1)
urllib3 (1.7.1)
wheel (0.29.0)
I was able to run calc1.py without any problems.
It's hard to follow the book. ..
[title]http://pcl.solima.net/pyblog/archives/57 [title]https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md
Recommended Posts