Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am upgrading python on an offline 64bit RHEL 6.4 box and am having to do it via RPM's rather than yum. I am trying to upgrade python from 2.4.3 to 2.6 so I can build nodejs from source.

I am running into trouble when I run

rpm -Uvh python26-2.6.8-2.el5.x86_64.rpm

I get a failed dependencies error:

libpython2.6.so.1.0() (64bit) is needed by python26-2.6.8-2.el5.x86_64

I can't find anyway to install libpython2.6 though...

share|improve this question

1 Answer 1

It's usually unwise to try to muck with the version of Python included on a system. These applications are there not so much for the users, but rather to support the applications that are bundled with the OS. Much of the internal plumbing of the distro depends on these specific Python packages.

If you have a need for specific versions of Python, Perl, Ruby etc. you should really get in the habit of using systems such as the following to setup your own local versions of these interpreters:

pyenv

This project used to be known as pythonbrew, but is now known as pyenv. To install it you need to clone a copy of it into your $HOME directory like so:

$ git clone git://github.com/yyuu/pyenv.git .pyenv
Cloning into .pyenv...
remote: Counting objects: 2207, done.
remote: Compressing objects: 100% (617/617), done.
remote: Total 2207 (delta 1489), reused 2172 (delta 1462)
Receiving objects: 100% (2207/2207), 358.75 KiB, done.
Resolving deltas: 100% (1489/1489), done.

Now add the setup of pyenv to your ~/.bashrc file:

$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> .bashrc
$ echo 'eval "$(pyenv init -)"' >> .bashrc

You can see the usage of pyenv:

$ pyenv 
pyenv 0.4.0-20130613-17-ge1ea64b
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using the python-build plugin
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/yyuu/pyenv#readme

You can see what versions are available:

$ pyenv versions
* system (set by /home/saml/.pyenv/version)

Now let's install Python 3.2.5:

$ pyenv install 3.2.5
Downloading Python-3.2.5.tgz...
-> http://yyuu.github.io/pythons/ed8d5529d2aebc36b53f4e0a0c9e6728
Installing Python-3.2.5...
Installed Python-3.2.5 to /home/saml/.pyenv/versions/3.2.5

Downloading setuptools-0.9.5.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-0.9.5.tar.gz
Installing setuptools-0.9.5...
Installed setuptools-0.9.5 to /home/saml/.pyenv/versions/3.2.5

Downloading pip-1.3.1.tar.gz...
-> http://yyuu.github.io/pythons/cbb27a191cebc58997c4da8513863153
Installing pip-1.3.1...
Installed pip-1.3.1 to /home/saml/.pyenv/versions/3.2.5

Rebuild our environment to incorporate new install:

$ pyenv rehash

Now we should see 2 versions available, system is still the default (*):

$ pyenv versions
* system (set by /home/saml/.pyenv/version)
  3.2.5

Let's switch to 3.2.5:

$ pyenv which python
/usr/bin/python

$ pyenv global 3.2.5

$ pyenv which python
/home/saml/.pyenv/versions/3.2.5/bin/python

$ pyenv versions
  system
* 3.2.5 (set by /home/saml/.pyenv/version)

virtualenv & virtualenvwrapper

These 2 Python modules provide you mechanisms for maintaining separate workspaces where site-packages can be maintained. They a good option if you want to isolate sets of Python modules into sets and associate them to a given Python application. They're a little awkward to use but do the job.

There's a screencast that shows how to use virtualenvwrapper as well. For Python I'd setup virtualenv first, followed by virtualenvwrapper.

Example

$ sudo easy_install virtualenv
$ easy_install virtualenvwrapper

At this point the 2 Python modules have been installed. From here you need to setup your environment, add the following to your $HOME/.bashrc file:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

Now re-source your .bashrc:

$ source ~/.bashrc

Now you're ready to list your work environments:

$ workon
$

You don't have any yet, so let's create one, we'll call it "temp":

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

Now when we re-list our worksets using workon:

(temp)$ workon
temp

Notice the prompt has changed so that the workspace is prefixed in front of your prompt. Now, to remove it:

(temp)$ rmvirtualenv temp
Removing temp...
ERROR: You cannot remove the active environment ('temp').
Either switch to another environment, or run 'deactivate'.

Can't so deactivate it, and your prompt is back to normal:

(temp)$ deactivate
$

Now try to remove it:

$ rmvirtualenv temp
Removing temp...

Now let's recreate it again, and cd to our workspace:

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

(temp)$ cdvirtualenv 
(temp)$ ls
bin  include  lib  lib64

Now check out the "temp" workspace site-packages:

$ cdsitepackages 
(temp)$ pwd
/home/saml/.virtualenvs/temp/lib/python2.7/site-packages

Now let's install a Python module, smooshy, first let's search for it using pip:

(temp)$ pip search smooshy
smooshy                   - Automatic lossless image compression

Now install it:

(temp)$ pip install smooshy
Downloading/unpacking smooshy
  Downloading smooshy-1.tar.gz
  Running setup.py egg_info for package smooshy

Requirement already satisfied (use --upgrade to upgrade): simplejson in /usr/lib64/python2.7/site-packages (from smooshy)
Installing collected packages: smooshy
  Running setup.py install for smooshy
    changing mode of build/scripts-2.7/smooshy from 664 to 775

    changing mode of /home/saml/.virtualenvs/temp/bin/smooshy to 775
Successfully installed smooshy
Cleaning up...

To confirm where it was installed:

(temp)$ which smooshy
~/.virtualenvs/temp/bin/smooshy
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.