Use lxml-library in a plugin

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
kimx Offline
Junior Member
Posts: 33
Joined: Feb 2008
Reputation: 0
Post: #1
I have a python script running on a python installation with lxml. How could I import the lxml to use it in a xbmc plugin?

Thanks
find quote
kimx Offline
Junior Member
Posts: 33
Joined: Feb 2008
Reputation: 0
Post: #2
Please help me with this. I'm getting crazy...

Thanks
find quote
rwparris2 Offline
Team-XBMC Python Developer
Posts: 1,341
Joined: Jan 2008
Reputation: 2
Location: US
Post: #3
elementtree uses the same syntax and will be a billion times easier to distribute.

If you don't want to use elementtree... you'll have to distribute and install setuptools in your addon for all three, see http://pypi.python.org/pypi/setuptools for how to install in xbmc's python, then easy_install lxml to xbmc's python. It will also require users to already have libxslt & whatever other prerequisites lxml has installed.

Basically, use elementtree instead.

Always read the XBMC online-manual, FAQ and search and search the forum before posting.
For troubleshooting and bug reporting please read how to submit a proper bug report.

If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/
find quote
Temhil Offline
Skilled Python Coder
Posts: 395
Joined: Apr 2008
Reputation: 1
Location: Canada
Post: #4
Yes, same advice than rwparris2, give a try to ET, it is a very lib and you just need to provide it with your script. I gave you an example on how to use it on your previous post when you were asking which XML parser were available.

[Image: passionxbmc_signature.png]
_____________________________

Repositories Installer: select and install unofficial repositories / TAC.TV: watch videos on TAC.TV
Installer Passion-XBMC: Download and Install Add-ons (pre-Dharma only)

[Image: project_thin_badge.gif]
find quote
Dan Dare Offline
http://www.xbmc4xbox.org
Posts: 1,054
Joined: Sep 2004
Reputation: 146
Post: #5
@kimx
One solution is to include the package source as part as your plugin and then add the path with code like:

PHP Code:
LIB_DIR xbmc.translatePathos.path.joinos.getcwd(), 'resources''lib' ) )
sys.path.append (LIB_DIR

and then you can use an import statement.

See some of the plugins plugins in my signature, they include things like BeautifulSoup or simpljason. An alternative is to use xml.dom to parse XMLs, see XBMC Xbox Trac Changelog or XBMC Zone Installer.
find quote
kimx Offline
Junior Member
Posts: 33
Joined: Feb 2008
Reputation: 0
Post: #6
Thank you for the answers, but the problem is not how to import, but which files I need to import the lib. In my script I use the etree element from lxml. In a normal python install I use this statement to import it:
Code:
from lxml import etree
How could I get the same result in xbmc and which files are needed?
Thanks in advance
find quote
Dan Dare Offline
http://www.xbmc4xbox.org
Posts: 1,054
Joined: Sep 2004
Reputation: 146
Post: #7
You could download the source for lxml (http://pypi.python.org/pypi/lxml/) and pick the contents of the src folder, but somehow I have a feeling they won't work without compiling them for a particular platform... I would try to rewrite the logic you have using the other suggested alternatives...
find quote
queeup Offline
Fan
Posts: 734
Joined: Feb 2009
Reputation: 15
Post: #8
yes it wont work without compiling. It's depends Os and Python version also. For exmple if you use lxml with your XBMC plugin you should add lxml for all platforms separately (Linux,win32,Os X) and python version must be 2.4. This is huge for 1 plugin. Its approximately 6mb Smile

One more thing, for example you have windows and your python version 2.6 and you developing plugins in this computer. You need lxml for windows and python version for 2.6 but when you release plugin you need lxml for all platforms and for python 2.4.
find quote
Dan Dare Offline
http://www.xbmc4xbox.org
Posts: 1,054
Joined: Sep 2004
Reputation: 146
Post: #9
I'd say - it would make sense to create a Trac request to include the appropriate lxml with Python with XBMC, but given that XBMC Team is concentrated on other tasks now, I don't see that happening soon. While there are other libraries already available with XBMC Python (xml.dom) or out there that could to the same task, the only reason I would against re-writing away from lxml is what, convenience?!
find quote
queeup Offline
Fan
Posts: 734
Joined: Feb 2009
Reputation: 15
Post: #10
I think this is the easiest way to do it. http://trac.xbmc.org/ticket/7246
find quote
Post Reply