python - 如何在 mac 上为 2.7 设置 python 路径?

标签 python macos python-2.7 add pythonpath

我知道,这个问题已被多次询问和回答。但是,我仍然无法摆脱这个。我在我的 mac 上发现了以下信息。

cd /Library/Frameworks/Python.framework/Versions/
Current -> 2.7
3.6

whereispython
/usr/bin/python

which python
/usr/bin/python

which -a python
/usr/bin/python
/usr/bin/python

python
Python 2.7.10 (default) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

尽管如此,当我如下编辑 ~/.bash_profile

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

#PYTHONPATH
PYTHONPATH="${PYTHONPATH}:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python"
export PYTHONPATH

然后,source ~/.bash-profile。重新启动我的 mac 和终端后,在执行 which python 时,仍然可以看到 /usr/bin/python 而不是指向 /Library/../Python2.7

我卸载了 python 并重新安装了 “pip install python” 而且,我可以看到 python 安装在 /System/Library/Frameworks/Python.framework/Versions

2.6
2.7
2.5 -> 2.6
2.3 -> 2.6
Current -> 2.7

我不确定这里可能缺少什么。我如何在 mac 中设置/添加 python 路径?请帮助我理解并克服这一点。你能帮我一下吗?

引用 Adding python path to mac osx

最佳答案

通过 brew 安装。 brew 安装 python2 或 python3。 brew 自动设置 mac 中的 python 路径。

关于python - 如何在 mac 上为 2.7 设置 python 路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45649473/

相关文章:

python & smtplib : Is sending mail via gmail using oauth2 possible?

python - 将枚举成员序列化为 JSON

python - 使用双方括号?

objective-c - Cocoa中窗口的圆角渐变背景

python - Pillow 未安装在 Apple Silicon 上

objective-c - 为什么 fget 不工作?

python - 用于 self 迭代 : what's in the list?

Python:将打印引号、破折号等替换为对应的 ascii 字符

python-2.7 - 这个 MRJob 例子的解释

python-2.7 - 如何对 Azure Data Lake 或 Blob Store 寄予厚望