python module dlls

后端 未结 4 1243

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 pytho

4条回答
  •  感情败类
    2021-02-12 11:54

    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.pathsep + 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.

提交回复
热议问题