金子邦彦研究室インストールUbuntu, WSL2Ubuntu で pyenv, Anaconda 5.3.0, Python 2.7.15, 各種パッケージのインストール

Ubuntu で pyenv, Anaconda 5.3.0, Python 2.7.15, 各種パッケージのインストール

pyenvは,Python をインストールするのに便利なツールである. システムの Python とPython の仮想環境の作成と利用が簡単にできる機能もある. Anaconda は,Python バージョン 3 の言語処理系と,開発環境 (Jupyter ノートブック (Jupyter Notebook), Spyder) と,各種ツールの詰め合わせである.

ここで行うこと.

pyenv をインストールする.pyenv の配下に Anaconda 5.3.0 (Python 3.6 同封)、Python 2.7.15 をインストールする.それらにパッケージを追加する.

目次

  1. 前準備 (preparation)
  2. pyenv のインストールと設定 (Install pyenv, and its settings)
  3. pyenv を用いて Anaconda 5.3.0 のインストール
  4. pyenv を用いて Python 2.7.15 のインストール
  5. pyenv の確認 (Examine pyenv)
  6. pyenv の Anaconda 5.3.0 環境での各種パッケージのインストール
  7. pyenv の Anaconda 5.3.0 環境で spyder 開発版 のインストール
  8. pyenv の Anaconda 5.3.0 環境で SWIG を使ってみる
  9. Python 3.6 系での既知のバグ
  10. pyenv の Python 2.7.15 環境での各種パッケージのインストール
  11. (オプション) Ubuntu 版 Graphviz のインストール (Optionally, Install Graphviz for Ubuntu)
  12. Python パッケージのインストール (Install / Upgrade Recommended Python Packages)

サイト内の関連 Web ページ:

前準備

Ubuntu のシステム更新

UbuntuUbuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行する.

UbuntuUbuntu のインストールは別ページ »で説明

sudo apt -y update
sudo apt -yV upgrade
sudo /sbin/shutdown -r now

C/C++ コンパイラー,make,パッケージツールのインストール(Ubuntu 上)

インストールするには,端末で,次のコマンドを実行する.

sudo apt -y install build-essential gcc g++ make libtool texinfo dpkg-dev pkg-config

git, wget,libbz2-dev,libreadline-dev,libssl-dev,libsqlite3-dev のインストール

端末で,次のコマンドを実行する.

sudo apt -y update
sudo apt -y install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev

pyenv のインストールと設定

  1. pyenv のダウンロード (Download pyenv)
    cd /tmp
    git clone https://github.com/pyenv/pyenv.git ~/.pyenv
    
  2. pyenv の更新 (Updata pyenv)
    cd ~/.pyenv
    git pull
    

    [image]
  3. pyenv の設定 (Settings of pyenv)
    echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.bashrc
    echo 'if [ -d "${PYENV_ROOT}" ]; then' >> ~/.bashrc
    echo '    export PATH=${PYENV_ROOT}/bin:$PATH' >> ~/.bashrc
    echo '    eval "$(pyenv init -)"' >> ~/.bashrc
    echo 'fi' >> ~/.bashrc
    exec $SHELL -l
    

    [image]

pyenv を用いて Anaconda 5.3.0 のインストール

  1. 新しく端末を開く
  2. インストールするPython のバージョンの確認 (decide the version)
    pyenv rehash 
    pyenv install -l 
    

    [image]
  3. インストールできる Anaconda3 のバージョンの確認 (Anaconda Versions)
    pyenv install -l | grep anaconda 
    

    [image]
  4. Anaconda3 の前提ソフトウェアのインストール (Install libraries)
    sudo apt -y update
    sudo apt -y install libbz2-dev libsqlite3-dev libssl-dev libreadline-dev libpng-dev libjpeg-dev zlib1g-dev libx11-dev libfreetype6-dev
    

    [image]
  5. Anaconda3 の最新版のインストールと設定 (Install Anaconda latest version)

    下の実行例では anaconda3-5.3.0 をインストールしている

    pyenv install anaconda3-5.3.0
    

    [image]
  6. 確認 (Examine the python versions)
    pyenv versions
    

    anaconda3-5.3.0」がインストールされたことが分かる

    [image]
  7. 試しに、anaconda3-5.3.0 のPython を起動してみる (Try to launch anaconda3-5.3.0 Python)

    「pyenv shell anaconda3-5.3.0」は、anaconda3-5.3.0 のPythonの使用を開始するためのコマンド

    pyenv shell anaconda3-5.3.0
    python 
    print(1 + 2)
    exit()
    

    [image]
  8. 試しに spyder を起動してみる
    pyenv shell anaconda3-5.3.0
    spyder
    

    [image]

    spyder の画面が開くことを確認する

    [image]

