0

Hmmm I had an interesting issue and I don't understand why, but would love to.

→ python -V
Python 2.7.1

Let's check how my my program is starting

→ head -2 myprog.py
#!/usr/bin/env python2.7
# encoding: utf-8

Let's check what it returns

→ /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 so far so good. Let's try to execute the code.

→ 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

hmmm ok. lxml… there are plenty of other stackoverflow talking about this specific issue. BUT Weird because I have another script working perfectly with the same module. So I decided to look at the way I was using the other scripts, and I have seen that I was starting it directly.

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

Export html content from Zorglub

So when I'm using python for starting it, it doesn't work. When I use the program directly it is working. WHY? A python expert in the room?

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*

我们还没有到那里,但我至少有两个 python 2.7 副本

于 2013-08-07T18:55:32.827 回答