python-3.xvisual-studio-codecmdpython-module

Exception has occurred: ModuleNotFoundError No module named 'colorama'


Background: colorama is a module for python3 that allows you to type and print colored text and in different styles and with backgrounds for the text

Issue: I wanted to make my text output from my programs look beautiful and nice so I found out about colorama and then I installed it using pip on a windows 10 and then I opened up visual studio code and typed this in:

import colorama
from colorama import Fore, Back, Style
colorama.init()
print(Fore.RED + "hello world")

this is supposed to print "hello world" in the color red and that's when I got this error:

Exception has occurred: ModuleNotFoundError
No module named 'colorama'

Then I tried the exact same code on command prompt and guess what, IT WORKS JUST FINE!!! This is probably an issue with vscode but I just wanted to ask if there are any solutions to this. Thanks in advance for whoever helps me fix this issue!

P.S. Pylance reported this error through error lens (pylance is a python language server that adds extra features and commands to the default python and error lens is just a highlighter for errors or mistakes and error lens tells the issue before running the program)


Solution

  • I have found the answer myself, First I research other similar questions and then I found out about __init__.py, which allows you to make and use your own local modules and then I researched some more and then I realized that the Colorama package was installed through python3.8 but I was using python3.9 so I went into my files and took colorama out of the packages inside python3.8 and moved it to python3.9 and then all of a sudden it worked!! Sorry, if I wasted your time...