开发者

Trouble using lxml from a .py file. It works with the interpreter

I have python.org v2.7 installed on my Snow Leopard. There's also a Apple 2.6 Python onboard. I pip installed lxml with the 'sudo pip install lxml' command. I made sure I was doing this from within the bin directory of my python.org 2.7 version.

When I give the command:

from lxml import etree

within the IDLE interpreter everything works as expected and I can go on an use all the lxml methods. However if I create a .py file with 开发者_如何学运维a single line:

from lxml import etree

and I try to run it (be it within IDLE RUN/F5 or via command line '$python testlxml.py') I get the error: ImportError: cannot import name etree

The same holds true if I try importing other lxml modules like 'from lxml import html', it will work wonders in the interpreter but it won't in a .py file. I googled around but could not find a solution to this specific issue. Anybody got a clue? Thanks!


Finally figured this out. There was a file named lxml.py in the PATH which wasn't the lxml module. Actually, I created that file when I started playing with the lxml tutorial a couple days ago and didn't pay attention to the filename match. I totally forgot about it. Dumb me.


Which interpreter are they running with?

Make sure the first line of your py file is

#!/full/path/to/python2.7
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