Python configuration question when python scripts are executed using Appweb as web server.

IronyOfLife mydevforums at gmail.com
Mon Aug 10 10:48:31 EDT 2009


Hi Gabriel

Thanks for the detailed and useful reply.


On Aug 7, 1:37 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Thu, 06 Aug 2009 12:49:30 -0300, IronyOfLife <mydevfor... at gmail.com>  
> escribió:
>
>
>
>
>
> > On Aug 5, 4:18 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> >> En Tue, 04 Aug 2009 10:15:24 -0300, IronyOfLife <mydevfor... at gmail.com>
> >> escribió:
> >> > On Aug 3, 8:42 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> >> >> En Mon, 03 Aug 2009 11:04:07 -0300, IronyOfLife  
> >> <mydevfor... at gmail.com>  
> >> >> escribió:
>
> >> >> > I have installed python 2.6.2 in windows xp professional machine. I
> >> >> > have set the following environment variables -- PYTHONPATH. It  
> >> points
> >> >> > to following windows folders: python root folder, the lib folder  
> >> and
> >> >> > lib-tk folder.
>
> >> >> Why? Did you read it somewhere? Usually there is no need to set the  
> >> >> PYTHONPATH variable at all; remove it.
>
> >> > Setting PYTHONPATH environment variables is mentioned in Python docs.
>
> >> Could you provide a link please? Setting PYTHONPATH should not be
>
> > Here are couple of links that discusses setting PYTHONPATH environment
> > variable.
> >http://docs.python.org/using/windows.html
>
> Ouch, that document should be reworked and updated!
>
> >http://www.daimi.au.dk/~chili/PBI/pythonpath.html
>
> That's mostly obsolete for current versions. Since PEP370 [0] was  
> implemented, a per-user private directory is already in sys.path now, so  
> there is no need to play with PYTHONPATH.

Thanks for the clarification on PYTHONPATH.
>
> > I understand your concerns regarding setting of PYTHONPATH while
> > multiple versions of Python are installed on the same machine. My fix
> > however does not use PYTHONPATH. The GNUTLS wrapper module for PYTHON
> > loads the GNUTLS dll's and it was not able to find them. Using FileMon
> > (win tool) I found out the paths that are scanned and I copied the
> > dlls to one of such paths. I still do not like this fix. This is a
> > temporary solution.
>
> Note that this cannot be fixed from inside Python. When you import a  
> module, the interpreter scans the directories in ITS search path  
> (sys.path) looking for a matching module. Once the module is found:
> - if it is a Python file, it's executed
> - if it is an extension module (a .pyd file, in fact a .dll renamed) it's  
> loaded using LoadLibraryEx (a Windows function), and finally its  
> initialization routine is executed.
>
> For LoadLibrary to successfully load the module, all its external  
> references must be resolved. That is, Windows must locate and load all  
> other DLLs that this module depends on, using its own search strategy [1],  
> taking into account the PATH environment variable and many other places.
>
> It is at this stage that you get the error: when the gnutls wrapper  
> attempts to load the gnutls DLL. That search is done by Windows, not by  
> Python, and PYTHONPATH has nothing to do with it.
>
> Why different results in IIS and appweb? Note that there exist several  
> search strategies, they depend on the application home directory, the  
> location of the .exe, whether SetDllDirectory was called or not, whether  
> the application has a manifest or not, a .local file or not... Hard to  
> tell with so many variables.

This is fairly easy to explain. When I configured IIS to execute
python scripts, as per the documentation I pass two command line
arguments. Appweb works this way. It opens up a new command process
and in the function parameter for environment it sets only SYSTEMROOT.
It does not set the PATH variable (A BUG IN APPWEB which I have passed
on to them. They have not commented or provided any work around) for
Windows platform.

So while loading the gnutls client script is loaded, the following
path is searched
1. gnutls\library
2. C:\windows
3. C:\WIndows\system
4. C:\WIndows\system32
5. Folder where pyhton.exe is present.

And when I use IIS, the PATH variable is also set. So in this case all
the folders in the PATH are also searched and LoadLibrary is able to
successfully find the GNUTLS related Dlls without any issues.

You were mentioning about .local file or manifest file to specify the
path. I used the python's build command to build the wrapper. Is there
a way to mention in setup.py to generate the .manifest file? I wold
very much appreciate if you can help me with that.

I will also look for answers for how to modify setup.py to generate
manifest file or .local file etc..

>
> > Can you explain maybe with some sample how to set .pth files? Maybe
> > this will resolve my issue.
>
> Yes, but I don't think this will actually help with your issue.
>
> pth files are described here [2]. Suppose you want to add c:\foo\bar to  
> sys.path, then write a file whatever.pth containing this single line:
>
> c:\foo\bar
>
> and place it on c:\your_python_installation\lib\site-packages
> When the interpreter starts, it will find the .pth file, read it, and add  
> any directory it finds (that actually exists) to sys.path
>
> Note that another Python installation will use a diferent site-packages  
> directory and won't find this particular .pth file, so different Python  
> versions don't interfere.
>
> ---
>
> [0]http://python.org/dev/peps/pep-0370/
> [1]http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx
> [2]http://docs.python.org/library/site.html
>
> --
> Gabriel Genellina




More information about the Python-list mailing list