Docker TensorFlow

pythonによるスクレイピング&機械学習 開発テクニック』
の5章 (5-2)だけ試してみた。

docker run -it b.gcr.io/tensorflow/tensorflow:latest-devel

本の通りにpython3で試したらエラー。

root@ac3b891d06fd:~# 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'

python 2系だといけた。

root@ac3b891d06fd:~# 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.
>>> 
>>> 
>>> import tensorflow as tf
>>> sess = tf.Session()
>>> hello = tf.constant('Hello')
>>> sess.run(hello)
'Hello'
>>> 
>>> 
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> sess.run(a+b)
42

rmする時、ワイルドカードでマッチするファイルの内、一つだけ除外したい場合

~/Documents/ に
FileZilla_ で始まる消したいファイルがあったけど、
最新の1個だけ残しておきたかった時のメモ。

rm FileZilla_*
で全部消せたけど、マッチするファイルの内1個だけ残したい。
同じディレクトリに消したくないファイルが他にある。

find . -type f -name 'FileZilla*' -not -name 'FileZilla_3.23.0.2_macosx-x86.app.tar.bz2' -print0 | xargs -0 rm

bash - rm all files except some - Stack Overflow

コマンドが長すぎてめんどくさい。

macOSにpipが入っていない

macOS Sierra
Version 10.12.2

% brew install pip
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
antlr                                              youtube-dl

Error: No available formula with the name "pip" 
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can install
pip via the instructions at:
  https://pip.readthedocs.io/en/stable/installing/
% curl -kL https://bootstrap.pypa.io/get-pip.py | python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1558k  100 1558k    0     0  3886k      0 --:--:-- --:--:-- --:--:-- 3895k
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 912kB/s 
Collecting wheel
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
    100% |████████████████████████████████| 71kB 4.8MB/s 
Installing collected packages: pip, wheel
Exception:
Traceback (most recent call last):
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/var/folders/t_/1c8g5tlj7y70t3s4f3pvsqkm0000gn/T/tmpdpNht1/pip.zip/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip'

sudo を付けるらしい

curl -kL https://bootstrap.pypa.io/get-pip.py | sudo python

インストールできた。

Visual Studio CodeでPython

MacBookProを買ったので環境設定。

Visual Studio CodeでPythonの開発環境構築を構築してみた。 | Developers.IO

Python - Visual Studio Marketplace

Visual Studio Codeで
Command + P
ext install python

donjayamanne.python

If using a custom Python Version or a Virtual Environment, use the command Select Workspace Interpreter)

pyenvとvirtualenvの設定
pyenvのメモ - kubotti’s memo

pyenv virtualenv anaconda3-4.2.0 pydev3

Visual Studio Codeで
Command + P

shell

celeryが原因でpython manage.py syncdbに失敗した時のメモ

エラー。

$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/home/user1/.pyenv/versions/2.7.12/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/user1/.pyenv/versions/app1/lib/python2.7/site-packages/djcelery/models.py", line 15, in <module>
    from celery.utils.timeutils import timedelta_seconds
ImportError: No module named timeutils

http://stackoverflow.com/questions/40540769/importerror-no-module-named-timeutils

$ pip uninstall celery
$ pip install celery==3.1

stackoverflowのおかげですぐに解決。