0

I recently installed some software, which required python to operate. For some reason, it installed its own version of python, and modified the PYTHONPATH variable. Now, when I attempt to import a module such as numpy, all I get is

ImportError: No module named numpy

Currently, running echo $PYTHONPATH I get /home/astrolab/easyaccess/eups/1.2.30/python, which points to the usurping python installation. I get the same result from running sudo echo $PYTHONPATH. Checking the sys.path setting, I get

['', '/home/astrolab/easyaccess/eups/1.2.30/python', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python27.zip', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7/plat-linux2', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7/lib-tk', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7/lib-old', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7/lib-dynload', '/home/astrolab/.local/lib/python2.7/site-packages', '/home/astrolab/easyaccess/eups/packages/Linux64/python/2.7.6+2/lib/python2.7/site-packages']

however, if I run sudo python -c "import sys; print sys.path" I get

['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/astrolab/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7']

which is the correct path, and I can import numpy/matplotlib/etc as I normally would.

My question is: What is the best way of fixing my sys.path/PYTHONPATH environment variable? I thought about editing my .bashrc file and just manually exporting the paths from the sudo'd sys.path, but is that really the best way to fix this? It's also not clear to me if editing my $PYTHONPATH in this way will fix the sys.path difference.

edit: One thing I forgot to include is that I no longer need access to any part of the new python installation. Once I fix this problem I plan on removing the new installation + associated software.

1 Answer 1

0

Check your .rc files for the added PYTHONPATH env settings and comment them out - this should get you no PYTHONPATH env settings, meaning the defaults for your system (which you verified using your sudo cmd). Possibly correct PATH customisations for that sw package as well. You'll need to restart your sessions (or manually adjust the env vars for them).

If you still need to use the customisations for that sw package put them in a special file/script (maybe even wrap the sw invocation as well) - this way you can still customize the env to keep that sw happy, but you only do it if/when you need to run that sw.

2
  • That was something I looked at, but there's no added PYTHONPATH settings in the .bashrc file in my home directory (there were also none to begin with). Is there anywhere else this environment variable could be stored?
    – Nick
    Jun 1, 2015 at 18:13
  • I finally fixed the problem. It was similar to the solution you provided, but instead of just appending an export ... line in the .bashrc file, the software appended as source foo.sh line. I commented out the offending line and everything seems to be happy again.
    – Nick
    Jun 1, 2015 at 19:01

You must log in to answer this question.

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