tags:

views:

41

answers:

2

So I changed $PATH to have Python2.5 work with Django back when it didn't support 2.6. Now I can't install much of anything through Python because I screwed up a lot of the internals. $PATH is now unnecessarily long because I didn't know what I was doing when I was adding to it. .profile doesn't contain any of the paths that I added using "export" in the terminal. I can't even install virtualenv. At this point, I feel as if I corrupted everything and would like to start from scratch without losing all of my data. I have everything backed up with Time Machine, but that will just keep the same settings that I had before anyways.

Is it completely hopeless now? Should I opt for a fresh OS reinstall using something other than Time Machine to back up all of my information? Or would this be an easy fix?

A: 

Why not just edit (with the text editor of your choice) the "dot files" that determine the settings of PATH in the environment? In your $HOME (probably /Users/youruserid) that includes (assuming your shell is the default one, bash) .bash_profile and .bashrc -- there's typically also a "system" one /etc/bashrc (no dot for this one;-). find ~ -type f -name '.*' -print0 | xargs -0 grep PATH tells you all the relevant files in your home directory and subtree that contain the string PATH (plus no doubt some more, such as history files and saved copies of old dotfiles) and can direct your editing. Be sure to log off and log on again to ensure that all relevant files are applied in order to test your changes.

Edit: to make this at all Python-relevant;-), here's a simple Python way to determine how to set the path so that exactly the same commands are executed in all cases as with the path setting you have now, but without wasteful duplication:

>>> x='''/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin'''
>>> s = set()
>>> l = list()
>>> for p in x.split(':'):
...   if p in s: continue
...   s.add(p)
...   l.append(p)
... 
>>> print ':'.join(l)
/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin
>>> 
Alex Martelli
Users home$ echo $PATH/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/X11R6/bin^That's my PATH variable. It's pretty messy, right?I'll try the find command that you showed me.
RaDeuX
Just tried the find command and it didn't give me anything back.
RaDeuX
There are many redundant paths in your "PATH" :) . Try removing them.
pyfunc
Try also `cd /etc` followed by `grep PATH *`. You really need to get your environment under control and removing duplicate entries will be a step in the right direction.
dash-tom-bang
@Radeux, the problem is finding out which configuration files are causing the mess -- can't fix them unless you know what they are. There was an obvious typo in the `find` as I had typed it (closed quote after the `-print0` rather than right after the `.*`!-), edited to fix it now, please try the sensible version now present;-).
Alex Martelli
BTW, also did a short Python interactive shell session to find out what your path "should" be (to execute exactly the same commands as today but without any duplication) -- editing to show it.
Alex Martelli
BTW, `/opt/local` directories are for MacPorts-installed packages, `/sw/` ones are for Fink-installed packages. If you are going to use a 3rd-party OS X package manager (and I recommend that you do!), pick one or the other, don't mix them. For various reasons, I'd recommend MacPorts. You can easily delete either one of them, if necessary.
Ned Deily
+1  A: 

If you are using mac osx. Then my suggestion is that you use macports. The solution to do that is here.

You can then select to activate appropriate version by using python_select.

After that you can use virtualenv. This does work for me very well.

pyfunc
Worked like a charm. I don't need virtualenv anymore. Thanks!
RaDeuX