tags:

views:

743

answers:

3
+3  Q: 

python module dlls

Is there a way to make a python module load a dll in my application directory rather than the version that came with the python installation, without making changes to the python installation (which would then require I made an installer, and be careful I didn't break other apps for people by overwrting python modules and changing dll versions globaly...)?

Specifically I would like python to use my version of the sqlite3.dll, rather than the version that came with python (which is older and doesn't appear to have the fts3 module).

A: 

If your version of sqlite is in sys.path before the systems version it will use that. So you can either put it in the current directory or change the PYTHONPATH environment variable to do that.

André
I did put the dll in my apps dir, which should take prioity over the python install dir, but the sqlite3 module still uses the dll in the python install dir, rather than mine. Is there a seperate dll path or something?
Fire Lancer
Did you only put the dll into that dir or did you also add the python wrapper code into that? If not, try the latter.
André
+1  A: 

If you're talking about Python module DLLs, then simply modifying sys.path should be fine. However, if you're talking about DLLs linked against those DLLs; i.e. a libfoo.dll which a foo.pyd depends on, then you need to modify your PATH environment variable. I wrote about doing this for PyGTK a while ago, but in your case I think it should be as simple as:

import os
os.environ['PATH'] = 'my-app-dir' + ';' + os.environ['PATH']

That will insert my-app-dir at the head of your Windows path, which I believe also controls the load-order for DLLs.

Keep in mind that you will need to do this before loading the DLL in question, i.e., before importing anything interesting.

sqlite3 may be a bit of a special case, though, since it is distributed with Python; it's obviously kind of tricky to test this quickly, so I haven't checked sqlite3.dll specifically.

Glyph
still doesn't load the new dll...
Fire Lancer
+1  A: 

Ok it terns out python always loads the dll in the same directory as the pyd file, regardless of what the python and os paths are set to.

So I needed to copy the _sqlite3.pyd from python/v2.5/DLLS to my apps directory where the new sqlite3.dll is, making it load my new dll, rather than the one that comes with python (since the pyd files seem to follow the PYTHONPATH, even though the actaul dlls themselves dont).

Fire Lancer