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

dieter dieter at handshake.de
Mon Jul 30 01:15:41 EDT 2018

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:

 * Python silently ignores non existent directories in "sys.path"
 * "~" is not automatically expanded into the home directory.

This would suggest, remplace "~/.homeassistent/..." by
"/home/pyuser/.homeassistent/..." and try again.

More information about the Python-list mailing list