TL;DR:如果我尝试从自制安装版本获取 python 2.7,这个 $PATH 字符串是否向后?
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin
我曾经brew install python
将 python 2.7.13 放在 El Capitan (OS X 10.11) 上,并且在一段时间内运行良好。然后我尝试部署一个 venv,结果出现了问题,我认为我的故障排除发现了一个更深层次的问题(或几个)。我的目标是除了 OS X 的 python 安装之外,还安装 Python 2.7.x 并使其正常运行。除了与brew安装的python 2.7一起安装的一些其他导入模块之外,我还瞄准了pip
和。 venv
(我知道弄乱系统原始的 Python 可能会导致很深很深的问题 - 所以我想完全不碰它。)
$ brew info python
python: stable 3.6.5 (bottled), devel 3.7.0b3, HEAD [pinned at 2.7.13]
Interpreted, interactive, object-oriented programming language
https://www.python.org/
/usr/local/Cellar/python/2.7.13 (6,337 files, 87.0MB) *
Built from source on 2017-02-01 at 19:23:01
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/python.rb
brew info python
显示 python 2.7.13 已安装并固定。伟大的。但是,如果是这样的话,为什么会which python
指向系统安装的版本呢?
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
检查 $PATH,看起来那里出了问题......
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin
所以我当前的 $PATH 是(为了清楚起见,<cr>
在后面:
):
- /Library/Frameworks/Python.framework/Versions/3.4/bin:
- /Library/Frameworks/Python.framework/Versions/2.7/bin:
- /usr/bin:
- /bin:
- /usr/sbin:
- /sbin:
- /usr/local/bin: -
/opt/X11/bin:
- /usr/local/git/bin
正确的 $PATH 顺序应该是
- /usr/local/bin:
- /Library/Frameworks/Python.framework/Versions/3.4/bin:
- /Library/Frameworks/Python.framework/Versions/2.7/bin:
- /usr/bin:
- /bin:
- /usr/sbin:
- /sbin:
- /opt/X11/bin:
- /usr/local/git/bin
根据这一页,我需要添加export PATH="/usr/local/bin:/usr/local/sbin:$PATH"
到 my .profile
,这给了我三个问题:
1. 我需要添加/usr/local/sbin
到我的 $PATH 吗?
2. 我认为我的 $PATH 会在重新启动后持续存在 - 我错了吗?
3.如果我需要添加到~/.profile
,可以改为添加到吗~/.bash_profile
?
最后,这是我现在看到的错误之一:
$ vim peuler.py
Traceback (most recent call last):
File "<string>", line 9, in <module>
File "/Users/user/.vim/bundle/powerline/powerline/__init__.py", line 6, in <module>
import logging
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 26, in <module>
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
ImportError: No module named time
An error occurred while importing powerline module.
This could be caused by invalid sys.path setting,
or by an incompatible Python version (powerline requires
Python 2.6, 2.7 or 3.2 and later to work). Please consult
the troubleshooting section in the documentation for
possible solutions.
Unable to import powerline, is it installed?
Press ENTER or type command to continue
对我来说,这表明系统安装的 Python 版本出现了严重问题 - 是这样吗? (没有名为 的模块time
?这不太好..)我可以删除所有自制程序安装的 Python,确保操作系统安装的 Python 版本是纯的,然后用自制程序重新安装所有内容吗?..还是系统级Python完全被劫持了?
答案1
我仍然不知道我的系统安装的 python 是否搞砸了,但是切换 PATH 解决了 vim 插件的问题。
正确的 $PATH 顺序是(再次,为了清楚起见,<cr>
在后面添加:
):
- /usr/local/bin:
- /usr/local/sbin:
- /Library/Frameworks/Python.framework/Versions/3.4/bin:
- /Library /Frameworks/Python.framework/Versions/2.7/bin:
- /usr/bin:
- /bin:
- /usr/sbin:
- /sbin:
- /opt/X11/bin:
- /usr/local/git/bin