我在python2.7上运行自编译版本,--prefix = $ HOME,以免干扰python2.6的标准安装(在Ubuntu 10.04上)。 导入ssl模块时遇到一些问题,追踪问题,重新编译我的python2.7并进行测试:
$ ~/bin/python2.7 -c "import ssl"
看起来不错,再检查一下
$ python2.7 -c "import ssl"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/jab/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
嗯?这台机器上没有其他安装的python2.7
$ which python2.7
~/bin/python2.7
$ echo $PATH
/home/jab/bin:/usr/local/bin:/usr/bin:/bin:...
$ for dir in $(echo $PATH | tr ':' ' '); do ls $dir/python2.7 2>/dev/null; done
/home/jab/bin/python2.7
为了更加确定:
$ python2.7 -c "import sys; print sys.executable"
/home/jab/bin/python2.7
$ $(which python2.7) -c "import sys; print sys.executable"
/home/jab/bin/python2.7
上下文已经足够了。问题是:为什么这样做有效?
$(which python2.7) -c "import ssl"
当这不存在时?
$ python2.7 -c "import ssl"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/jab/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl