Python modules

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Python modules

Jignesh Sutar
I've just installed v17 and am in the process of transfering python modules
from python24 to python2.5 folder.

Can I simply copy and paste C:\Python24\Lib\site-packages to
C:\Python25\Lib\site-packages ?

I'm worried about modules such as wxPython which are installed from a .exe
file, would they also be transferred correctly to python25 folder correctly
simply by a coping and pasting.

I'd like to keep my site-packages folder more organised under python25, can
I drop python modules within sub-folders under site-packages?

I read somewhere that python will only look into sub-folder in site-packages
folder if it contains a certain file ('__in_it__'??). I can't seem to find
this document now that I need it and was hoping somebody could please
clarify how this works.

Thanks
Jigs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Python modules

Peck, Jon
Don't just copy modules under site-packages.  In some cases, you need a different version compiled for 2.5 rather than 2.4.  And something that got there by an install will probably need another install.  And, especially, you don't want to overwrite the spss*, spssaux, or spssdata directories.  There are new versions of all of those directories.  But simple .py files can often be copied as they would have no installer.

Python has a number of ways of finding imported modules.   It will search along a search path, and you can modify this path.  (Do import sys; print sys.path to see where it is looking).  In version 17, the extensions subdirectory of your SPSS Statistics installation directory is automatically added to the Python search path when you start SPSS, which is convenient for Python modules specific to SPSS, especially extension commands.

If a module is found on the search path, the import succeeds.  I always keep a few particular extra directories on that path.  The easiest way to do that is to add these by modifying a normally empty file called
sitecustomize.py
that lives in your site-packages directory.  Mine looks like this:
import sys
sys.path.append("c:/python25/lib/site-packages/spssaux")
sys.path.append("c:/python25/lib/site-packages/misc")
sys.path.append("c:/python25/lib/site-packages/temp")
It is automatically executed when Python starts.

A second strategy is to create a file called, say,
modulename.pth
on your search path (typically in site-packages) In that file you add a relative path.  (Look at spss.pth, for example).
Then when looking to resolve import modulename, it will look in the corresponding pth file for the name.

You can also put a zip file on your search path, and Python will look inside it.  If you do this, though, you may want to compile the contents, because for zip files, Python will discard any compile it has to do afterwards, so you compile it every time it is imported.

If you have a subdirectory with the name of a module, then Python will look in that subdirectory and execute __init__.py (or .pyc) if found.  There are some other nuances of this process that you can read about in the help under __init__ or in the description of the import statement.

And there are other things you can do as well, but this is probably more than enough.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of J Sutar
Sent: Thursday, November 27, 2008 10:58 AM
To: [hidden email]
Subject: [SPSSX-L] Python modules

I've just installed v17 and am in the process of transfering python modules
from python24 to python2.5 folder.

Can I simply copy and paste C:\Python24\Lib\site-packages to
C:\Python25\Lib\site-packages ?

I'm worried about modules such as wxPython which are installed from a .exe
file, would they also be transferred correctly to python25 folder correctly
simply by a coping and pasting.

I'd like to keep my site-packages folder more organised under python25, can
I drop python modules within sub-folders under site-packages?

I read somewhere that python will only look into sub-folder in site-packages
folder if it contains a certain file ('__in_it__'??). I can't seem to find
this document now that I need it and was hoping somebody could please
clarify how this works.

Thanks
Jigs

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD