开发者

Changing $PATH in OS X to run most recent version of Python

开发者 https://www.devze.com 2023-01-14 12:31 出处:网络
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 u

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 any开发者_C百科ways.

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?


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

  • "no matching architecture in universal wrapper" problem in wxPython?
  • All you have to do is add "/opt/local/bin" in front of your path.

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.


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
>>> 
0

精彩评论

暂无评论...
验证码 换一张
取 消