当我运行无法在 Python 解释器中重现的脚本时,我收到 ImportError。
$ head -6 bin/taglint
#!/usr/bin/env python
#
import re
from lsaf.lsaf import file_info, error, exit
$ taglint
Traceback (most recent call last):
File "/home/ernest/bin/taglint", line 5, in <module>
from lsaf.lsaf import file_info, error, exit
ImportError: No module named lsaf
但是,导入在解释器中工作正常:
$ /usr/bin/env python
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from lsaf.lsaf import file_info, error, exit
>>>
这里发生了什么?
附加信息:
Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import lsaf; print(lsaf)
<module 'lsaf' from '/home/ernest/lib/python/lsaf/__init__.pyc'>
PYTHONPATH 环境变量设置为 PYTHONPATH=/home/ernest/lib/python。