def define_custom_scripts(tpl_rman, ibeis_rman, PY2, PY3):
    '\n    export THEANO_FLAGS="device=cpu,print_active_device=True,enable_initial_driver_test=True"\n    set THEANO_FLAGS=device=cpu,print_active_device=True,enable_initial_driver_test=True,print_test_value=True\n\n    python -c "import pydot; print(pydot.__file__)"\n    python -c "import pydot; print(pydot.__version__)"\n    python -c "import pydot; print(pydot.find_graphviz())"\n    DEVICE="cuda" python -c "import pygpu;pygpu.test()"\n    python -c "import theano; print(theano.__file__)"\n    # python -c "import pylearn2; print(pylearn2.__file__)"\n    python -c "import lasagne; print(lasagne.__file__)"\n    python -c "import ibeis_cnn; print(ibeis_cnn.__file__)"\n    python -c "import detecttools; print(detecttools.__file__)"\n\n    # http://stackoverflow.com/questions/18042919/how-to-install-pyqt5-on-a-new-virtualenv-and-work-on-an-idle\n    pip install vext.pyqt5\n    sudo apt-get install pyqt5-dev\n    sudo apt-get install python3-pyqt5\n    python\n    python -c "import sip; print(\'[test] Python can import sip\')"\n    python -c "import sip; print(\'sip.__file__=%r\' % (sip.__file__,))"\n    python -c "import sip; print(\'sip.SIP_VERSION=%r\' % (sip.SIP_VERSION,))"\n    python -c "import sip; print(\'sip.SIP_VERSION_STR=%r\' % (sip.SIP_VERSION_STR,))"\n\n    ln -s /usr/lib/python3/dist-packages/PyQt5/ /home/joncrall/venv3/lib/python3.4/site-packages/PyQt5\n    ln -s /usr/lib/python3/dist-packages/sip*.so /home/joncrall/venv3/lib/python3.4/site-packages/\n    ln -s /usr/lib/python3/dist-packages/sip*.py /home/joncrall/venv3/lib/python3.4/site-packages/\n    '
    import utool as ut
    major = str(sys.version_info.major)
    minor = str(sys.version_info.minor)
    majorminor = [major, minor]
    pyoff = ('2' if (sys.version_info.major == 3) else '3')
    pyon = majorminor[0]
    plat_spec = get_plat_specifier()
    build_dname = ('cmake_builds/build' + plat_spec)
    script_fmtdict = {'pyexe': sys.executable, 'pyversion': ('python' + '.'.join(majorminor)), 'pypkg_var': (('PYTHON' + pyon) + '_PACKAGES_PATH'), 'build_dname': build_dname, 'pyoff': pyoff, 'pyon': pyon, 'cv_pyon_var': ('BUILD_opencv_python' + pyon), 'cv_pyoff_var': ('BUILD_opencv_python' + pyoff), 'plat_spec': plat_spec, 'source_dpath': '../..', 'libext': ut.get_lib_ext()}
    if (os.environ.get('VIRTUAL_ENV', '') == ''):
        if sys.platform.startswith('darwin'):
            local_prefix = '/opt/local'
        else:
            local_prefix = '/usr/local'
    else:
        local_prefix = os.environ['VIRTUAL_ENV']
    opencv_dir = os.path.join(local_prefix, '/share/OpenCV')
    if (not os.path.exists(opencv_dir)):
        if (not ut.get_argflag('--opencv')):
            opencv_dir = ''
            print('OpenCV is not installed in the expected location: {}'.format(opencv_dir))
            print('Running this script with --opencv will build and install it there')
    python_bash_setup = ut.codeblock('\n        # STARTBLOCK bash\n\n        if [[ "$VIRTUAL_ENV" == ""  ]]; then\n            # The case where we are installying system-wide\n            # It is recommended that a virtual enviornment is used instead\n            export PYTHON_EXECUTABLE=$(which {pyversion})\n            if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n                # Mac system info\n                export LOCAL_PREFIX=/opt/local\n                export {pypkg_var}=$($PYTHON_EXECUTABLE -c "import site; print(site.getsitepackages()[0])")\n                export PYTHON_PACKAGES_PATH=${pypkg_var}\n                export _SUDO="sudo"\n            else\n                # Linux system info\n                export LOCAL_PREFIX=/usr/local\n                export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/dist-packages\n                export PYTHON_PACKAGES_PATH=${pypkg_var}\n                export _SUDO="sudo"\n            fi\n            # No windows support here\n        else\n            # The prefered case where we are in a virtual environment\n            export PYTHON_EXECUTABLE=$(which python)\n            # export LOCAL_PREFIX=$VIRTUAL_ENV/local\n            export LOCAL_PREFIX=$VIRTUAL_ENV\n            export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/site-packages\n            export PYTHON_PACKAGES_PATH=${pypkg_var}\n            export _SUDO=""\n        fi\n\n        echo "LOCAL_PREFIX = $LOCAL_PREFIX"\n        echo "{pypkg_var} = ${pypkg_var}"\n        # ENDBLOCK bash\n        ').format(**script_fmtdict)
    script_fmtdict['python_bash_setup'] = python_bash_setup
    ibeis_rman['pyflann'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n\n        cd {repo_dir}\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        cmake -G "Unix Makefiles" \\\n            -DCMAKE_BUILD_TYPE="Release" \\\n            -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \\\n            -DBUILD_EXAMPLES=Off \\\n            -DBUILD_TESTS=Off \\\n            -DBUILD_PYTHON_BINDINGS=On \\\n            -DBUILD_MATLAB_BINDINGS=Off \\\n            -DBUILD_CUDA_LIB=Off\\\n            -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX\\\n            {source_dpath}\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n\n        # ENDBLOCK bash\n        ').format(repo_dir=ibeis_rman['pyflann'].dpath, **script_fmtdict))
    ibeis_rman['pyflann'].add_script('install', ut.codeblock('\n        # STARTBLOCK bash\n        # The pyflann source lives here\n        cd {repo_dir}/src/python\n        # Need to run build to move the libs to the build directory\n        python setup.py build\n        # Use pip to editable install\n        pip install -e {repo_dir}/src/python\n\n        # Old way of doing it\n        # But the setup script is generated during build\n        # python {repo_dir}/build/src/python/setup.py develop\n\n        python -c "import pyflann; print(pyflann.__file__)" --verb-flann\n        python -c "import pyflann; print(pyflann)" --verb-flann\n        # ENDBLOCK bash\n        ').format(repo_dir=ibeis_rman['pyflann'].dpath))
    ibeis_rman['hesaff'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/hesaff\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=""\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            cmake -G "Unix Makefiles" \\\n                -DCMAKE_OSX_ARCHITECTURES=x86_64 \\\n                -DCMAKE_C_COMPILER=clang2 \\\n                -DCMAKE_CXX_COMPILER=clang2++ \\\n                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n                $OPENCV_ARGS \\\n                {source_dpath}\n        else\n            cmake -G "Unix Makefiles" \\\n                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n                $OPENCV_ARGS \\\n                {source_dpath}\n        fi\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            #make VERBOSE=1\n            cp -v libhesaff{libext} {source_dpath}/pyhesaff/libhesaff{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    ibeis_rman['pydarknet'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/pydarknet\n\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        if [[ "$(which nvcc)" == "" ]]; then\n            export CMAKE_CUDA=Off\n        else\n            export CMAKE_CUDA=On\n        fi\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=""\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        else\n            export CONFIG="-DCMAKE_BUILD_TYPE=\'Release\' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        fi\n        export CONFIG="$CONFIG -DCUDA=$CMAKE_CUDA"\n        echo "CONFIG = $CONFIG"\n\n        cmake $CONFIG -G \'Unix Makefiles\' {source_dpath}\n        #################################\n        echo \'Building with make\'\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS -w\n        #################################\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            echo \'Moving the shared library\'\n            # cp -v lib* ../pydarknet\n            cp -v lib*{libext} {source_dpath}/pydarknet\n            # cp -v libdarknet{libext} {source_dpath}/pydarknet/libdarknet{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    ibeis_rman['pyrf'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/pyrf\n\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=""\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        else\n            export CONFIG="-DCMAKE_BUILD_TYPE=\'Release\' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        fi\n        echo "CONFIG = $CONFIG"\n\n        cmake $CONFIG -G \'Unix Makefiles\' {source_dpath}\n        #################################\n        echo \'Building with make\'\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS -w\n        #################################\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            echo \'Moving the shared library\'\n            # cp -v lib* ../pyrf\n            cp -v lib*{libext} {source_dpath}/pyrf\n            # cp -v libpyrf{libext} {source_dpath}/pyrf/libpyrf{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    '\n    ./super_setup.py --dump-scripts\n    '
    tpl_rman['cv2'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        # Checkout opencv core\n        cd $CODE_DIR\n        # export REPO_DIR=$CODE_DIR/opencv\n        export REPO_DIR={repo_dpath}\n        # git clone https://github.com/Itseez/opencv.git\n        cd $REPO_DIR\n        # Checkout opencv extras\n        git clone https://github.com/Itseez/opencv_contrib.git\n        # cd opencv_contrib\n        # git pull\n        # cd ..\n        # git pull\n        mkdir -p $REPO_DIR/{build_dname}\n        cd $REPO_DIR/{build_dname}\n\n        cmake -G "Unix Makefiles" \\\n            -D WITH_OPENMP=ON \\\n            -D CMAKE_BUILD_TYPE=RELEASE \\\n            -D {cv_pyoff_var}=Off \\\n            -D {cv_pyon_var}=On \\\n            -D PYTHON_DEFAULT_EXECUTABLE="{pyexe}" \\\n            -D {pypkg_var}=${pypkg_var} \\\n            -D CMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n            -D OPENCV_EXTRA_MODULES_PATH=$REPO_DIR/opencv_contrib/modules \\\n            -D WITH_CUDA=Off \\\n            -D BUILD_opencv_dnn=Off \\\n            -D BUILD_opencv_dnn_modern=Off \\\n            -D WITH_VTK=Off \\\n            -D WITH_CUDA=Off \\\n            -D WITH_MATLAB=Off \\\n            $REPO_DIR\n            # -D WITH_OPENCL=Off \\\n            # -D BUILD_opencv_face=Off \\\n            # -D BUILD_opencv_objdetect=Off \\\n            # -D BUILD_opencv_video=Off \\\n            # -D BUILD_opencv_videoio=Off \\\n            # -D BUILD_opencv_videostab=Off \\\n            # -D BUILD_opencv_ximgproc=Off \\\n            # -D BUILD_opencv_xobjdetect=Off \\\n            # -D BUILD_opencv_xphoto=Off \\\n            # -D BUILD_opencv_datasets=Off \\\n            # -D CXX_FLAGS="-std=c++11" \\ %TODO\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n        # ENDBLOCK\n        ').format(repo_dpath=ut.unexpanduser(tpl_rman['cv2'].dpath), **script_fmtdict))
    tpl_rman['cv2'].add_script('install', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n\n        cd $CODE_DIR/opencv/{build_dname}\n\n        $_SUDO make install\n        # Hack because cv2 does not want to be installed for some reason\n        # cp lib/cv2.so $PYTHON_PACKAGES_PATH\n        # Seems to work now that local is removed from prefix\n        # cp -v lib/cv2.so $PYTHON_PACKAGES_PATH\n        # Test makesure things working\n        python -c "import numpy; print(numpy.__file__)"\n        python -c "import numpy; print(numpy.__version__)"\n        python -c "import cv2; print(cv2.__version__)"\n        python -c "import cv2; print(cv2.__file__)"\n        #python -c "import vtool"\n        # Check if we have contrib modules\n        python -c "import cv2; print(cv2.xfeatures2d)"\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    tpl_rman['libgpuarray'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n\n        # Ensure the repo was checked out\n        if [ ! -d {repo_dpath} ]; then\n            git clone https://github.com/Theano/libgpuarray.git {repo_dpath}\n        fi\n\n\n        {python_bash_setup}\n        cd {repo_dpath}\n\n        # need a specific version of libgpuarray\n        git checkout tags/v0.6.2 -b v0.6.2\n\n        mkdir -p {repo_dpath}/{build_dname}\n        cd {repo_dpath}/{build_dname}\n\n        # First build the C library\n        cmake {repo_dpath} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n        $_SUDO make install\n\n        # Now build the python libarary\n        cd {repo_dpath}\n        python setup.py build_ext -L $LOCAL_PREFIX/lib -I $LOCAL_PREFIX/include\n        python setup.py build\n        # python setup.py install\n        $_SUDO pip install -e {repo_dpath}\n\n        # DEVICE="<test device>" python -c "import pygpu;pygpu.test()"\n        # DEVICE="gpu0" python -c "import pygpu;pygpu.test()"\n        cd ~\n        $_SUDO pip install nose\n        DEVICE="cuda" python -c "import pygpu;pygpu.test()"\n\n        # pip uninstall pygpu\n        # ENDBLOCK\n        ').format(repo_dpath=ut.unexpanduser(tpl_rman['libgpuarray'].dpath), **script_fmtdict))
    if ut.in_virtual_env():
        try:
            fmtdict = {'sys_dist_packages': ut.get_global_dist_packages_dir(), 'venv_site_packages': ut.get_site_packages_dir(), 'pyqt': ('PyQt4' if PY2 else 'PyQt5'), 'debian-python-qt': ('python-qt4' if PY2 else 'qt5-default python3-pyqt5 debian-python-qt-svg'), 'pip-python-qt': ('python-qt4' if PY2 else 'python-qt5')}
            system_to_venv = ut.codeblock('\n                # STARTBLOCK bash\n                # Creates a symlink to the global PyQt in a virtual env\n                export GLOBAL_DIST_PACKAGES="{sys_dist_packages}"\n                export VENV_DIST_PACKAGES="{venv_site_packages}"\n                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then\n                    echo "have qt"\n                    ls $GLOBAL_DIST_PACKAGES/{pyqt}\n                    ls $VENV_DIST_PACKAGES/{pyqt}\n                else\n                    # Ensure PyQt is installed first (FIXME make this work for non-debian systems)\n                    sudo apt-get install {debian-python-qt}\n                    # pip install {pip-python-qt}\n                fi\n                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then\n                    # Install system pyqt packages to virtual envirment via symlink\n                    ln -s $GLOBAL_DIST_PACKAGES/{pyqt}/ $VENV_DIST_PACKAGES/{pyqt}\n                    ln -s $GLOBAL_DIST_PACKAGES/sip*.so $VENV_DIST_PACKAGES/\n                    ln -s $GLOBAL_DIST_PACKAGES/sip*.py $VENV_DIST_PACKAGES/\n                else\n                    echo "{pyqt} DOES NOT SEEM TO BE INSTALLED ON THE SYSTEM"\n                fi\n                echo "testing"\n                python -c "import {pyqt}; print({pyqt})"\n                # ENDBLOCK bash\n                ').format(**fmtdict)
            tpl_rman['PyQt'].add_script('system_to_venv', system_to_venv)
        except NotImplementedError:
            pass
export THEANO_FLAGS="device=cpu,print_active_device=True,enable_initial_driver_test=True"
set THEANO_FLAGS=device=cpu,print_active_device=True,enable_initial_driver_test=True,print_test_value=True

python -c "import pydot; print(pydot.__file__)"
python -c "import pydot; print(pydot.__version__)"
python -c "import pydot; print(pydot.find_graphviz())"
DEVICE="cuda" python -c "import pygpu;pygpu.test()"
python -c "import theano; print(theano.__file__)"
# python -c "import pylearn2; print(pylearn2.__file__)"
python -c "import lasagne; print(lasagne.__file__)"
python -c "import ibeis_cnn; print(ibeis_cnn.__file__)"
python -c "import detecttools; print(detecttools.__file__)"

# http://stackoverflow.com/questions/18042919/how-to-install-pyqt5-on-a-new-virtualenv-and-work-on-an-idle
pip install vext.pyqt5
sudo apt-get install pyqt5-dev
sudo apt-get install python3-pyqt5
python
python -c "import sip; print('[test] Python can import sip')"
python -c "import sip; print('sip.__file__=%r' % (sip.__file__,))"
python -c "import sip; print('sip.SIP_VERSION=%r' % (sip.SIP_VERSION,))"
python -c "import sip; print('sip.SIP_VERSION_STR=%r' % (sip.SIP_VERSION_STR,))"

ln -s /usr/lib/python3/dist-packages/PyQt5/ /home/joncrall/venv3/lib/python3.4/site-packages/PyQt5
ln -s /usr/lib/python3/dist-packages/sip*.so /home/joncrall/venv3/lib/python3.4/site-packages/
ln -s /usr/lib/python3/dist-packages/sip*.py /home/joncrall/venv3/lib/python3.4/site-packages/
def define_custom_scripts(tpl_rman, ibeis_rman, PY2, PY3):
    '\n    export THEANO_FLAGS="device=cpu,print_active_device=True,enable_initial_driver_test=True"\n    set THEANO_FLAGS=device=cpu,print_active_device=True,enable_initial_driver_test=True,print_test_value=True\n\n    python -c "import pydot; print(pydot.__file__)"\n    python -c "import pydot; print(pydot.__version__)"\n    python -c "import pydot; print(pydot.find_graphviz())"\n    DEVICE="cuda" python -c "import pygpu;pygpu.test()"\n    python -c "import theano; print(theano.__file__)"\n    # python -c "import pylearn2; print(pylearn2.__file__)"\n    python -c "import lasagne; print(lasagne.__file__)"\n    python -c "import ibeis_cnn; print(ibeis_cnn.__file__)"\n    python -c "import detecttools; print(detecttools.__file__)"\n\n    # http://stackoverflow.com/questions/18042919/how-to-install-pyqt5-on-a-new-virtualenv-and-work-on-an-idle\n    pip install vext.pyqt5\n    sudo apt-get install pyqt5-dev\n    sudo apt-get install python3-pyqt5\n    python\n    python -c "import sip; print(\'[test] Python can import sip\')"\n    python -c "import sip; print(\'sip.__file__=%r\' % (sip.__file__,))"\n    python -c "import sip; print(\'sip.SIP_VERSION=%r\' % (sip.SIP_VERSION,))"\n    python -c "import sip; print(\'sip.SIP_VERSION_STR=%r\' % (sip.SIP_VERSION_STR,))"\n\n    ln -s /usr/lib/python3/dist-packages/PyQt5/ /home/joncrall/venv3/lib/python3.4/site-packages/PyQt5\n    ln -s /usr/lib/python3/dist-packages/sip*.so /home/joncrall/venv3/lib/python3.4/site-packages/\n    ln -s /usr/lib/python3/dist-packages/sip*.py /home/joncrall/venv3/lib/python3.4/site-packages/\n    '
    import utool as ut
    major = str(sys.version_info.major)
    minor = str(sys.version_info.minor)
    majorminor = [major, minor]
    pyoff = ('2' if (sys.version_info.major == 3) else '3')
    pyon = majorminor[0]
    plat_spec = get_plat_specifier()
    build_dname = ('cmake_builds/build' + plat_spec)
    script_fmtdict = {'pyexe': sys.executable, 'pyversion': ('python' + '.'.join(majorminor)), 'pypkg_var': (('PYTHON' + pyon) + '_PACKAGES_PATH'), 'build_dname': build_dname, 'pyoff': pyoff, 'pyon': pyon, 'cv_pyon_var': ('BUILD_opencv_python' + pyon), 'cv_pyoff_var': ('BUILD_opencv_python' + pyoff), 'plat_spec': plat_spec, 'source_dpath': '../..', 'libext': ut.get_lib_ext()}
    if (os.environ.get('VIRTUAL_ENV', ) == ):
        if sys.platform.startswith('darwin'):
            local_prefix = '/opt/local'
        else:
            local_prefix = '/usr/local'
    else:
        local_prefix = os.environ['VIRTUAL_ENV']
    opencv_dir = os.path.join(local_prefix, '/share/OpenCV')
    if (not os.path.exists(opencv_dir)):
        if (not ut.get_argflag('--opencv')):
            opencv_dir = 
            print('OpenCV is not installed in the expected location: {}'.format(opencv_dir))
            print('Running this script with --opencv will build and install it there')
    python_bash_setup = ut.codeblock('\n        # STARTBLOCK bash\n\n        if [[ "$VIRTUAL_ENV" ==   ]]; then\n            # The case where we are installying system-wide\n            # It is recommended that a virtual enviornment is used instead\n            export PYTHON_EXECUTABLE=$(which {pyversion})\n            if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n                # Mac system info\n                export LOCAL_PREFIX=/opt/local\n                export {pypkg_var}=$($PYTHON_EXECUTABLE -c "import site; print(site.getsitepackages()[0])")\n                export PYTHON_PACKAGES_PATH=${pypkg_var}\n                export _SUDO="sudo"\n            else\n                # Linux system info\n                export LOCAL_PREFIX=/usr/local\n                export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/dist-packages\n                export PYTHON_PACKAGES_PATH=${pypkg_var}\n                export _SUDO="sudo"\n            fi\n            # No windows support here\n        else\n            # The prefered case where we are in a virtual environment\n            export PYTHON_EXECUTABLE=$(which python)\n            # export LOCAL_PREFIX=$VIRTUAL_ENV/local\n            export LOCAL_PREFIX=$VIRTUAL_ENV\n            export {pypkg_var}=$LOCAL_PREFIX/lib/{pyversion}/site-packages\n            export PYTHON_PACKAGES_PATH=${pypkg_var}\n            export _SUDO=\n        fi\n\n        echo "LOCAL_PREFIX = $LOCAL_PREFIX"\n        echo "{pypkg_var} = ${pypkg_var}"\n        # ENDBLOCK bash\n        ').format(**script_fmtdict)
    script_fmtdict['python_bash_setup'] = python_bash_setup
    ibeis_rman['pyflann'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n\n        cd {repo_dir}\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        cmake -G "Unix Makefiles" \\\n            -DCMAKE_BUILD_TYPE="Release" \\\n            -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \\\n            -DBUILD_EXAMPLES=Off \\\n            -DBUILD_TESTS=Off \\\n            -DBUILD_PYTHON_BINDINGS=On \\\n            -DBUILD_MATLAB_BINDINGS=Off \\\n            -DBUILD_CUDA_LIB=Off\\\n            -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX\\\n            {source_dpath}\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n\n        # ENDBLOCK bash\n        ').format(repo_dir=ibeis_rman['pyflann'].dpath, **script_fmtdict))
    ibeis_rman['pyflann'].add_script('install', ut.codeblock('\n        # STARTBLOCK bash\n        # The pyflann source lives here\n        cd {repo_dir}/src/python\n        # Need to run build to move the libs to the build directory\n        python setup.py build\n        # Use pip to editable install\n        pip install -e {repo_dir}/src/python\n\n        # Old way of doing it\n        # But the setup script is generated during build\n        # python {repo_dir}/build/src/python/setup.py develop\n\n        python -c "import pyflann; print(pyflann.__file__)" --verb-flann\n        python -c "import pyflann; print(pyflann)" --verb-flann\n        # ENDBLOCK bash\n        ').format(repo_dir=ibeis_rman['pyflann'].dpath))
    ibeis_rman['hesaff'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/hesaff\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            cmake -G "Unix Makefiles" \\\n                -DCMAKE_OSX_ARCHITECTURES=x86_64 \\\n                -DCMAKE_C_COMPILER=clang2 \\\n                -DCMAKE_CXX_COMPILER=clang2++ \\\n                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n                $OPENCV_ARGS \\\n                {source_dpath}\n        else\n            cmake -G "Unix Makefiles" \\\n                -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n                $OPENCV_ARGS \\\n                {source_dpath}\n        fi\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            #make VERBOSE=1\n            cp -v libhesaff{libext} {source_dpath}/pyhesaff/libhesaff{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    ibeis_rman['pydarknet'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/pydarknet\n\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        if [[ "$(which nvcc)" ==  ]]; then\n            export CMAKE_CUDA=Off\n        else\n            export CMAKE_CUDA=On\n        fi\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        else\n            export CONFIG="-DCMAKE_BUILD_TYPE=\'Release\' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        fi\n        export CONFIG="$CONFIG -DCUDA=$CMAKE_CUDA"\n        echo "CONFIG = $CONFIG"\n\n        cmake $CONFIG -G \'Unix Makefiles\' {source_dpath}\n        #################################\n        echo \'Building with make\'\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS -w\n        #################################\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            echo \'Moving the shared library\'\n            # cp -v lib* ../pydarknet\n            cp -v lib*{libext} {source_dpath}/pydarknet\n            # cp -v libdarknet{libext} {source_dpath}/pydarknet/libdarknet{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    ibeis_rman['pyrf'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        cd $CODE_DIR/pyrf\n\n        mkdir -p {build_dname}\n        cd {build_dname}\n\n        # only specify an explicit opencv directory if we know one exists\n        if [ -d "$LOCAL_PREFIX/share/OpenCV" ]; then\n            OPENCV_ARGS="-DOpenCV_DIR=$LOCAL_PREFIX/share/OpenCV"\n        else\n            OPENCV_ARGS=\n        fi\n\n        echo \'Configuring with cmake\'\n        if [[ \'$OSTYPE\' == \'darwin\'* ]]; then\n            export CONFIG="-DCMAKE_OSX_ARCHITECTURES=x86_64 -DCMAKE_C_COMPILER=clang2 -DCMAKE_CXX_COMPILER=clang2++ -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        else\n            export CONFIG="-DCMAKE_BUILD_TYPE=\'Release\' -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX $OPENCV_ARGS"\n        fi\n        echo "CONFIG = $CONFIG"\n\n        cmake $CONFIG -G \'Unix Makefiles\' {source_dpath}\n        #################################\n        echo \'Building with make\'\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS -w\n        #################################\n\n        export MAKE_EXITCODE=$?\n        echo "MAKE_EXITCODE=$MAKE_EXITCODE"\n\n        # Move the compiled library into the source folder\n        if [[ $MAKE_EXITCODE == 0 ]]; then\n            echo \'Moving the shared library\'\n            # cp -v lib* ../pyrf\n            cp -v lib*{libext} {source_dpath}/pyrf\n            # cp -v libpyrf{libext} {source_dpath}/pyrf/libpyrf{plat_spec}{libext}\n        fi\n\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    '\n    ./super_setup.py --dump-scripts\n    '
    tpl_rman['cv2'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n        # Checkout opencv core\n        cd $CODE_DIR\n        # export REPO_DIR=$CODE_DIR/opencv\n        export REPO_DIR={repo_dpath}\n        # git clone https://github.com/Itseez/opencv.git\n        cd $REPO_DIR\n        # Checkout opencv extras\n        git clone https://github.com/Itseez/opencv_contrib.git\n        # cd opencv_contrib\n        # git pull\n        # cd ..\n        # git pull\n        mkdir -p $REPO_DIR/{build_dname}\n        cd $REPO_DIR/{build_dname}\n\n        cmake -G "Unix Makefiles" \\\n            -D WITH_OPENMP=ON \\\n            -D CMAKE_BUILD_TYPE=RELEASE \\\n            -D {cv_pyoff_var}=Off \\\n            -D {cv_pyon_var}=On \\\n            -D PYTHON_DEFAULT_EXECUTABLE="{pyexe}" \\\n            -D {pypkg_var}=${pypkg_var} \\\n            -D CMAKE_INSTALL_PREFIX=$LOCAL_PREFIX \\\n            -D OPENCV_EXTRA_MODULES_PATH=$REPO_DIR/opencv_contrib/modules \\\n            -D WITH_CUDA=Off \\\n            -D BUILD_opencv_dnn=Off \\\n            -D BUILD_opencv_dnn_modern=Off \\\n            -D WITH_VTK=Off \\\n            -D WITH_CUDA=Off \\\n            -D WITH_MATLAB=Off \\\n            $REPO_DIR\n            # -D WITH_OPENCL=Off \\\n            # -D BUILD_opencv_face=Off \\\n            # -D BUILD_opencv_objdetect=Off \\\n            # -D BUILD_opencv_video=Off \\\n            # -D BUILD_opencv_videoio=Off \\\n            # -D BUILD_opencv_videostab=Off \\\n            # -D BUILD_opencv_ximgproc=Off \\\n            # -D BUILD_opencv_xobjdetect=Off \\\n            # -D BUILD_opencv_xphoto=Off \\\n            # -D BUILD_opencv_datasets=Off \\\n            # -D CXX_FLAGS="-std=c++11" \\ %TODO\n\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n        # ENDBLOCK\n        ').format(repo_dpath=ut.unexpanduser(tpl_rman['cv2'].dpath), **script_fmtdict))
    tpl_rman['cv2'].add_script('install', ut.codeblock('\n        # STARTBLOCK bash\n        {python_bash_setup}\n\n        cd $CODE_DIR/opencv/{build_dname}\n\n        $_SUDO make install\n        # Hack because cv2 does not want to be installed for some reason\n        # cp lib/cv2.so $PYTHON_PACKAGES_PATH\n        # Seems to work now that local is removed from prefix\n        # cp -v lib/cv2.so $PYTHON_PACKAGES_PATH\n        # Test makesure things working\n        python -c "import numpy; print(numpy.__file__)"\n        python -c "import numpy; print(numpy.__version__)"\n        python -c "import cv2; print(cv2.__version__)"\n        python -c "import cv2; print(cv2.__file__)"\n        #python -c "import vtool"\n        # Check if we have contrib modules\n        python -c "import cv2; print(cv2.xfeatures2d)"\n        # ENDBLOCK\n        ').format(**script_fmtdict))
    tpl_rman['libgpuarray'].add_script('build', ut.codeblock('\n        # STARTBLOCK bash\n\n        # Ensure the repo was checked out\n        if [ ! -d {repo_dpath} ]; then\n            git clone https://github.com/Theano/libgpuarray.git {repo_dpath}\n        fi\n\n\n        {python_bash_setup}\n        cd {repo_dpath}\n\n        # need a specific version of libgpuarray\n        git checkout tags/v0.6.2 -b v0.6.2\n\n        mkdir -p {repo_dpath}/{build_dname}\n        cd {repo_dpath}/{build_dname}\n\n        # First build the C library\n        cmake {repo_dpath} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$LOCAL_PREFIX\n        export NCPUS=$(grep -c ^processor /proc/cpuinfo)\n        make -j$NCPUS\n        $_SUDO make install\n\n        # Now build the python libarary\n        cd {repo_dpath}\n        python setup.py build_ext -L $LOCAL_PREFIX/lib -I $LOCAL_PREFIX/include\n        python setup.py build\n        # python setup.py install\n        $_SUDO pip install -e {repo_dpath}\n\n        # DEVICE="<test device>" python -c "import pygpu;pygpu.test()"\n        # DEVICE="gpu0" python -c "import pygpu;pygpu.test()"\n        cd ~\n        $_SUDO pip install nose\n        DEVICE="cuda" python -c "import pygpu;pygpu.test()"\n\n        # pip uninstall pygpu\n        # ENDBLOCK\n        ').format(repo_dpath=ut.unexpanduser(tpl_rman['libgpuarray'].dpath), **script_fmtdict))
    if ut.in_virtual_env():
        try:
            fmtdict = {'sys_dist_packages': ut.get_global_dist_packages_dir(), 'venv_site_packages': ut.get_site_packages_dir(), 'pyqt': ('PyQt4' if PY2 else 'PyQt5'), 'debian-python-qt': ('python-qt4' if PY2 else 'qt5-default python3-pyqt5 debian-python-qt-svg'), 'pip-python-qt': ('python-qt4' if PY2 else 'python-qt5')}
            system_to_venv = ut.codeblock('\n                # STARTBLOCK bash\n                # Creates a symlink to the global PyQt in a virtual env\n                export GLOBAL_DIST_PACKAGES="{sys_dist_packages}"\n                export VENV_DIST_PACKAGES="{venv_site_packages}"\n                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then\n                    echo "have qt"\n                    ls $GLOBAL_DIST_PACKAGES/{pyqt}\n                    ls $VENV_DIST_PACKAGES/{pyqt}\n                else\n                    # Ensure PyQt is installed first (FIXME make this work for non-debian systems)\n                    sudo apt-get install {debian-python-qt}\n                    # pip install {pip-python-qt}\n                fi\n                if [ -d $GLOBAL_DIST_PACKAGES/{pyqt} ]; then\n                    # Install system pyqt packages to virtual envirment via symlink\n                    ln -s $GLOBAL_DIST_PACKAGES/{pyqt}/ $VENV_DIST_PACKAGES/{pyqt}\n                    ln -s $GLOBAL_DIST_PACKAGES/sip*.so $VENV_DIST_PACKAGES/\n                    ln -s $GLOBAL_DIST_PACKAGES/sip*.py $VENV_DIST_PACKAGES/\n                else\n                    echo "{pyqt} DOES NOT SEEM TO BE INSTALLED ON THE SYSTEM"\n                fi\n                echo "testing"\n                python -c "import {pyqt}; print({pyqt})"\n                # ENDBLOCK bash\n                ').format(**fmtdict)
            tpl_rman['PyQt'].add_script('system_to_venv', system_to_venv)
        except NotImplementedError:
            pass