LoginSignup
5
5

More than 5 years have passed since last update.

Macで複数バージョンのPythonを使用するための環境を構築する方法

Last updated at Posted at 2016-05-29
  • 自分の環境はHomebrewを導入しているので、今回はHomebrewを通してpyenvを入れます。
  • 基本的には、rbenvのインストール方法と全く一緒でした。

pyenv

インストール

  • brewでインストール

    $ brew install pyenv
    
  • 確認

    $ pyenv --help
    Usage: pyenv <command> [<args>]
    
    Some useful pyenv commands are:
       commands    List all available pyenv commands
       local       Set or show the local application-specific Python version
       global      Set or show the global Python version
       shell       Set or show the shell-specific Python version
       install     Install a Python version using python-build
       uninstall   Uninstall a specific Python version
       rehash      Rehash pyenv shims (run this after installing executables)
       version     Show the current Python version and its origin
       versions    List all Python versions available to pyenv
       which       Display the full path to an executable
       whence      List all Python versions that contain the given executable
    
    See `pyenv help <command>' for information on a specific command.
    For full documentation, see: https://github.com/yyuu/pyenv#readme
    
    $ brew info pyenv
    pyenv: stable 20160509, HEAD
    Python version management
    https://github.com/yyuu/pyenv
    /usr/local/Cellar/pyenv/20160509 (489 files, 2.1M) *
      Built from source on 2016-06-02 at 10:49:26
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/pyenv.rb
    ==> Dependencies
    Recommended: autoconf ✔, pkg-config ✔, openssl ✔, readline ✔
    ==> Options
    --without-autoconf
        Build without autoconf support
    --without-openssl
        Build without openssl support
    --without-pkg-config
        Build without pkg-config support
    --without-readline
        Build without readline support
    --HEAD
        Install HEAD version
    ==> Caveats
    To use Homebrew's directories rather than ~/.pyenv add to your profile:
      export PYENV_ROOT=/usr/local/var/pyenv
    
    To enable shims and autocompletion add to your profile:
      if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
    

パス設定

  • パス通します。

    echo 'export PYENV_ROOT=/usr/local/var/pyenv' >> ~/.bash_profile
    echo 'eval "$(pyenv init -)"'                 >> ~/.bash_profile
    source ~/.bash_profile
    

python

インストール

  • インストール可能バージョンの確認

    $ pyenv install --list
    
  • インストール

    $ pyenv install 3.5.1
    
    Downloading Python-3.5.1.tgz...
    -> https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
    Installing Python-3.5.1...
    
    BUILD FAILED (OS X 10.11.5 using python-build 20151028)
    
    Inspect or clean up the working tree at /var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447
    Results logged to /var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447.log
    
    Last 10 log lines:
      File "/private/var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447/Python-3.5.1/Lib/ensurepip/__main__.py", line 4, in <module>
        ensurepip._main()
      File "/private/var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447/Python-3.5.1/Lib/ensurepip/__init__.py", line 209, in _main
        default_pip=args.default_pip,
      File "/private/var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447/Python-3.5.1/Lib/ensurepip/__init__.py", line 116, in bootstrap
        _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
      File "/private/var/folders/pq/m1yrrt652vg03wf5q66xk0m00000gn/T/python-build.20160529161005.9447/Python-3.5.1/Lib/ensurepip/__init__.py", line 40, in _run_pip
        import pip
    zipimport.ZipImportError: can't decompress data; zlib not available
    make: *** [install] Error 1
    
    • お。怒られた。。。

上記エラーで怒られた場合

  • xcodeのコマンドラインツールが入ってないと怒られるらしいので、インストール。

    $ xcode-select --install
    
    • GUIでインスト-ルの確認されるので、よしなに…。
  • 再実行

    $ pyenv install 3.5.1
    
    Downloading Python-3.5.1.tgz...
    -> https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz
    Installing Python-3.5.1...
    Installed Python-3.5.1 to /Users/LowSE01/.pyenv/versions/3.5.1
    
    • 今度はOK。

デフォルトバージョン指定

  • デフォルトで使用するバージョンを指定する

    $ pyenv global 3.5.1
    
  • 確認

    $ python --version
    Python 3.5.1
    
    • VersionがインストールしたものになっていればOK。

anaconda

インストール

  • インストール実行

    $ pyenv install anaconda3-4.0.0
    

デフォルトバージョン指定

  • デフォルトで使用するバージョンを指定する

    $ pyenv global anaconda3-4.0.0
    

IntelliJ + Python

プラグイン

  • 名前そのまま、「Python」ってプラグインがあったのでインストール。
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5