Why is the PATH changed when Windows PyQt5 is imported?
Phil Thompson
phil at riverbankcomputing.com
Sun Jan 3 22:05:23 GMT 2021
On 03/01/2021 15:06, Barry Scott wrote:
> I'm debugging an issue that is breaking some of my code.
> I'm using Python 3.8 and PyQt5==5.12.2
>
> What I'm seeing is that the PATH is changed by PyQt5 __init__.py.
>
> It has this code in it:
>
> ---
> import os as _os
>
> _path = _os.path.dirname(__file__) + '\\Qt\\bin;' + _os.environ['PATH']
> _os.environ['PATH'] = _path
> ---
>
> Why is this necessary?
>
> Its has the effect that any subprocess created from a PyQt5 program
> gets this PATH.
>
> And if a program that uses a different version of PyQt5 then the
> one the PATH has at its start sees DLL errors.
>
> Is this a because of the change in 3.8 for DLL loading?
> Should this code use the os.add_dll_directory instead?
>
> Why am I spotting this now? I've changed my build processes to use
> a venv. I have installed tools that use an older PyQt5 and then
> build the updated tools using the venv.
Current code updates PATH and uses add_dll_directory() if it is
available.
Phil
More information about the PyQt
mailing list