Trevor Fedyna
Trevor Fedyna

Reputation: 13

VS Code .py ModuelNotFoundError no moduel named 'pyodbc'

I'm currently working in VS code; wanting to interact with an .mdb file.

File "d:/UDtools/CostEstimator/vsWorkspace/pyOdbcv1.py", line 1, in <module>
import pyodbc
ModuleNotFoundError: No module named 'pyodbc'

pip installed in cmd, pip installed again in VS terminal: Requirement already satisfied.

I'm a bit new to this.

Upvotes: 1

Views: 1980

Answers (2)

Jill Cheng
Jill Cheng

Reputation: 10372

The reason is that the module "pyodbc" you installed is not installed in the VSCode environment you are currently using.

  1. Check the installation tool "pip". When we use 'pip' to install a module, the source of 'pip' determines where the module exists. Use "pip --version" to check if it comes from the current environment:

    enter image description here

    (If not, please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, VSCode will automatically enter the current environment.)

  2. Install the module. Use 'pip' to install the module in the currently selected environment: "pip install pyodbc" or "pip3 install pyodbc"

  3. Check the installation package. "pip list":

    enter image description here

  4. Run:

    enter image description here

More: Environment in VSCode.

Upvotes: 1

BeeFriedman
BeeFriedman

Reputation: 1974

If you are using the python extension to run you files. Then you are using python in a virtual envirnment to run python and not the system python. so even if you installed a package, as long as you did not install it in the venv python vs code won't find it. To test this run your .py file from the command line and see if you get the same error. if you don't then reconfigure you python interpreter in vs code or install the package in the vnev.

Upvotes: 0

Related Questions