A memorandum of scraping & machine learning [development technique] by Python (Chapter 5)

Chapter 5

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.

Start with python

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.

Start with python3

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.

  1. /usr/lib/python3.4
  2. /usr/lib/python3.4/plat-x86_64-linux-gnu
  3. /usr/lib/python3.4/lib-dynload
  4. /usr/local/lib/python3.4/dist-packages
  5. /usr/lib/python3/dist-packages

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.

: :

Strategy change (install tensorflow with pip3)

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. ..

reference

[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

A memorandum of scraping & machine learning [development technique] by Python (Chapter 4)
A memorandum of scraping & machine learning [development technique] by Python (Chapter 5)
A memorandum of extraction by python bs4 request
Get a glimpse of machine learning in Python
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
Python learning memo for machine learning by Chainer until the end of Chapter 2
Python learning memo for machine learning by Chainer from Chapter 2
Build a machine learning application development environment with Python
Python learning memo for machine learning by Chainer Chapter 7 Regression analysis
A beginner's summary of Python machine learning is super concise.
[Python] A memorandum of beautiful soup4
Machine learning summary by Python beginners
"Scraping & machine learning with Python" Learning memo
Python learning memo for machine learning by Chainer Chapter 8 Introduction to Numpy
Python learning memo for machine learning by Chainer Chapter 10 Introduction to Cupy
Python learning memo for machine learning by Chainer Chapter 9 Introduction to scikit-learn
[Learning memo] Basics of class by python
Python & Machine Learning Study Memo ④: Machine Learning by Backpropagation
Creating a development environment for machine learning
Judgment of igneous rock by machine learning ②
A memorandum of python string deletion process
Python learning memo for machine learning by Chainer Chapter 13 Neural network training ~ Chainer completed
A beginner of machine learning tried to predict Arima Kinen with python
Machine learning memo of a fledgling engineer Part 1
Classification of guitar images by machine learning Part 1
Machine learning starting with Python Personal memorandum Part2
Machine learning starting with Python Personal memorandum Part1
A memorandum of calling Python from Common Lisp
A memorandum of studying and implementing deep learning
Python & Machine Learning Study Memo ②: Introduction of Library
About the development contents of machine learning (Example)
Get a list of Qiita likes by scraping
Analysis of shared space usage by machine learning
[Translation] scikit-learn 0.18 Tutorial Introduction of machine learning by scikit-learn
Machine learning memo of a fledgling engineer Part 2
Reasonable price estimation of Mercari by machine learning
Classification of guitar images by machine learning Part 2
A story about data analysis by machine learning
Build a Python machine learning environment with a container
Chapter 6 Supervised Learning: Classification pg212 ~ [Learn by moving with Python! New machine learning textbook]
Implementation of a model that predicts the exchange rate (dollar-yen rate) by machine learning
Basic data frame operations written by beginners in a week of learning Python
A memorandum of method often used in machine learning using scikit-learn (for beginners)
[Recommended tagging for machine learning # 2] Extension of scraping script
Predicting the goal time of a full marathon with machine learning-③: Visualizing data with Python-
[Recommended tagging for machine learning # 2.5] Modification of scraping script
Run a machine learning pipeline with Cloud Dataflow (Python)
Basics of Python scraping basics
Build a machine learning Python environment on Mac OS
Python learning memo for machine learning by Chainer Chapters 1 and 2
Installation of TensorFlow, a machine learning library from Google
[Machine learning] "Abnormality detection and change detection" Let's draw the figure of Chapter 1 in Python.
Basics of Python learning ~ What is a string literal? ~
[Python] I made a classifier for irises [Machine learning]
Summary of the basic flow of machine learning with Python
Group by consecutive elements of a list in Python
Memo for building a machine learning environment using Python
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
MALSS, a tool that supports machine learning in Python
An example of a mechanism that returns a prediction by HTTP from the result of machine learning
Build a python machine learning study environment on macOS sierra