pyenv を用いて Python 2.7.15 のインストール

  1. 新しく端末を開く
  2. システムの python のバージョンの確認
    
    

    Ubuntu 18.04 での実行結果の例

    [image]
  3. インストールするPython のバージョンの確認 (decide the version)
    pyenv rehash 
    pyenv install -l 
    

    [image]
  4. インストールできる Python 2 のバージョンの確認
    pyenv install -l | grep 2.
    

    [image]
  5. Python 2.7.15 のインストールと設定 (Install Python 2.7.15 and Settings)
    pyenv install 2.7.15
    

    [image]
  6. 確認 (Examine the python versions)
    pyenv versions
    

    [image]

    複数のPython がインストールされていることが分かる。

    使用する Python の切り替えは 次のコマンドで行う

    • pyenv shell system
    • pyenv shell 2.7.15
    • pyenv shell anaconda3-5.3.0
  7. 試しに Python を起動してみる (Try to launch Python)
    pyenv shell 2.7.15
    python 
    print(1 + 2)
    exit()
    pyenv shell anaconda3-5.3.0
    python 
    print(1 + 2)
    exit()
    

    [image]
  8. (オプション)デフォルトで使用する Python の設定 (optionally, setting of default python)

pyenv の確認 (Examine pyenv)

  1. 新しく端末を開く
  2. ~/.pyenv/versions ディレクトリ (~/.pyenv/versions directory)
    ls ~/.pyenv/versions
    

    [image]
  3. pyenv により、pip と easy_install も設定される (pyenv do setting up easy_install and pip)
    which pip
    which easy_install
    

    [image]
  4. Python のパッケージも同時にインストールされる (Python packages are also installed)
    pyenv shell 2.7.15
    which pip
    which easy_install
    pip list
    

    [image]
    pyenv shell anaconda3-5.3.0
    which pip
    which easy_install
    pip list
    

    [image]

pyenv の Anaconda 5.3.0 環境での各種パッケージのインストール

  1. まずは,Anaconda3 に、最新の conda-build パッケージが欲しい.次のコマンドを実行

    ※ conda-buildパッケージは,condaパッケージを自前で作成するなどが簡単にできるためのツール.

    pyenv shell anaconda3-5.3.0
    conda install -y conda-build
    

    [image]

    ※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enter キーを押してみる.

  2. pip の更新 (Update pip)
    cd /tmp
    sudo rm -f get-pip.py
    curl -O https://bootstrap.pypa.io/get-pip.py
    python get-pip.py
    

    [image]
  3. setuptools, conda, conda-build の更新 (Update setuptools, conda and conda-build)
    conda update -y setuptools
    conda update -y conda
    conda update -y conda-build
    

    ※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enterキーを押してみる.

    [image]
  4. gcc_linux, gxx_linux のインストール・インストール済みパッケージの更新
    conda install -y gcc_linux-64
    conda install -y gxx_linux-64
    conda update -y --all
    
  5. 各種パッケージのインストール

    Anaconda では,「conda」という形式の Python のパッケージも、簡単に扱うことができる. Python のパッケージを追加することで,Python にいろいろな機能を追加することができる.conda を用いてPythonパッケージ以外のソフトウェアをインストールすることもできる

    端末で,次のコマンドを実行する.

    pyenv shell anaconda3-5.3.0
    conda install -y numpy
    conda install -y six
    conda install -y protobuf
    conda install -y pillow
    conda install -y hdf5
    conda install -y h5py
    conda install -y chainer
    #
    conda install -y scikit-learn
    conda install -y scikit-image
    conda install -y matplotlib
    conda install -y seaborn
    conda install -y graphviz
    conda install -y pydot
    conda install -y yaml
    conda install -y flask
    conda install -y django
    conda install -y sympy
    conda install -y pandas
    conda install -y sqlite
    conda install -y redis
    conda install -y scipy
    conda install -y gensim
    conda install -y opencv
    conda install -y pylint
    conda install -y bz2file
    conda install -y PyOpenGL 
    conda install -y ipykernel
    # pip install ... か  github を使うもの
    #  最初の conda ... は、下の pip でいれているものの前提ソフトウェア
    conda install -y termcolor astor wheel setuptools six protobuf werkzeug markdown absl-py grpcio gast future six click cligj click-plugins munch fiona python-dateutil pytz pyproj shapely 
    pip install git+https://github.com/msgpack/msgpack-python
    pip install git+https://github.com/davisking/dlib
    pip install git+https://github.com/ageitgey/face_recognition
    pip install git+https://github.com/jrosebr1/imutils
    
    pip install --ignore-installed --upgrade pyglet
    pip install --ignore-installed --upgrade pygame
    pip install --ignore-installed --upgrade cocos2d
    pip install --ignore-installed --upgrade geopandas
    pip install git+https://github.com/DinoTools/python-overpy
    # conda-forge か pip install git+https://github... でインストールするもの
    pip install git+https://github.com/python-visualization/folium
    conda install -y -c conda-forge exifread
    conda install -y -c conda-forge haversine
    conda install -y -c conda-forge utm
    conda install -y -c conda-forge gdal
    #again
    conda install -y conda
    conda update -y --all
    

    ※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enterキーを押してみる.

