How to install lxml.etree directly to web2py modules? - python

I have a working setup of lxml.etree working on my windows desktop.
Since I wanted to move this to my server, instead of installing lxml in sitepackages, I wanted to install it inside the modules directly, so this lxml version is specific to this applicaion/site.
I copied my lxml directory directly under modules on the linux server, and I got this error :
No module named etree
So it seems it understood there is an lxml, package but couldn't see etree inside it.
Any ideas ?
Also, I couldn't find exactly where I can download the binaries for ubuntu 9.10 on the site : http://lxml.de/installation.html#installation

You can't just copy the Windows version over to a Linux server; lxml uses C extensions which need to be compiled for the target platform.
The etree module is such a compiled extension, on Linux that'd be etree.so, while on Windows it would be a etree.dll file instead, for example.
For Ubuntu, look for python-lxml, or install the dependencies libxml2-dev, libxslt1-dev and python-dev, plus python-pip, then use sudo pip install lxml to install lxml on your server.

Related

ImportError: No module named lxml on Mac OSX 10.11

I just bought a new Mac Book Pro with OSX 10.11 El Capitan.
I'm running Google App Engine Launcher python for local dev, which is where I see this in the logs when it reaches import lxml.
"ImportError: No module named lxml"
I followed the instructions from the lxml website
sudo pip install lxml
Package installs but can't be seen on path by python. I updated my path in .bashrc and .bash_profile with:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/lib/python2.7/site-packages/:$PATH
Then found this article Installing lxml on Mac OSX (10.11) inside a virtualenv with pip
$ STATIC_DEPS=true pip install lxml
Again it installs but can't be found.
I even tried compiling from source and installing macports as it got it embedded, but still no luck.
I read the lxml team is frustrated with OSX and the mess with its outdated libraries and all.
UPDATE
In relation to the comments made, its not a app.yaml libraries declaration, and its unlikely an issue specific to GAE, as it seems more likely between python and oxs-elcapitan.
also I get this unusual message
The directory '/Users/[username]/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
I tried with sudo -H but that didn't resolve the paths either.
But it does suggest the changes in 10.11 might be part of the problem.
AppEngine uses it's own environment that reflects their server and does not see libraries that you've installed locally.
To see the package it should be located in the root of the project (where the app.yaml is located).
But there is also runtime provide libraries- read section "Using Runtime-Provided Libraries with the Local Development Server" at https://cloud.google.com/appengine/docs/python/tools/libraries27
Probably you would need to add to app.yaml:
libraries:
- name: lxml
version: "2.3.5"
STATIC_DEPS didn't work for me (looks like the relevant FTP sites were down?), but this did the trick:
C_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2:$C_INCLUDE_PATH pip install lxml

No module named 'lxml' Windows 8.1

Everyone's code online refers to sudo apt-get #whatever# but windows doesn't have that feature. I heard of something called Powershell but I opened it and have no idea what it is.
I just want to get a simple environment going and lxml so I could scrape from websites.
Go to the regular command prompt and try pip install lxml. If that doesn't work, remove and reinstall python. You'll get a list of check marks during installation, make sure you check pip and try pip install lxml again afterwards.
pip stands for pip installs packages, and it can install some useful python packages for you.
Try downloading the lxml package from here, then, on the command prompt, type in:
pip install path/to/lxml_package_file
For example, after downloading lxml‑3.5.0‑cp35‑none‑win_amd64.whl since I have Python 3.5 on a 64-bit Windows box, I type in the following commands:
cd path/to/lxml_file
pip install lxml‑3.5.0‑cp35‑none‑win_amd64.whl
Then it should install fine.
Other packages may be used instead:
import xml.etree.cElementTree as etree
import xml.etree.ElementTree as etree
import cElementTree as etree
import elementtree.ElementTree as etree
The lxml.etree Tutorial

Receiving 'ImportError: cannot import name etree' when using lxml in Python on Mac

