`import somemodule` does not check all paths in `sys.path`

Chris Angelico rosuav at gmail.com
Mon Jul 30 01:23:28 EDT 2018


On Mon, Jul 30, 2018 at 3:15 PM, dieter <dieter at handshake.de> wrote:
> stefand986 at gmail.com writes:
>> ...
>> The "story" is: In homeassistant (short HA) some modules are installed at runtime during first start ("bootstrapping"), and for some reason loading the modules fails directly after installing the modules. Subsequent starts work fine.
>>
>> The modules that are installed during bootstrapping are installed to `~/.homeassistant/deps/lib/python3.7/site-packages`. Installing the modules happens in a different thread than where the modules are imported. (However as far as I can tell the importing thread waits for the install to finish.)
>>
>> Now the interesting thing is that when I start HA in verbose mode, I can see that Python is trying not all of the paths that are in `sys.path` (in the following snippet I cut out some stuff for brevity. Link to the full log at the end). As one can see the `~/.homeassistant/deps/lib/python3.7/site-packages` location is not tried and hence the import fails:
>
> When I remember right:
>
>  * "~" is not automatically expanded into the home directory.

Yes, this would be correct. The expansion of ~ into your home
directory is actually a shell feature. You can use os.path.expanduser
to do the transformation manually, but it won't happen automatically.

Good catch.

ChrisA


More information about the Python-list mailing list