lxml,flat_名称空间,使用或不使用python启动程序

lxml,flat_名称空间,使用或不使用python启动程序,python,command-line-interface,lxml,Python,Command Line Interface,Lxml,嗯,我有一个有趣的问题,我不明白为什么,但我很乐意 → python -V Python 2.7.1 让我们检查一下我的程序是如何启动的 → head -2 myprog.py #!/usr/bin/env python2.7 # encoding: utf-8 让我们看看它返回了什么 → /usr/bin/env python2.7 Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) [GCC 4.2.1 (Based on Apple In

嗯,我有一个有趣的问题,我不明白为什么,但我很乐意

→ python -V
Python 2.7.1
让我们检查一下我的程序是如何启动的

→ head -2 myprog.py
#!/usr/bin/env python2.7
# encoding: utf-8
让我们看看它返回了什么

→ /usr/bin/env python2.7
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
好的,到目前为止还不错。让我们试着执行代码

→ python myprog.py -h
Traceback (most recent call last):
  File "/Users/foobar/myprog.py", line 16, in <module>
    from lxml.html import html5parser
  File "/Library/Python/2.7/site-packages/lxml/html/__init__.py", line 42, in <module>
    from lxml import etree
ImportError: dlopen(/Library/Python/2.7/site-packages/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
  Referenced from: /Library/Python/2.7/site-packages/lxml/etree.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/lxml/etree.so

因此,当我使用python启动它时,它不起作用。当我直接使用程序时,它正在工作为什么?房间里有一位python专家?

所以@torek你让我走对了路

→ ls -l /usr/bin/python*

-rwxr-xr-x 2 root 62 2011-08-15 21:09 /usr/bin/python*
-rwxr-xr-x 6 root  1 2011-08-15 21:09 /usr/bin/python-config*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.5-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5-config*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config*
-rwxr-xr-x 2 root 62 2011-08-15 21:09 /usr/bin/pythonw*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/pythonw2.5 -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/pythonw2.5*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6*
lrwxr-xr-x 1 root  1 2011-08-15 21:09 /usr/bin/pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7*
好吧,让我们试试

→ /usr/bin/python
我们得到了

Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:06) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Python/2.7/site-packages/lxml/etree.so, 2): Symbol not found: _htmlParseChunk
  Referenced from: /Library/Python/2.7/site-packages/lxml/etree.so
  Expected in: flat namespace
 in /Library/Python/2.7/site-packages/lxml/etree.so
>>> 
我们得到了

Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lmxl import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named lmxl
>>> 

Se我们还没有找到,但我有至少两个Python2.7的副本,我之前在python源代码中挖掘,发现了很多OSX的“如果定义”魔法,它使用解释器被调用的路径来为dlopen设置东西,特别是,是否将各种
/Library/Frameworks
东西放进去。看看
/usr/bin/python myprog.py-h
和/或
/usr/bin/python~/myprog.py-h
在这里是否有任何区别(我不知道它是否有区别)。它没有任何区别:)它失败了。好吧,只是为了检查一下。尝试
python2.7myprog.py-h
而不是
python myprog.py-h
。可能这是2.7.1的两个不同版本,其中一个不正常工作?:-)哦,我想我们越来越近了;)看看答案。谢谢
→ /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lmxl import etree
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named lmxl
>>> 
→ ls -l /usr/local/bin/python*
-rwxr-xr-x 1 root 2 2006-11-09 05:05 /usr/local/bin/python2.5-config*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3-32*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3-config*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3.3 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3.3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3-32*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3.3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3-config*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3.3m -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3m*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/python3.3m-config -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3m-config*
-rwxr-xr-x 1 root 1 2012-03-02 13:43 /usr/local/bin/pythonbrew_install*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/pythonw3 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/pythonw3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3-32*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/pythonw3.3 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3.3*
lrwxr-xr-x 1 root 1 2013-02-25 12:50 /usr/local/bin/pythonw3.3-32 -> ../../../Library/Frameworks/Python.framework/Versions/3.3/bin/pythonw3.3-32*