如何使python_select适用于'$> python'命令? [英] How to make python_select work for '$>python' command?

查看:89
本文介绍了如何使python_select适用于'$> python'命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在macports上安装了几个不同版本的python,苹果python 2.6也可以工作.现在,我需要运行一个程序,该程序需要python中的MySQLdb软件包支持,并且该软件包已安装到我由macports安装的python中.该程序告诉我没有安装MySQLdb,所以我猜这是适用于该程序的apple python.

I installed a couple of pythons in different versions with macports, and the apple python 2.6 is also working. Now I need to run a program which requires MySQLdb package support in python, and this package was installed to the python I installed by macports. The program tells me that there is no MySQLdb installed, so I guess it is the apple python working for that program.

我搜索了一些帮助,发现使用python_select在python之间进行切换.但是在命令之后

I searched for some help and found python_select for switching between pythons. However after the command

$>sudo python_select python25

告诉我,当我键入时,它为python选择了版本"python25"

told me that it selected the version "python25" for python, when I type

$>python

仍然是苹果python 2.6启动.

it is still apple python 2.6 that launches.

问题是,我该如何使python25(带有MySQLdb的那个)而不是苹果python能够运行该程序?

The question is that how can I make python25(the one with MySQLdb) work for the program rather than apple python?

另一个重要的事情,该程序不是.py文件,需要在运行之前进行编译.那我需要重新安装该程序吗?我的Mac OS版本是Snow Leopard 10.6.

Another important thing, the program is NOT a .py file and needs to be compiled before running. So do I need to re-install this program? My Mac OS version is Snow Leopard 10.6.

任何答案都值得赞赏.

推荐答案

默认情况下,MacPorts在/opt/local/bin中安装用户程序(或指向它们的链接). MacPorts select_python命令选择哪个python实例链接到/opt/local/bin/python.它对Apple在/usr/bin中安装的内容没有影响(也不应该),这是Apple提供的pythonpython2.x命令所在的位置.

By default, MacPorts installs user programs (or links to them) in /opt/local/bin. The MacPorts select_python command selects which python instance is linked to /opt/local/bin/python. It has no effect (nor should it) on what Apple installs in /usr/bin, which is where the Apple-supplied python and python2.x commands are.

要调用MacPorts python2.5,您需要确保在外壳$PATH/opt/local/bin/usr/bin之前(可以通过修改.bash_profile或其他外壳初始化脚本来做到这一点),或者可以只需使用绝对路径引用调用所需的python:

To invoke the MacPorts python2.5, you either need to ensure that /opt/local/bin precedes /usr/bin on your shell $PATH (you can do this by modifying your .bash_profile or other shell initialization script) or you can simply invoke the desired python with an absolute path reference:

$ /usr/bin/python your-program.py

使用Apple提供的默认python;

to use the Apple-supplied default python;

$ /opt/local/bin/python your-program.py

使用通过python_select选择的版本,或者:

to use the version selected with python_select, or:

$ /opt/local/bin/python2.5 your-program.py

以明确选择MacPorts 2.5之一.

to explicitly select the MacPorts 2.5 one.

要修改搜索路径以使用MacPort,请将此行添加到.bash_profile:

To modify your search PATH to use MacPorts, add this line to .bash_profile:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

这篇关于如何使python_select适用于'$> python'命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