pyenv の Anaconda 5.3.0 環境で spyder 開発版 のインストール

https://github.com/spyder-ide/spyder に記載の手順に従う

pyenv shell anaconda3-5.3.0
pip install -U PyQt5
pip install git+https://github.com/spyder-ide/spyder-kernels
pip install git+https://github.com/spyder-ide/qtpy
cd /tmp
git clone https://github.com/spyder-ide/spyder.git
cd spyder 
git pull 
python bootstrap.py
python setup.py install 

spyder」で、試しに起動してみる.

[image]

[image]

pyenv の Anaconda 5.3.0 環境で SWIG を使ってみる

  1. SWIG のインストール (Install swig)
    sudo apt -y update
    sudo apt -y install swig
    

    [image]
  2. プログラムファイルの作成

    http://www.swig.org/Doc1.3/Python.html#Python_nn6 に記載のサンプルプログラム

  3. 新しく端末を開く
  4. プログラムファイルから、Python で実行可能にするためのファイルを作る

    端末で次のように操作

    pyenv shell anaconda3-5.3.0
    swig -python example.i
    python setup.py build_ext --inplace
    ls -la example.* build 
    

    [image]
  5. python 処理系を起動し、次のプログラムを試してみる
    import example
    example.fact(4)
    exit()
    

    [image]

Python 3.6 系での既知のバグ

参考Webページ https://qiita.com/ruteshi_SI_shiteru/items/be6a58276bdbd67dc096

~/.pyenv/versions/anaconda3-5.3.0/pkgs/pip-9.0.3-py36_0/lib/python3.6/site-packages/pip/compat/__init__.py をエディタで修正.

※ 「pip-9.0.3-py36_0」のところは違うかも.

修正前

[image]

修正後

[image]

修正前

[image]

修正後

[image]

pyenv の Python 2.7.15 環境での各種パッケージのインストール

  1. まずは,pip の更新
    pyenv shell 2.7.15
    cd /tmp
    sudo rm -f get-pip.py
    curl -O https://bootstrap.pypa.io/get-pip.py
    python get-pip.py
    

    [image]

    ※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enter キーを押してみる.

  2. 各種パッケージのインストール

    端末で,次のコマンドを実行する. pip を利用.sudo は付けない.

    pyenv shell 2.7.15
    pip install --ignore-installed --upgrade numpy
    pip install --ignore-installed --upgrade six
    pip install --ignore-installed --upgrade protobuf
    pip install --ignore-installed --upgrade pillow
    pip install --ignore-installed --upgrade hdf5
    pip install --ignore-installed --upgrade h5py
    pip install --ignore-installed --upgrade chainer
    #
    pip install --ignore-installed --upgrade scikit-learn
    pip install --ignore-installed --upgrade scikit-image
    pip install --ignore-installed --upgrade matplotlib
    pip install --ignore-installed --upgrade seaborn
    pip install --ignore-installed --upgrade graphviz
    pip install --ignore-installed --upgrade pydot
    pip install --ignore-installed --upgrade yaml
    pip install --ignore-installed --upgrade flask
    pip install --ignore-installed --upgrade django
    pip install --ignore-installed --upgrade sympy
    pip install --ignore-installed --upgrade pandas
    pip install --ignore-installed --upgrade sqlite
    pip install --ignore-installed --upgrade redis
    pip install --ignore-installed --upgrade scipy
    pip install --ignore-installed --upgrade gensim
    pip install --ignore-installed --upgrade opencv
    pip install --ignore-installed --upgrade pylint
    pip install --ignore-installed --upgrade bz2file
    pip install --ignore-installed --upgrade PyOpenGL 
    pip install --ignore-installed --upgrade ipykernel
    # pip install ... か  github を使うもの
    #  最初の conda ... は、下の pip でいれているものの前提ソフトウェア
    pip install --ignore-installed --upgrade termcolor astor wheel setuptools six protobuf werkzeug markdown absl-py grpcio gast future six click cligj click-plugins munch fiona python-dateutil pytz pyproj shapely 
    pip install git+https://github.com/msgpack/msgpack-python
    pip install git+https://github.com/davisking/dlib
    pip install git+https://github.com/ageitgey/face_recognition
    pip install git+https://github.com/jrosebr1/imutils
    
    pip install --ignore-installed --upgrade pyglet
    pip install --ignore-installed --upgrade pygame
    pip install --ignore-installed --upgrade cocos2d
    pip install --ignore-installed --upgrade geopandas
    pip install git+https://github.com/DinoTools/python-overpy
    pip install pyproj rtree shapely fiona gdal geopandas
    pip install --ignore-installed --upgrade exifread
    pip install --ignore-installed --upgrade haversine
    pip install --ignore-installed --upgrade utm
    # pip install --ignore-installed --upgrade gdal
    #again
    pip install --ignore-installed --upgrade conda
    

    ※ 「Proceed ([y]/n)?」と表示されたら, y + Enter で続行する.「反応が遅いなあ」と思ったら、Enterキーを押してみる.