Skip to content

Instantly share code, notes, and snippets.

@BigglesZX
Created January 14, 2012 10:49
Show Gist options
  • Select an option

  • Save BigglesZX/1610950 to your computer and use it in GitHub Desktop.

Select an option

Save BigglesZX/1610950 to your computer and use it in GitHub Desktop.

Revisions

  1. BigglesZX revised this gist Jan 15, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, and since I'm also likely to forget how I did it, I thought I'd detail the steps here. These instructions should work with any Dreamhost shared hosting user, but follow them at your own risk.

    The end result of this process is being able to run a current version of Python from your shared hosting user's shell. It requires compiling, installing and running Python from your home directory rather than the system bin directories.
    The end result of this process is being able to run a current version of Python from your shared hosting user's shell. It requires compiling, installing and running Python from your home directory rather than the system @bin@ directories.

    **1. Create a helpful working directory**
    I chose to install all Python-related stuff in a @python/@ directory under my user's home directory.
    @@ -81,11 +81,11 @@ pip 1.0.2 from /home/biggleszx/python/lib/python2.7/site-packages/pip-1.0.2-py2.
    **8. Final note: cron jobs**
    If you want to use Python from the shell, you're now all set. But if you want to run Python scripts from @cron@, note this: @cron@ doesn't know about your @$PATH@ preference for using the local Python binaries we created, so you will need to prefix your @cron@ jobs with a command to read your @~/.bash_profile@ or @~/.bashrc@ file. Here's what your original @cron@ job might have looked like:

    bc. 0 0 * * * cd /home/biggleszx/maintenance/maintenance.py 1>/dev/null 2>&1
    bc. 0 0 * * * cd /home/biggleszx/maintenance; python maintenance.py 1>/dev/null 2>&1

    And here's what it'll need to look like now:

    bc. 0 0 * * * source /home/biggleszx/.bashrc; cd /home/biggleszx/maintenance/maintenance.py 1>/dev/null 2>&1
    bc. 0 0 * * * source /home/biggleszx/.bashrc; cd /home/biggleszx/maintenance; python maintenance.py 1>/dev/null 2>&1

    Otherwise you'll find your @cron@ jobs run using the older system-wide Python binary. You can double-check which Python binary is being used by @cron@ by creating a new job to just run @python --version@, or similar, and inspect the output.

  2. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -87,6 +87,6 @@ And here's what it'll need to look like now:

    bc. 0 0 * * * source /home/biggleszx/.bashrc; cd /home/biggleszx/maintenance/maintenance.py 1>/dev/null 2>&1

    Otherwise you'll find your @cron@ jobs run using the older system-wide Python binary.
    Otherwise you'll find your @cron@ jobs run using the older system-wide Python binary. You can double-check which Python binary is being used by @cron@ by creating a new job to just run @python --version@, or similar, and inspect the output.

    **Fin.**
  3. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -55,7 +55,7 @@ This file is run whenever you log in to a bash shell. At the end of it, add this

    bc. export PATH=/home/biggleszx/python/bin:$PATH

    You may also wish to add this line to your @~/.bashrc@ file, which is used for non-login shells.
    You may also wish to add the same line to your @~/.bashrc@ file, which is used for non-login shells.

    Now we get our shell to read this file and update its configuration. You can either log out and log in again, or type:

  4. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -51,7 +51,7 @@ We need to add our new Python bin dir to our @$PATH@, the set of directories our

    bc. $ nano ~/.bash_profile

    This file is run whenever you log in to a bash shell. At the end of it, add this line, substituting the path to your own @python@ dir created earlier:
    This file is run whenever you log in to a bash shell. At the end of it, add this line, substituting the path to your own @python@ dir created earlier, being sure to preserve the @bin@ part at the end, since this is where the Python binaries actually reside:

    bc. export PATH=/home/biggleszx/python/bin:$PATH

  5. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,27 @@ Check your Python version again; it should be updated:
    bc. $ python --version
    Python 2.7.2

    Hurrah!
    Hurrah!

    **7. For bonus points: install easy_install and pip**
    If you're working with Python packages, you'll find it helpful to install @setuptools@ and @pip@.

    bc. $ cd ~/python
    $ wget http://peak.telecommunity.com/dist/ez_setup.py
    $ python ez_setup.py
    $ easy_install pip
    $ pip --version
    pip 1.0.2 from /home/biggleszx/python/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg (python 2.7)

    **8. Final note: cron jobs**
    If you want to use Python from the shell, you're now all set. But if you want to run Python scripts from @cron@, note this: @cron@ doesn't know about your @$PATH@ preference for using the local Python binaries we created, so you will need to prefix your @cron@ jobs with a command to read your @~/.bash_profile@ or @~/.bashrc@ file. Here's what your original @cron@ job might have looked like:

    bc. 0 0 * * * cd /home/biggleszx/maintenance/maintenance.py 1>/dev/null 2>&1

    And here's what it'll need to look like now:

    bc. 0 0 * * * source /home/biggleszx/.bashrc; cd /home/biggleszx/maintenance/maintenance.py 1>/dev/null 2>&1

    Otherwise you'll find your @cron@ jobs run using the older system-wide Python binary.

    **Fin.**
  6. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, I thought I'd detail the steps here.
    Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, and since I'm also likely to forget how I did it, I thought I'd detail the steps here. These instructions should work with any Dreamhost shared hosting user, but follow them at your own risk.

    The end result of this process is being able to run a current version of Python from your shared hosting user's shell. It requires compiling, installing and running Python from your home directory rather than the system bin directories.

    @@ -39,9 +39,31 @@ This might take a while. Once it's done:

    bc. $ make install

    This installs the compiled Python binaries.
    This completes the compilation and installs the compiled Python binaries.

    **6. Reconfigure your environment to use the newly created local Python binaries**
    If you check your Python version now, you should still see the older Dreamhost-supplied system version:

    bc. $ python --version
    Python 2.5.2

    We need to add our new Python bin dir to our @$PATH@, the set of directories our shell searches through when we type a command. At the moment, it is picking up the system-wide Python binary (the older version).

    bc. $ nano ~/.bash_profile

    This file is run whenever you log in to a bash shell. At the end of it, add this line, substituting the path to your own @python@ dir created earlier:

    bc. export PATH=/home/biggleszx/python/bin:$PATH

    You may also wish to add this line to your @~/.bashrc@ file, which is used for non-login shells.

    Now we get our shell to read this file and update its configuration. You can either log out and log in again, or type:

    bc. $ source ~/.bash_profile

    Check your Python version again; it should be updated:

    bc. $ python --version
    Python 2.7.2

    Hurrah!
  7. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 34 additions and 1 deletion.
    35 changes: 34 additions & 1 deletion Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -11,4 +11,37 @@ $ cd ~/python
    **2. Download an up-to-date version of the Python source**
    At the time of writing this was 2.7.2. You may wish to use a different version.

    bc. $ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
    bc. $ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
    $ tar -xzf Python-2.7.2.tgz
    $ cd Python-2.7.2

    **3. Establish the full path to your new Python working directory**
    When running the Python @configure@ script, we need to supply a prefix that tells the compiler to set everything up locally. We'll be running Python out of @~/python@ and we need to know full path to that directory.

    bc. $ pwd
    /home/biggleszx/python/Python-2.7.2

    Keep a mental note of this.

    **4. Run the Python configure script**
    We'll supply the path to our @python@ dir as established above, thus:

    bc. $ ./configure --prefix=/home/biggleszx/python

    This sets everything up to install locally. You will see lots of technical output, but hopefully everything will progress OK (the Dreamhost environment has just about everything we need to install Python). If your project requires certain special Python features, you may need to install additional dependencies.

    **5. make, make install**
    Once @./configure@ has run, we can perform the actual compilation.

    bc. $ make

    This might take a while. Once it's done:

    bc. $ make install

    This installs the compiled Python binaries.

    **6. Reconfigure your environment to use the newly created local Python binaries**
    If you check your Python version now, you should still see the older Dreamhost-supplied system version:

    bc. $ python --version
  8. BigglesZX revised this gist Jan 14, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -4,9 +4,11 @@ The end result of this process is being able to run a current version of Python

    **1. Create a helpful working directory**
    I chose to install all Python-related stuff in a @python/@ directory under my user's home directory.

    bc. $ mkdir ~/python
    $ cd ~/python

    **2. Download an up-to-date version of the Python source**
    At the time of writing this was 2.7.2. You may wish to use a different version.

    bc. $ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
  9. BigglesZX created this gist Jan 14, 2012.
    12 changes: 12 additions & 0 deletions Dreamhost.Python.installation.textile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, I thought I'd detail the steps here.

    The end result of this process is being able to run a current version of Python from your shared hosting user's shell. It requires compiling, installing and running Python from your home directory rather than the system bin directories.

    **1. Create a helpful working directory**
    I chose to install all Python-related stuff in a @python/@ directory under my user's home directory.
    bc. $ mkdir ~/python
    $ cd ~/python

    **2. Download an up-to-date version of the Python source**
    At the time of writing this was 2.7.2. You may wish to use a different version.
    bc. $ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz