Skip to content

Instantly share code, notes, and snippets.

@ckandoth
Created November 29, 2016 22:12
Show Gist options
  • Save ckandoth/f25c7469f23e63e34bee346fcb10ec29 to your computer and use it in GitHub Desktop.
Save ckandoth/f25c7469f23e63e34bee346fcb10ec29 to your computer and use it in GitHub Desktop.
Download, install, and build Python 2.7.10 in a local folder
# Create a folder where you want to install different Pythons, and cd into it:
# Note that it doesn't need to be your home folder. Put it wherever you want to maintain such software:
export PYTHON_BASE="$HOME/python"
mkdir -p $PYTHON_BASE
cd $PYTHON_BASE
# Download source tarball into a subfolder named src, and untar:
curl --create-dirs -L -o src/Python-2.7.10.tgz https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
cd src
tar -zxf Python-2.7.10.tgz
# Configure, build, and install into a properly versioned subdirectory:
cd Python-2.7.10
./configure --prefix=$PYTHON_BASE/python-2.7.10 --enable-shared --enable-unicode=ucs4 LDFLAGS="-Wl,-rpath=$PYTHON_PREFIX/lib"
make
make install
# Make sure the latest setuptools and pip are installed:
$PYTHON_BASE/python-2.7.10/bin/python -m ensurepip
$PYTHON_BASE/python-2.7.10/bin/pip install --upgrade setuptools pip
# Install all the various packages we use here at MSKCC:
$PYTHON_BASE/python-2.7.10/bin/pip install --upgrade alabaster ansi argparse azure babel biopython drmaa filemagic fireworks fusepy ipython lockfile markerlib nose powerline-status pygments pyvcf sh snowballstemmer sphinx virtualenv wheel
$PYTHON_BASE/python-2.7.10/bin/pip install --upgrade pysam matplotlib pandas cython scipy
@Poikilos
Copy link

Poikilos commented Oct 17, 2024

./configure --enable-shared --prefix=/opt/python LDFLAGS=-Wl,-rpath=/opt/python/lib

Thanks, that clarifies it should be nested. But...if you want multiple versions of Python installed (which is already assumed by installing Python 2), putting a version in the path will make it more maintainable (So your programs can require that version, instead of using the wrong version on a different computer or after reinstall). In other words, if that directory structure works:

  • The original script which specifies the version can be fixed simply by setting export PYTHON_PREFIX=$PYTHON_BASE/python-2.7.10 after export PYTHON_BASE="$HOME/python", then:
    • ./configure --prefix=$PYTHON_PREFIX --enable-shared --enable-unicode=ucs4 LDFLAGS="-Wl,-rpath=$PYTHON_PREFIX/lib"
    • I'd even use $PYTHON_BASE/python-2.7 for PYTHON_PREFIX (and for -prefix) instead, so programs can find still find it after updating Python 2 (and there probably aren't API changes between subminor versions such as between 2.7.10 and 2.7.11. If you really need to distinguish between them, you could make $PYTHON_BASE/python2 a symlink to the one you want to use for your programs).

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