0

I've been learning PyTorch for deep learning recently. Using anaconda I found some problems when I ran the program. For example, I encountered the following import error

"no module named kiwisolver"

when my program imported matplotlib. It is fixed, but such error is very frustrating. The program runs for a long time.

Is there any way to check whether all the required dependencies are installed?

SU3
  • 5,064
  • 3
  • 35
  • 66

1 Answers1

0

Depending on how your program is structured...

Many Python programs use the if __name__ == "__main__": idiom so that they don't immediately execute code. This lets you import the code without it immediately running.

For example, if you have my_py_torch.py, then if you run python to launch the Python interpreter in interactive mode, you can import your code:

import my_py_torch

Importing your code will process any imports, execute any top-level code, and define any functions and classes, but, as long as you use the if __name__ == "__main__": idiom, it won't actually run the (long-running) code. That's typically enough to let you know if you have major issues like syntax errors, bad imports, or missing dependencies.

Code can still circumvent this: you may have functions or methods that only import modules locally (when they're actually run), or code may wrap imports in try / except blocks to handle missing dependencies then later throw an error if the dependency is used. So it's not foolproof, but it can be a useful test.

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246