'Long import times for some modules in VS Code

When I run a Python script in VS Code, it delays execution by more than a second if, for example, Pandas or Numpy are part of the script's import statement.

If only libraries from the Python Standard Library are used in the imports, the script will start immediately.

A second doesn't sound like a lot, but it is to me because I've used Spyder so far, where the same script starts immediately without spending any noticeable time on imports. I was wondering if this is normal in VS Code or if there are configuration parameters to speed up import time.

Edit

A minimal example would be a script with content

import collections
import pandas

print("a string")

which in my opinion should only take a few milliseconds (not noticeable) for complete processing after clicking the "run" button. Without the pandas import, it actually does. I think this is an important aspect, because slow "import speeds" hinder the unit-testing workflow.



Solution 1:[1]

pandas invokes numpy, and both of those are very large packages with many C DLLs. It takes many seconds for them to load. Once the DLLs have been loaded into Windows file cache, it should load quicker until they age out. It's just a fact.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Roberts