Bash on Windows10 有効化メモ

OSビルドバージョン確認

スタートメニュー > 設定 > システム > バージョン情報

https://msdn.microsoft.com/en-us/commandline/wsl/install_guide

Windows Updateからだと、
Windows 10 Anniversary Update
が適用されなかったので、インストーラーをダウンロードした。
https://support.microsoft.com/ja-jp/help/12387/windows-10-update-history?ocid=update_setting_client

Windows 10 Anniversary Update のインストーラーを実行してアップデート。

開発者モード の有効化

スタートメニュー > 設定 > 更新とセキュリティ > 開発者向け

開発者モード
をチェック。

Windows Subsystem for Linux (Beta)

スタートボタンを右クリック > プログラムと機能 > (左側の)Windowsの機能の有効化または無効化
Windows Subsystem for Linux (Beta)
をチェックしてOKボタン。

http://qiita.com/Aruneko/items/c79810b0b015bebf30bb

※会社で使っているPCは32bit版WindowsだったのでWindows Subsystem for Linux (Beta)が出てこなかった。

コピー&ペースト

Ctrl + V でコピペができない。

Windows 10 build 14316: Ctrl + v doesn't work on Bash on Ubuntu on Windows - Super User 簡易編集モードを有効にすると、
マウスの右クリックで貼り付け(ペースト)はできるっぽい。

nginx + django uwsgi

CentOS6 にdjangoアプリを設置しようとしたら、nginxでエラーになった。
django 1.8

EC2上で Django + Nginx + uWSGI を試す - Qiita

http://unix.stackexchange.com/questions/218747/nginx-says-open-etc-nginx-conf-d-foo-conf-failed-13-permission-denied

service nginx restart
nginx: [emerg] open() "/home/aaaaaaa/app1/uwsgi_params" failed (13: Permission denied) in /etc/nginx/conf.d/app1.conf:25
nginx: configuration file /etc/nginx/nginx.conf test failed

SELinuxが原因だった。

service nginx restart
nginx: [emerg] invalid number of arguments in "uwsgi_param" directive in /home/aaaaaaa/app1/uwsgi_params:11
nginx: configuration file /etc/nginx/nginx.conf test failed

http://serverfault.com/questions/704366/error-invalid-number-of-arguments-in-uwsgi-param-directive-on-nginx-restart

http://nginx.org/en/linux_packages.html#stable

nginx の再インストール

nginxを1.10.1にする。

/etc/yum.repos.d/nginx.repo

http://qiita.com/utano320/items/0c0d9b84a9a28525bcb9

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
yum remove nginx
yum remove nginx-filesystem

Installing:
 nginx                      x86_64                      1.10.1-1.el6.ngx                         nginx                      821 k

server_names_hash_bucket_size

service nginx start
Starting nginx: nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 32

/etc/nginx/nginx.conf
server_names_hash_bucket_size 64;
を足した。

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;
    server_names_hash_bucket_size 64;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

連携設定

uwsgi --wsgi-file wsgi.py --socket 127.0.0.1:3031
upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    server 127.0.0.1:3031;
}

rmで指定したファイル以外を削除

メモ:

ls | grep -v -E 'bpmappers|__init__.py' | xargs rm -r

~以外を削除する場合(rmコマンド) - Linux系OS 解決済 | 教えて!goo

Linuxで特定のファイル、ディレクトリ以外を削除するコマンド|はぐれメタルのブログ

django PostgreSQL Error : Symbol not found: _lo_lseek64

Django 1.8
PostgreSQL 9.4
Mac OS X Yosemite (Version 10.10.5)

python manage.py runserver

でエラー。

    return import_module('%s.base' % backend_name)
  File "/Users/uuuuuuuu/.pyenv/versions/2.7.9/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/uuuuuuuu/.pyenv/versions/mmr2/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/uuuuuuuu/.pyenv/versions/mmr2/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _lo_lseek64
  Referenced from: /Users/uuuuuuuu/.pyenv/versions/mmr2/lib/python2.7/site-packages/psycopg2/_psycopg.so
  Expected in: /usr/lib/libpq.5.dylib
 in /Users/uuuuuuuu/.pyenv/versions/mmr2/lib/python2.7/site-packages/psycopg2/_psycopg.so

http://stackoverflow.com/questions/8237842/django-core-exceptions-improperlyconfigured-error-loading-psycopg-module-no-mo

Pythonインタープリターでも同じエラー。

>>> import psycopg2

psycopg2 を読み込んだ時に、Symbol not found: _lo_lseek64

http://stackoverflow.com/questions/28515972/problems-using-psycopg2-on-mac-os-yosemite

$ sudo mv /usr/lib/libpq.5.dylib /usr/lib/libpq.5.dylib.old  
$ sudo ln -s /Library/PostgreSQL/9.4/lib/libpq.5.dylib /usr/lib

で直った。

pyenvでPythonのバージョンが切り替わらない

pyenvのコマンドで2.7.9に設定して、pyenvのコマンドで設定確認したら2.7.9なのに、
python コマンドを実行するとバージョンが3.5.1

pyenv local 2.7.9
pyenv local
2.7.9

pyenv global 2.7.9
pyenv global      
2.7.9

pyenv shell 2.7.9
pyenv shell      
2.7.9
python
Python 3.5.1 (default, Jan 22 2016, 08:52:08) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

.pyenvディレクトリの中

2.7.9の実体が3.5.1になっている気がする。

~/.pyenv/versions/2.7.9/bin% ll

total 96
-rw-r--r--  1 kubotad  staff  2154 May 19 12:52 activate
-rw-r--r--  1 kubotad  staff  1270 May 19 12:52 activate.csh
-rw-r--r--  1 kubotad  staff  2406 May 19 12:52 activate.fish
-rwxr-xr-x  1 kubotad  staff   267 May 19 12:52 easy_install
-rwxr-xr-x  1 kubotad  staff   267 May 19 12:52 easy_install-3.5
-rwxr-xr-x  1 kubotad  staff   239 May 19 12:52 pip
-rwxr-xr-x  1 kubotad  staff   239 May 19 12:52 pip3
-rwxr-xr-x  1 kubotad  staff   239 May 19 12:52 pip3.5
lrwxr-xr-x  1 kubotad  staff     9 May 19 12:52 python -> python3.5
lrwxr-xr-x  1 kubotad  staff     9 May 19 12:52 python3 -> python3.5
lrwxr-xr-x  1 kubotad  staff    86 May 19 12:52 python3.5 -> /usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/bin/python3.5
-rwxr-xr-x  1 kubotad  staff   246 Jun 29 19:04 virtualenv
pyenv uninstall 2.7.9
pyenv: remove /Users/kubotad/.pyenv/versions/2.7.9? y

pyenv install 2.7.9 
Downloading Python-2.7.9.tgz...
-> https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
Installing Python-2.7.9...
patching file ./Lib/site.py
patching file ./Lib/ssl.py
Installed Python-2.7.9 to /Users/kubotad/.pyenv/versions/2.7.9

とりあえず、直った。

python
Python 2.7.9 (default, Jun 29 2016, 19:25:33) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt