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,333
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: 397
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,039
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,039
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
Posting Freak
Posts: 762
Joined: Feb 2009
Reputation: 16
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,039
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
Posting Freak
Posts: 762
Joined: Feb 2009
Reputation: 16
Post: #10
I think this is the easiest way to do it. http://trac.xbmc.org/ticket/7246
find quote
Dan Dare Offline
http://www.xbmc4xbox.org
Posts: 1,039
Joined: Sep 2004
Reputation: 146
Post: #11
I think that's already possible by adding libraries into XBMC\system\python\lib, that's what the readme.txt in there says:

Lib dir:
Library directory used by python.
Here can new packages or modules be installed by the user.

But still, who's going to maintain those libraries, build them and make sure they they work for each platform?
find quote
queeup Offline
Posting Freak
Posts: 762
Joined: Feb 2009
Reputation: 16
Post: #12
Yes I know that but if we need to install with SVN repo we need special://home/system/python for that. On special://xbmc/system/python users not have permission on Linux and Windows without admin account.
Quote:But still, who's going to maintain those libraries, build them and make sure they they work for each platform?
It's not a big deal. I have already lxml for all platforms and for python 2.4 I mean working with XBMC. Not to many libraries need it. Like i said. Most important libraries are Feedparser, BeautifulSoup and lxml (Its my opinion.) If we do it we don't need librarys in our plugins. Your and mine plugins have same Beautifulsoup library and we have total 10-12 same library installed on our harddisk.
find quote
Dan Dare Offline
http://www.xbmc4xbox.org
Posts: 1,039
Joined: Sep 2004
Reputation: 146
Post: #13
@queeup
I completely agree with you on that, but what happens if two plugins need two versions of the library? Smile I have a couple of plugins that don't work with the latest version of BeautifulSoup, I had to revert to using the previous one.

I agree though, it would be much easier if these libraries would be delivered with XBMC, or why not even your enhancement would work.
find quote
queeup Offline
Posting Freak
Posts: 762
Joined: Feb 2009
Reputation: 16
Post: #14
Yes I prefer BeautifulSoup 3.0.7a also.
Quote:but what happens if two plugins need two versions of the library?
If your plugin need it never version, you can always add in to your plugin folder and import from there. Am I wrong?
find quote
rwparris2 Offline
Team-XBMC Python Developer
Posts: 1,333
Joined: Jan 2008
Reputation: 2
Location: US
Post: #15
The current way of doing it is the safest.
10 copies of BeautifulSoup is less than 1mb...

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
Post Reply