Python Path

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

Python Path

Georg Maubach
Dear Listers,

we need to put a new module into the Python path. We tried the following
using
IDLE but the configuration was gone the next time we started IDLE:

>>>from sys import *
>>>sys.path.append("C:\\Programme\\Python243\\Lib\\site-packages\\EasyGu
i")

>>> sys.path
['C:\\Programme\\Python243\\Lib\\idlelib',
'C:\\WINDOWS\\system32\\python24.zip', 'C:\\Programme\\Python243',
'C:\\Programme\\Python243\\DLLs', 'C:\\Programme\\Python243\\lib',
'C:\\Programme\\Python243\\lib\\plat-win',
'C:\\Programme\\Python243\\lib\\lib-tk',
'C:\\Programme\\Python243\\lib\\site-packages',
'C:\\Programme\\Python243\\lib\\site-packages\\win32',
'C:\\Programme\\Python243\\lib\\site-packages\\win32\\lib',
'C:\\Programme\\Python243\\lib\\site-packages\\Pythonwin',
'C:\\Programme\\Python243\\lib\\site-packages\\wx-2.6-msw-ansi',
'C:\\Programme\\Python243\\Lib\\site-packages\\EasyGui']

What can we do to include new modules permanently into the Python path?

Best regards

Georg Maubach
Market Analyst
Reply | Threaded
Open this post in threaded view
|

Re: Python Path

Peck, Jon
There is an article with a pointer to details on this topic on SPSS Developer Central under How to Use Downloaded Python Modules, but here is a quick summary of the techniques available to extend the Python search path.

As you note, doing this dynamically as with the code below is transient, lasting only for that Python session.

You can create package-specific search extensions using pth files.  You would put a file named, say, fred.pth in a location on your search path.  Typically that would be in your site-packages directory.  The contents of that file would point to the directory where the fred module is kept.  Usually that would be a relative path.

To extend the search path itself so that the search would extend to other locations for all modules, there are two mechanisms.  What I do is to add code such as what you gave below to the file
sitecustomize.py
which you will find (empty) in your site-packages directory.
The contents of that file are executed each time you start Python.
Alternatively, you can create an environment variable named PYTHONPATH specifying the search path.  While environment variables work under Windows, Windows hides the creation of permanent ones rather deeply down in the Control Panel.

Another useful technique is to create a zip file containing your library of modules and add this specific file name and path to your search path.  Python will search the zip file as if it were a directory.

HTH
Jon Peck


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Georg Maubach
Sent: lunes, 21 de agosto de 2006 4:16
To: [hidden email]
Subject: [SPSSX-L] Python Path

Dear Listers,

we need to put a new module into the Python path. We tried the following
using
IDLE but the configuration was gone the next time we started IDLE:

>>>from sys import *
>>>sys.path.append("C:\\Programme\\Python243\\Lib\\site-packages\\EasyGu
i")

>>> sys.path
['C:\\Programme\\Python243\\Lib\\idlelib',
'C:\\WINDOWS\\system32\\python24.zip', 'C:\\Programme\\Python243',
'C:\\Programme\\Python243\\DLLs', 'C:\\Programme\\Python243\\lib',
'C:\\Programme\\Python243\\lib\\plat-win',
'C:\\Programme\\Python243\\lib\\lib-tk',
'C:\\Programme\\Python243\\lib\\site-packages',
'C:\\Programme\\Python243\\lib\\site-packages\\win32',
'C:\\Programme\\Python243\\lib\\site-packages\\win32\\lib',
'C:\\Programme\\Python243\\lib\\site-packages\\Pythonwin',
'C:\\Programme\\Python243\\lib\\site-packages\\wx-2.6-msw-ansi',
'C:\\Programme\\Python243\\Lib\\site-packages\\EasyGui']

What can we do to include new modules permanently into the Python path?

Best regards

Georg Maubach
Market Analyst