开发者

What's the best way to set up symbolic links to current installs, e.g python -> python2.6

What's the best way to set up symbolic links to current installs, e.g python -> python2.6?

I've just installed python2.6 through Macports at /opt/local/bin/python2.6, I'd now like to set up a symbolic link called python here /usr/local/bin/. I then want to be able to add this line at the beginning of my pythons scripts so it knows where to look: #!/usr/local/bin/python. But w开发者_运维百科hat happens when I upgrade python to python2.7 for example, do I just need to remember to go to my symbolic link and change it? I guess I'll remember because it likely won't work anymore? Is there a better way to do this?


By default, MacPorts deliberately and carefully installs everything into a separate directory space: /opt/local. This ensures it does not conflict with anything installed as part of OS X or third-parties. To ensure that MacPorts-installed executables are found first, the recommended solution is to modify your shell PATH to put /opt/local/bin before /usr/bin.

MacPorts also provides a special port package, python_select, to manage which python version is pointed to by the command python in /opt/local/bin.

sudo port install python_select
sudo python_select

Then, to make your scripts use your current preferred python, the traditional solution is to use the env program in the shebang line of your scripts.

#!/usr/bin/env python


Symlink the version you use most.

When you need another version, run it by specifying the version number, e.g.:

$ python2.5 dev_appserver.py myapp


Not sure about OSX, here is what I do on Ubuntu 9.04:

>which python
#/usr/bin/python

Just replace that file with a sym link to the version of Python you actually want to use:

>sudo ln -s /usr/bin/python2.6/python /usr/bin/python
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