我已经使用pip(2.x)和pip-3.5成功安装了gnureadline。虽然在Python2.7中导入它可以很好地工作,但在Python 3.5中它会引发以下异常:
Python 3.5.1 (default, Jan 31 2016, 04:03:04)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import gnureadline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so, 2): Symbol not found: _PyInt_AsLong
Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
Expected in: flat namespace
in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gnureadline.so
奇怪的是python在Python2.7路径中查找包。
该平台是OSX 10.11.3。
答案 0 :(得分:1)
您必须检查PYTHONHOME env变量。
使用echo $PYTHONHOME
进行检查,它应指向3.5
版本,
如果不成立,请按以下命令修复
export PYTHONHOME=/full path to appropriate python libs/
答案 1 :(得分:1)
在检查了sys.path变量为BasicWolf之后,我发现2.7站点包是独立于我运行的python版本而包含的。这是因为我的.bashrc文件中覆盖了PYTHONPATH env变量:
export PYTHONPATH=~/Library/Python/2.7/lib/python/site-packages/