lxml cannot import element etree

一笑奈何 提交于 2020-01-24 09:11:10

问题


  1. I downloaded the source of lxml.
  2. then unpacked it
  3. typed "python setup.py install".

==> everything went fine.

but now typing :

import lxml

i get:

Traceback (most recent call last):
  File "lxml.py", line 1, in <module>
    from lxml import etree
  File "/Soft/fox_dev/dev/ut1u3h/dev/lxml.py", line 1, in <module>
    from lxml import etree
ImportError: cannot import name etree

Before you offer me any solution, I must tell you, our sys admins and network admins are control/Sercurity freaks.

  1. I am not root
  2. I cannot reach any url outside the company ( from the server on which i'm trying to install lxml on )

for example I tried to install pip:

>> python get-pip.py
Downloading/unpacking pip
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not find any downloads that satisfy the requirement pip
Cleaning up...
No distributions at all found for pip
Storing debug log for failure in /Home/ut1u3h/.pip/pip.log

I have a windows machine which can reach the web. Then I can transfer files from it to the linux server via sftp.

Any idea/solution ?

EDIT

ok I tried: http://lxml.de/build.html

first :

make inplace
python setup.py install

now if depending on the path on which I open the python interpreter, either it works or I get the above error. I've added the source too the pythonpath... but it does not chang anything !

EDIT2: solution

Please don't hurt me... the final solution: do not put a file named lxml.py in the directory from which you are trying to import lxml... rather name your test lxml_test.py !!!!


回答1:


probably you change the default python version python2.7 to other like python3.6, as we all known that some modules are different between the two versions, and some modules work bad with python3+, so you can reset your python version to 2.7

if you are using ubuntu, you can do as follows:

$ rm /usr/bin/python
$ ln -s /usr/bin/python2.7 /usr/bin/python


来源:https://stackoverflow.com/questions/21779155/lxml-cannot-import-element-etree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!