Skip to content

Instantly share code, notes, and snippets.

@cbowers
Forked from donilan/centos_python_env_setup
Last active March 1, 2021 13:56
Show Gist options
  • Save cbowers/bdc67fe1d2417b138846 to your computer and use it in GitHub Desktop.
Save cbowers/bdc67fe1d2417b138846 to your computer and use it in GitHub Desktop.
Script for setting up Python virtual environment on Centos
#!/bin/bash
# Install stuff #
#################
# Install development tools and some misc. necessary packages
yum -y groupinstall "Development tools"
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel mysql-devel libxml2-devel libxslt-devel unixODBC-devel sqlite sqlite-devel -y
# Alias shasum to == sha1sum (will prevent some people's scripts from breaking)
echo 'alias shasum="sha1sum"' >> $HOME/.bashrc
# Install Python 2.7.4 (do NOT remove 2.6, by the way)
if [ ! -e ./Python-2.7.4 ]
then
wget --no-check-certificate http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tar.bz2
tar xf Python-2.7.4.tar.bz2
fi
if [ ! -e /usr/local/bin/python2.7 ]
then
( cd Python-2.7.4 && ./configure --prefix=/usr/local && make && make altinstall )
fi
# Install easy install
echo "[easy_install]" >> ~/.pydistutils.cfg
echo "index_url = http://pypi.douban.com/simple" >> ~/.pydistutils.cfg
mkdir ~/.pip
echo "[global]" >> ~/.pip/pip.conf
echo "index-url = http://pypi.douban.com/simple" >> ~/.pip/pip.conf
wget http://peak.telecommunity.com/dist/ez_setup.py
sed -i 's/pypi.python.org/pypi.douban.com/' ez_setup.py
python ez_setup.py && easy_install pip
# Install virtualenv and virtualenvwrapper
# Once you make your first virtualenv, you'll have 'pip' in there.
# I got bitten by trying to install a system-wide (i.e. Python 2.6) version of pip;
# it was clobbering my access to pip from within virtualenvs, and it was frustrating.
# So these commands will install virtualenv/virtualenvwrapper the old school way,
# just so you can make yourself a virtualenv, with pip, and then do everything Python-related
# that you need to do, from in there.
if [ ! -e virtualenv-1.9.1.tar.gz ]
then
wget --no-check-certificate http://pypi.douban.com/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz#md5=07e09df0adfca0b2d487e39a4bf2270a
tar -xvzf virtualenv-1.9.1.tar.gz
fi
( cd virtualenv-1.9.1 && python setup.py install )
if [ ! -e virtualenvwrapper-4.0 ]
then
wget --no-check-certificate http://pypi.douban.com/packages/source/v/virtualenvwrapper/virtualenvwrapper-4.0.tar.gz#md5=78df3b40735e959479d9de34e4b8ba15
tar -xvzf virtualenvwrapper-*
fi
( cd virtualenvwrapper-4.0 && python setup.py install )
# Running these commands direclty from the script using sudo results
# in setting up virtualenvwrapper on the root account. If this is not what you want,
# do the following commands by hand from a normal user account.
# echo 'export WORKON_HOME=~/Envs' >> $HOME/.bashrc # Change this directory if you don't like it
# source $HOME/.bashrc
# mkdir -p $WORKON_HOME
# echo 'source /usr/bin/virtualenvwrapper.sh' >> $HOME/.bashrc
# source $HOME/.bashrc
echo Almost done! Look at the end of the script for the few commands
echo that need to be run from the user account.
echo Then you will be able create a vitualenv using: mkvirtualenv foo --python=python2.7
echo and when you want to use that virtualenv, do : workon foo
# Extra stuff #
###############
@0978591217
Copy link

Cho

@0978591217
Copy link

Echo

@0978591217
Copy link

Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment