ImportError: "No modules named". But modules already installed in dist-packages
Is the module installed in your PYTHONPATH?
You can verify running this command line:
python -c "import sys; print '/usr/local/lib/python2.7/dist-packages' in sys.path"
Try to put psycopg2 module (or package, i don't know psycopg2) in the same directory of your script, and try to import it. Import searches first in the current directory.
import sys
print sys.path
Should display which are the search directories for the python interpreter, in order from the first to the last. The first is always the current directory, then there are the directories in PYTHONPATH and then python setup-dependent directories.
See: https://docs.python.org/2.7/tutorial/modules.html#the-module-search-path
You can edit sys.path in order to reach your module, or put the module in one of its directories.
Check where you installed the package, for me it was into the python 32 bit folder c:\program files (x86)\python37-32\lib\site-packages.
The problem I was running VsCode in x64 bit mode and the packages live in the x86 folder.
See here how you can change the interpreter you're using - in my case - I needed to set it to Python 3.7.4(x86) 32 bit (image off internet):