Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linux shell script to create/update a standalone virtualenv scipy-stack with symlinks to PyQt system install
#!/bin/bash
# source: https://gist.github.com/jlesquembre/2042882
libs=( PyQt4 PyQt5 sip.so )
python_version=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
var=( $(which -a $python_version) )
get_python_lib_cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
lib_virtualenv_path=$(python -c "$get_python_lib_cmd")
lib_system_path=$(${var[-1]} -c "$get_python_lib_cmd")
for lib in ${libs[@]}
do
echo "ln -s $lib_system_path/$lib $lib_virtualenv_path/$lib"
done
for lib in ${libs[@]}
do
ln -s $lib_system_path/$lib $lib_virtualenv_path/$lib
done
#!/bin/bash
# ONLY WORKS WITHIN A VIRTUALENV, otherwise you are messing with the system
# python installation. If not in a virtualenv, create a new one!
cmd="from distutils.sysconfig import get_python_lib; print (get_python_lib()[:4])"
python_lib_root=`python -c "$cmd"`
sys_lib_root="/usr"
if [ "$python_lib_root" = "$sys_lib_root" ] ; then
# we need two arguments: the python version and the new virtualenv name
if [ $# -eq 2 ] ; then
# use the virtualenv wrapper (workon, mkvirtualenv, etc)
export WORKON_HOME=$HOME/Software/virtualenv/
source /usr/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
# make sure the environment doesn't already exist
if [ -d "$HOME/Software/virtualenv/$2" ]; then
echo " *** virtualenv $2 already exists, not recreating"
workon $2
else
echo " *** Creating a new virtualenv $2 with /usr/bin/$1"
mkvirtualenv -p /usr/bin/$1 --no-site-packages $2
workon $2
fi
virtualenv_activated="yes"
else
echo " *** need 2 arguments: python version and new virtuelenv name"
exit 2
fi
else
virtualenv_activated="no"
echo " *** we are in a virtualenv already"
fi
# note that sip and pyqt4/5 can not be installed directly with pip. Instead,
# copy/symlink the lot from your system wide install...
cmd="try:
import PyQt4
print (0)
except: print (1)"
pyqt4=`python -c "$cmd"`
if [ $pyqt4 = 1 ]; then
echo ""
echo " *** PyQt4 not installed in virtualenv, assuming the same for sip, PyQt5"
echo " *** will create links to PyQt4, PyQt5 and sip from system install..."
# source: https://gist.github.com/jlesquembre/2042882
sh virtualenv-postmk-pyqt-sip
echo " *** done linking"
echo ""
fi
echo " *** installing/updating..."
pip install --upgrade pip wheel
# jdcal is a dependency of openpyxl
pip install --use-wheel --upgrade texttable pyparsing jedi jdcal
# when not installed --upgrade is just ignored
pip install --use-wheel --upgrade numpy scipy numexpr cython tables sympy h5py ipython
# additional dependencies for pandas, ezodf, and other excel related tools
# latest openpyxl (2.2) does not work with pandas??
pip install --use-wheel --upgrade xlrd xlwt xlsxwriter ezodf lxml pytz
pip install --use-wheel --upgrade pandas
# matplotlib seems to pull in dependencies by itself
pip install --use-wheel --upgrade matplotlib
# dependencies for spyder
pip install --use-wheel --upgrade six sphinx pyflakes pyzmq pylint psutil qtawesome
pip install --use-wheel --upgrade spyder
# figure out which version of python we are using
python_major=`python -c "import sys; print (str(sys.version_info[0]))"`
if [ $python_major = 2 ]; then
# for python2
pip install --use-wheel --upgrade rope
else
# for python3
pip install --use-wheel --upgrade rope_py3k
fi
echo " *** done installing/updating."
# using mkvirtualenv/workon in this fashion does make the activation persistant
if [ $virtualenv_activated = "yes" ] ; then
echo ""
echo " *** virtualenv $2 has been created or updated, but is not active."
echo " *** Use workon $2 to activate"
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.