I'm having difficulty properly installing lxml for Python on Mac. I have followed the instructions here, which after installation indicates that the installation is successful (however, there are some warnings. The full log of the install and warnings can be found here)
After running the install, I am trying to run Test.py in the lxml install directory to ensure that it's working correctly. I am immediately prompted with the error:
ImportError" cannot import name etree.
This error results from the line from lxml import etree.
I can't seem to figure out why it's failing here after a seemingly successful install. Please forgive my ignorance, as I don't typically program in Python and certainly never on a MAC (forced to do so at the moment).
For reference:
Python Version: 2.7.2
Mac OS X 10.8.2
Thanks in advance for all the help.
Sounds like you have another lxml in your path. Make sure you are referencing the right one, it should look something like this:
>>> import lxml
>>> lxml
<module 'lxml' from '/path/to/lib/python2.7/site-packages/lxml/__init__.pyc'>
I had the same problem as you.
My problem was that I named one of my Python files lxml.py.
You should always check if your Python file's name conflicts with a module.
Microsoft Server
Spyder IDE
Python 3.7 and Python 3.9
Documenting this as I couldn't find the solution ANYWHERE on Google/StackOverflow etc.
Regarding SharePlum, SharePoint Integration, issues with
import from lxml import etree
ImportError: cannot import name etree
I had the same issue while trying to use SharePlum with Spyder IDE.
I tried installing, uninstalling, and installing versions of the below with no success
pip install shareplum
pip install lxml
I had Python 3.9 installed and Spyder IDE (which I didn't know, also installs it's own version of Python 3.7 - as at 13 May 2021 Spyder version) .. [even though the Spyder IDE is set up to search all python package inventories (e.g. ../Python39/Lib/Site-Packages) for packages] there seems to be a Spyder issue with Python pulling packages from other paths.
Solution, I have uninstalled all Python and Spyder IDE installations.
I then ONLY installed Spyder IDE (which nests a python install within it's PATH. I then went into the PATH ".../Spyder/Python" where you can find all the familiar Python.exe and other familiar Python files. I had to use this install of Python to install Pip, and then I could "pip install -r requirements.txt" - which installs etree lxml and other goodies such as SharePlum etc.
This seemed to do the trick!
I had the same problem using PyCharm IDE v2021.2 with Python 3.8
What worked for me was in PyCharm,
go to Preferences -> Python Interpreter,
uninstall the lxml package,
close & restart PyCharm,
install the lxml package
Dunno why it worked, but it did.

Building lxml on Windows using MinGW

My Python application required lxml. When I tried installing lxml, it the a "vcvrsall.bat not found" error. After digging around on the interwebs, I found that I needed to install MinGW, add it to my PATH variable and modify the distutils.cfg to use this compiler. It worked to the point that it now tried to download the lxml sources and compile it but fails on an error that reads fatal error: libxml/xmlversion.h: No such file or directory. It seems that lxml in turn depends on the libxml C library. How can I install this C library into my MinGW environment so that I can continue building my lxml.
Thanks.
It seems that lxml in turn depends on the libxml C library.
lxml is a python wrapper for the libxml C library.
How can I install this C library into my MinGW environment so that I can continue building my lxml.
Try this tutorial: http://www.pokorra.de/coding/compile_libxml_mingw.html
For lxml, you have to include references to the libxml headers and also have to link against the binaries.
you can download Unofficial Windows Binaries at:
http://www.lfd.uci.edu/~gohlke/pythonlibs/
e.g. for python 2.7 32bit:
http://www.lfd.uci.edu/~gohlke/pythonlibs/3i67tivk/lxml-2.3.3.win32-py2.7.exe

How to install lxml into virtualenv from the local system?

There is lxml module installed on my system (debian package python-lxml, for python 2.6), also I'm using virtualenv based on python2.6, installed with flag --no-site-packages.
Is it possible to install lxml inside virtual environment without compilation using some standard tools (pip, easy_install etc) and already install lxml binary files from the base system?
P.S.
I can, of course, manually create symlinks/copy files but don't like this method.
You may create required symlinks automatically by bootstrap script.

Categories

Resources