RunSnakeRun on Mac

2875 ワード

Pythonの性能分析を行うには、cProfileの出力結果を分析する必要があります.使いやすいグラフィック分析ツールがあれば、より直感的になります.gprof 2 dotとRunSnakeRunはこのような2つのツールです.gprof 2 dotのインストールは簡単で、graphvizがインストールされていることを確認すれば図を出すことができます.しかしRunSnakeRunはMacではそれほど走りにくいので、ここでぶつかった穴を記録します(brewやvirtualenvを全く使わないと簡単です).
環境:
  • macOS 10.13.6
  • pyenv 1.2.6 installed by brew
  • pyenv-virtualenv 1.1.3 installed by brew
  • python 2.7.15 installed by pyenv
  • wxPython 3.0.2.0_1 installed by brew
  • 仮想環境python_2.7 using python 2.7.15

  • 主な問題:
  • wxPythonには2つのバージョンがあり、1つはclassicバージョンと呼ばれ、SourceForgeに管理され、新しい4.xバージョンは新しく、pipで直接インストールできます.runSnakerun依存はclassicバージョン、Macでbrewでインストールされているバージョンはclassicバージョン、バージョン番号は3.0.2.0_1
  • wxPythonはbrewによってインストールされているため、仮想環境python_2.7にインストールされているRunSnakeRunはwxPythonにアクセスできません.wxPythonと仮想環境pythonを2.7リンクされている場合、次のエラーが表示されます.
  • ImportError: No module named wx
    
  • 仮想環境python_2.7インストールしたPythonはFramework buildのPythonではありません.GUIプログラムを起動できません.次のエラーを示します.これはシステムのPythonでRunSnakeRunを起動するとともにPYTHONHOMEを仮想環境のPython
  • に設定する必要がある.
    This program needs access to the screen.
    Please run with a Framework build of python, and only when you are
    logged in on the main display of your Mac.
    
  • はこのエラーを提示し続け、解決策は見つからなかったが、
  • の使用には影響しなかった.
    UserWarning: wxPython/wxWidgets release number mismatch
      warnings.warn("wxPython/wxWidgets release number mismatch")
    

    ソフトウェアのインストール
    pip install SquareMap RunSnakeRun
    brew install wxPython wxmac
    

    リンクwxPythonと仮想環境python_2.7
  • wxPythonインストールパス
  • を確認
    /usr/local/Cellar/wxpython/3.0.2.0_1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx
    
  • 仮想環境でpython_2.7の下にwxPythonへのソフトチェーンの設置経路
  • を構築する.
    cd ~/.pyenv/versions/2.7.15/envs/python_2.7/lib/python2.7/site-packages/
    ln -s /usr/local/Cellar/wxpython/3.0.2.0_1/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx wx
    

    システムPythonでrunsnakerunを起動する
    #!/bin/bash -ex
    
    WXPYTHON_APP="runsnakerun/runsnake.py"
    PYVER=2.7
    
    if [ -z "$VIRTUAL_ENV" ] ; then
        echo "You must activate your virtualenv: set '$VIRTUAL_ENV'"
        exit 1
    fi
    
    BREW_PYTHON_ROOT="$(brew --prefix)/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/$PYVER"
    
    PYTHON_BINARY="bin/python$PYVER"
    FRAMEWORK_PYTHON="$BREW_PYTHON_ROOT/$PYTHON_BINARY"
    
    VENV_SITE_PACKAGES="$VIRTUAL_ENV/lib/python$PYVER/site-packages"
    
    # Use the Framework Python to run the app
    export PYTHONHOME=$VIRTUAL_ENV
    exec "$FRAMEWORK_PYTHON" "$VENV_SITE_PACKAGES/$WXPYTHON_APP" $*
    

    参照先:
  • https://wiki.wxpython.org/wxPythonVirtualenvOnMac
  • https://www.georgevreilly.com/blog/2015/09/20/RunSnakeRun-WxPython-Brew-Virtualenv.html