I have same python script. but when I run the python use "visual studio" vs "command prompt" the result is different (to be exact, I get error while use command prompt)
I found out that the error is happened due to the library is not found while run via command prompt. so here is my tracing.
# run in command prompt
E:\py>where python
# Result
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe
C:\Users\x\AppData\Local\Microsoft\WindowsApps\python.exe
run this file python code (same file but different opener) in Viusal Studio Code
# run this file python code use visual studio
# code python
import sys
print ('\n'.join(sys.path))
# result
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python37.zip
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\DLLs
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\win32
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\win32\lib
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\Pythonwin
in command prompt
# run this file python code use command prompt
# code python
import sys
print ('\n'.join(sys.path))
# result
E:\py\test>whyitnotwork.py
E:\py\test
E:\Anaconda3\python38.zip
E:\Anaconda3\DLLs
E:\Anaconda3\lib
E:\Anaconda3
E:\Anaconda3\lib\site-packages
E:\Anaconda3\lib\site-packages\win32
E:\Anaconda3\lib\site-packages\win32\lib
E:\Anaconda3\lib\site-packages\Pythonwin
yes, I installed Anaconda, but I'm not use it anymore (atleast for now) it seem that the default "command prompt" has changed to anaconda dll directory (even though I'm not using it) but I don't know how to change it back like used to be.
what I have I try? i have make sure in environment variable, both path user variable and path system variable, "python micorsoft visual studio" is on the top. but still it has not fix the problem
thnks for your time and sorry about my english.