I have virtual environment setup for my project, where i run python 3.6 with openpyxl module installed inside virtual enviroment.
I wrote a simple test program and when i run it within VIsual Studio Code editor i get this error:
No module named 'openpyxl'
However if i run the program from the command prompt, inside virtual environment, it executes without any error. I have configured Visual Studio Code to use my virtual environment path with this line:
"python.pythonPath": "C:\\Users\\Nermin\\Desktop\\EA-Monthly-Report\\Scripts"
Why is Visual Studio Code complaining that the openpyxl module does not exist when that is not true?
'''Testing openpyxl modlue for python'''
from openpyxl import Workbook
def test_workbook():
'''
Testing openpyxl
'''
work_book = Workbook()
work_sheet = work_book.active
work_sheet.title = "EA Monthly Report"
work_sheet['A1'] = 'Test Data'
work_book.save('test.xlsx')
#Run program
test_workbook()
I found a solution to my problem. I will share and hope someone else might find this helpful with same issue that i was having.
The way i got it to work is to start Visual Studio Code from the activated virtual environment command prompt. After that i was able to execute the program within Visual Studio Code.
Visual Studio Code will configure its self for the virtual environment after you start it from active virtual environment.