3

I want to build Python 2.7.8 on my Ubuntu 12.04 machine, which has Python 2.7.3 as default distribution. I would like to "install" Python 2.7.8 but isolate it completely from Python 2.7.3 - meaning, I don't want to interfere at all with the distribution's default Python, including modules installed via apt-get or PIP.

I would like to do this from source, and I would like not to use virtualenv - I'd rather learn to do it the "hard" way before using more sophisticated tools.

A second related part to this question is, after I have installed Python 2.7.8, how can I have two different PIPs, the default installing Python modules to Python 2.7.3, and the alternative installing modules to Python 2.7.8?

Thanks.

2
  • 1
    The distinction that makes me think this isn't a duplicate is the second part of the question, which differs from the question cited by the additional requirement of total isolation from the installation (i.e. also modules). If I were talking about 3.0 vs 2.7.3 that would be one thing, but, for example, if I wanted to install 2.7.3, 2.7.5 and 2.7.8 I'm not sure I could with the method proposed. I am a newbie at this so I could be totally wrong...
    – jpf
    Sep 27, 2014 at 23:54
  • @bodhi.zazen edited to try to clarify distinction from possible duplicate
    – jpf
    Sep 28, 2014 at 0:26

2 Answers 2

2

First, to make sure I started with a clean slate, I took the following steps:

  • Uninstalled package xlwt (for testing), via sudo apt-get uninstall python-xlwt and pip uninstall xlwt
  • Uninstalled PIP via sudo apt-get uninstall python-pip
  • Made clean python source directory (~/src/Python2.7.8) via make clean
  • Made sure pip was not available via which pip (resulted in nothing)

To build Python 2.7.X and make sure PIP is configured for only that specific installation

  • (assuming already downloaded and decompressed into home directory, say ~/src/Python2.7.8)
  • Make two directories for --prefix and --exec-prefix configure options, say ~/bld/python2.7.8_ind and ~/bld/python2.7.8_dep
  • Go to source directory (e.g. ~/src/Python2.7.8) and type

    ./configure --prefix=/home/uname/bld/python2.7.8_ind --exec-prefix=/home/uname/bld/python2.7.8_dep
    
  • type make && make install

The binary python (or a symbolic link to the binary) for this installation is located in this example in /home/uname/bld/python2.7.8_dep/bin

This creates a (previously non-extant) directory bin in ~/bld/python2.7.8_ind and places the PIP executables there which will be used for this specific installation. The PIP packages are placed in ~/bld/python2.7.8_ind/lib/python2.7/site-packages (which was previously empty save a README file).

Now, to install the first package to this specific python installation,

I verified that the directory ~/bld/python2.7.8_ind/lib/python2.7/site-packages contains only packages added during PIP installation (pip, setuptools, easy_install)

  • type ~/bld/python2.7.8_dep/bin/pip install xlwt

Now, the directory ~/bld/python2.7.8_ind/lib/python2.7/site-packages contains a new package (xlwt).

Now when I type

~/bld/python2.7.8_dep/bin/python
>>> import xlwt

it works, and typing python and import xlwt produces an error (as expected). Also verify that path searched for packages by new python installation is correct with

~/bld/python2.7.8_dep/bin/python
>>> import site
>>> site.getsitepackages()

This whole process might have been obvious to non-newbies, but I'm a newbie so I've written it all out.

0

Install it into /usr/local

./configure --prefix=/usr/local
3
  • 1
    /usr/local/lib/python2.7/ contains dist-packages which has been modified by PIP with python 2.7.3 and site-packages which may have other modules in it intended to be used with 2.7.3. How can I make sure that python 2.7.8 has its own modules? In other words, /usr/local/lib/python2.7.8 would be ideal if I could make a second PIP installation work with it.
    – jpf
    Sep 27, 2014 at 23:45
  • @jpf tried setting PYTHONPATH?
    – muru
    Sep 28, 2014 at 4:21
  • @muru I haven't set PYTHONPATH but according to the documentation the default search path for the standard Python libraries is always appended to PYTHONPATH; i.e. PYTHONPATH augments the default search path - it doesn't completely isolate the two installations. PYTHONHOME might be more relevant to what I'm trying to do, but before I use PYTHONHOME I need to know how to install any number of additional python2.7 default libraries to a directory different from /usr/local/lib/python2.7 (via PIP) and /usr/lib/python2.7 (see docs.python.org/2/using/cmdline.html).
    – jpf
    Sep 28, 2014 at 11:55

Not the answer you're looking for? Browse other questions tagged .