You are here:


I can’t import any modules even though I am sure I installed them.

My script works when I run it from IDE, but fails when i run it from Terminal/Command Prompt.

The Issue Explained

Python allows multiple versions to be installed in parallel on the same computer.
It even allows the same version to be installed in different location/directories on the computer.

How does it know which python to run when you open terminal and run “python”?
How does the IDE know which version of python you want to execute your code on?
How does the package manager know which python are you installing packages to?

This depends on many things, and having one setting point to one python and another setting point to another can cause issues.

Solving this issue requires going over all possible settings relevant to your environment and making sure they match what you expect.
If any setting does not match, changing it is required.

The list below should be done step by step for every environment that is relevant to your setup.
For example if you are running Visual Studio Code on Linux, you need to go over Linux, Visual Studio Code topics below.

Gathering Information and Fixing

On Linux

  1. Shebang
  2. PATH
  3. which python, python -V
  4. if using pip: which pip, pip -V

On Windows

  1. PATH
  2. assoc, ftype
  3. where python, python -V
  4. if using pip: where pip, pip -V

Using Visual Studio Code

Using PyCharm

Using Conda

  1. conda info
  2. conda list