0

うーん、興味深い問題がありました。理由はわかりませんが、ぜひ知りたいです。

→ 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.
>>> 

ここまではOK。コードを実行してみましょう。

→ 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

んーよしっ。lxml…この特定の問題について話している他のスタックオーバーフローがたくさんあります。しかし、同じモジュールで完全に動作する別のスクリプトがあるため、奇妙です。そこで、他のスクリプトの使用方法を調べることにしたところ、直接開始していたことがわかりました。

→ ~/myprog.py -h
usage: myprog.py [-h] -u USERNAME [-o ARCHIVEPATH] [-f FILE_FORMAT]

Export html content from Zorglub

そのため、Pythonを使用して起動すると機能しません。プログラムを直接使用すると、機能しています。なぜ?部屋に python の専門家?

4

1 に答える 1

0

だから@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
>>> 

それからもう一つ

→ /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
>>> 

ああ、さらに悪いことに… :) python3 は /usr/local/bin/ にあります

→ 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*

まだそこにはいませんが、少なくとも 2 つの Python 2.7 のコピーがあります。

于 2013-08-07T18:55:32.827 に答える