OS X 上的“-bash: python2: command not found”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38343960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:53:55  来源:igfitidea点击:

"-bash: python2: command not found" on OS X

pythonbashmacos

提问by ForTheEvulz

I'm trying to use thisscript to import my iTunes library to another program.

我正在尝试使用脚本将我的 iTunes 库导入另一个程序。

At the step where I enter python2 export_to_quod_libet.py, I'm getting an error message that says that the python2command can't be found. I figured out through python -vthat I definitely have Python 2.7 installed, so I'm really confused about this.

在我输入的步骤中python2 export_to_quod_libet.py,我收到一条错误消息,指出python2无法找到该命令。我python -v发现我肯定安装了 Python 2.7,所以我真的很困惑。

I did find a similar questionbeing asked here, but the original poster was using Windows (whereas I'm using OS X El Capitan), so a lot of what was said at least didn't seemapplicable to my situation.

我确实发现这里有人问了一个类似的问题,但原始海报使用的是 Windows(而我使用的是 OS X El Capitan),所以至少所说的很多内容似乎不适用于我的情况。

Could someone tell me what I'm doing wrong, please?

有人能告诉我我做错了什么吗?

回答by Julian

Maybe you could try do define an alias. It seems that python2 is hardcoded somewhere in the script.

也许您可以尝试定义别名。似乎 python2 被硬编码在脚本的某个地方。

You could try (just an example):

你可以试试(只是一个例子):

alias python2="python2.7"

and then run the script -- hope that helps.

然后运行脚本——希望有帮助。

Kind regards, Julian

亲切的问候,朱利安

回答by diyprojects.io

I confirmed it works on macOS. I installed Python 2.7 and 3.5 using brew commands:

我确认它适用于 macOS。我使用 brew 命令安装了 Python 2.7 和 3.5:

brew update
brew install python
brew install python3