Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:25:11+00:00 2026-05-30T19:25:11+00:00

There’s Python 2.6 installed in the system. Now I want to use modules introduced

  • 0

There’s Python 2.6 installed in the system.

Now I want to use modules introduced in Python 2.7. Because I have no root privilege, I have built & installed 2.7 under my home directory ($HOME/local/)

I added the following to my $HOME/.bashrc:

export PATH=$HOME/local/bin:$PATH
export PYTHONPATH=$HOME/local/lib/python2.7:$PYTHONPATH

Now I encountered the two problems I want ask for workarounds.

1. Invoking Python 2.7

Newly installed Python 2.7 doesn’t find 2.6 modules in system’s library path (/usr/lib/python2.6/site-packages/).

Should I add it to PYTHONPATH manually? Is there any nicer solution?

2. Invoking Python 2.6

Python 2.6 complains at startup:

'import site' failed; use -v for traceback

I guess it’s trying to load 2.7 modules (in $HOME/local/lib/python2.7).
Is it possible to load only 2.6 modules when Python 2.6 is invoked?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:25:12+00:00Added an answer on May 30, 2026 at 7:25 pm

    1) Invoking python 2.7

    In short: don’t do this.
    There are reasons why the path is called ‘/usr/lib/python*2.6*/site-packages/’.

    One reason is, that in this directory typically the ‘compiled’ python files (.pyc) are stored. python 2.6 and python 2.7 .pyc files are not compatible:

    $ python2.7 /usr/lib/python2.6/sitecustomize.pyc
    RuntimeError: Bad magic number in .pyc file
    

    python will skip pyc files which it cannot understood, but you loose at least the benefits of precompiled files.

    Another reason is, that things might get mixed up:

    $ strace -f python2.7 /usr/lib/python2.6/sitecustomize.py
    ...
    stat("/etc/python2.6", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    stat("/etc/python2.6", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    stat("/etc/python2.6/apport_python_hook", 0x7fffa15601f0) = -1 ENOENT (No such file or directory)
    open("/etc/python2.6/apport_python_hook.so", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/python2.6/apport_python_hookmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/python2.6/apport_python_hook.py", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/etc/python2.6/apport_python_hook.pyc", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/python2.7/apport_python_hook", 0x7fffa15601f0) = -1 ENOENT (No such file or directory)
    open("/usr/lib/python2.7/apport_python_hook.so", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/python2.7/apport_python_hookmodule.so", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/python2.7/apport_python_hook.py", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/python2.7/apport_python_hook.pyc", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib/python2.7/plat-linux2/apport_python_hook", 0x7fffa15601f0) = -1 ENOENT (No such file or directory)
    ...
    

    I would in your case install the modules needed also for python 2.7 in the python2.7 directory.

    2) Invoking python 2.6

    You might want to have a look at the part of the man page where PYTHONHOME is described:

    PYTHONHOME: Change the location of the standard Python libraries. By default, the libraries are searched in ${prefix}/lib/python[version] and ${exec_prefix}/lib/python[version], where ${prefix} and ${exec_prefix} are installation-dependent directories, both defaulting to /usr/local

    You can store the python 2.7 specific files / modules in the appropriate directory in your local installation. Those files / modules will only be picked up when you run the specific version of python. In this case you must not set the PYTHONPATH (or PYTHONHOME).

    Note: this is exactly the way Debian (and maybe other distributions) manage different simultaneously installed versions of python.

    [Edit: Added section 1 after receiving a comment from niboshi.]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There seem to be many ways to define singletons in Python. Is there a
There are numerous Agile software development methods. Which ones have you used in practice
There are several types of objects in a system, and each has it's own
There is this strange situation I'm fighting on. I have 3 pages, les call
There are a lot of Jquery plugins and libraries. and sometimes I want to
I want use html5's new tag to play a wav file (currently only supported
There have been several questions on SO regarding getting Contacts numbers using the Contacts
There is a conversion process that is needed when migrating Visual Studio 2005 web
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.