Installing Python modules


#1

Hello,

Is this possible? The same question was asked by someone on the Programming Forum but was never answered.

I want to use Element Tree (http://effbot.org/zone/element-index.htm). If possible I’ll install it, or upgrade to Python 2.5.

Thanks.


#2

You can’t install modules system-wide, but you can certainly install Python modules in a local directory. Then it’s a matter of setting up, Python’s search path to include that directory (eg, modify the PYTHONPATH environment variable, programmatically change sys.path).

Larry


#3

Thank you for the reply. After a disastrous attempt at upgrading to Python 2.5 I tried your suggestion. It works, but only after an unsuccessful installation attempt, and only for about a day. Here’s what I did:

  1. Downloaded elementtree-1.2.6-20050316.tar.gz to ~/extern

  2. In extern I did:
    tar -zxvf elementtree-1.2.6-20050316.tar.gz

  3. When I try to install the module there is a permissions problem:

python setup.py install
running install
running build
running build_py
creating build
creating build/lib
creating build/lib/elementtree
copying elementtree/ElementInclude.py -> build/lib/elementtree
copying elementtree/ElementPath.py -> build/lib/elementtree
copying elementtree/ElementTree.py -> build/lib/elementtree
copying elementtree/HTMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/SgmlopXMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/SimpleXMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/SimpleXMLWriter.py -> build/lib/elementtree
copying elementtree/TidyHTMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/TidyTools.py -> build/lib/elementtree
copying elementtree/XMLTreeBuilder.py -> build/lib/elementtree
copying elementtree/init.py -> build/lib/elementtree
running install_lib
creating /usr/lib/python2.3/site-packages/elementtree
error: could not create ‘/usr/lib/python2.3/site-packages/elementtree’: Permission denied

4.Testing on the command line:

import sys

sys.path = [’~/extern/elementtree-1.2.6-20050316/elementtree/’]

from elementtree import ElementTree

Like I said, I can access the module for about a day after a failed install. Not a long-term solution… Suggestions?


#4

By default, it’s going to install into a system-wide directory. You need to tell the install script to install into one of your directories. See this section of the Python manuals:

http://docs.python.org/inst/alt-install-windows.html

Larry


#5

I really appreciate the help, it’s still not working though…

I’ve tried:
python setup.py install --home=~
python setup.py install --home=~/domain_name_folder
python setup.py install --prefix=~

I’ve also tried:
/usr/bin/env python setup.py install --home=~
/usr/bin/env python setup.py install --prefix=~

The cgi in my domain folder starts with:
import sys
sys.path.append("~/lib/python/elementtree")

Still nothing though and really frustrating. I don’t see what I’m doing wrong, this seems straightforward.


#6

[quote]sys.path.append("~/lib/python/elementtree")

[/quote]

That probably won’t work because “~” is expanded by the shell. Also, you probably want the lib/python directory in sys.path rather than the elementtree directory. You can either hardwire in the the full path to your lib/python directory, or access the HOME environment variable using the os module: os.environ[‘HOME’] and use that to construct the path.

Larry


#7

Awesome that did it. Thank you very much!