I’m developing a script written with Python 3.8.10 and that uses external libraries installed with pip (e.g. torch: torch · PyPI). I’m running that script in Windows 10. The problem is that importing those libraries is very slow the first time I run the script after restarting my PC.
Just a wild guess here, but it sounds like maybe the first time you run the script after a reboot, your anti-virus scans all the files involved and that’s why it’s so slow.
The timing difference could be the result of caching. It’s possible that the first time you import torch after a reboot, a lot of data are loaded from disk into a memory cache. During the second import, the data are already in memory and don’t need to be loaded from disk again. If you have a slow hard drive such as the type with a spinning platter, then that could at least partly explain the large difference in runtime.
I’m in the same situation as you, the first time I import some larger libraries such as pandas, sklearn, torch will be very slow, often tens of seconds. Have you solved it?