1

我的 Mac 上安装了 python 2.7.2。我使用 python-2.7.2-macosx10.6.dmg 安装我只有一个 python 实例。

当我在终端中输入查找 python 路径时,我得到了这个:

 python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> os.environ['PYTHONPATH'].split(os.pathsep)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'PYTHONPATH'

这是缺少的一件事,因此我可以安装 Mercurial。我以前使用过 Mercurial,我可能弄坏了一些东西。你知道如何解决这个问题吗?

4

2 回答 2

5

您需要修改 sys.path 数组。它从 Python 默认值和环境变量“PYTHONPATH”初始化: http: //docs.python.org/library/sys.html#sys.path

要将您的目录附加到活动路径:

import sys
sys.path.append("/path/to/your/dir")
于 2012-02-16T23:07:45.920 回答
1

这是另一个有用的提示:

查看您的 ~/.local 文件夹。~/.local/lib/ 下可能有一个 homebrew.pth(或 *.pth)文件,这可能会通过覆盖 python 路径而导致问题。

If unsetting $PYTHONPATH doesn't fix your issue, try removing the:

~/.local folder.

于 2017-09-23T02:03:40.883 回答