1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] ModuleNotFoundError: No module named 'pyodbc' when importing pyodbc into py script

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 11, 2024.

  1. Stack

    Stack Membro Participativo

    I've written a short python script which tries to import the pyodbc extension package so I can access my SQL table.

    import pyodbc as pyodbc
    cnxn = pyodbc.connect('Driver={SQL Server};'
    'Server=DESKTOP-UO8KJOP;'
    'Database=ExamplePFData'
    'Trusted_Connection=yes;')


    I have definitely installed the extension by using: pip install pyodbc. And when I go to install it again, cmd says: Requirement already satisfied: pyodbc in ... and I've found the pyd file in my directories.

    I have also tried installing pypyodbc, which didn't work.

    The error I get is:

    Traceback (most recent call last):
    File "C:\Users\Jerry\Documents\Python\SQLembed.py", line 5, in <module>
    import pyodbc as pyodbc
    ModuleNotFoundError: No module named 'pyodbc'


    (where line 5 is the 'import pyodbc' line)

    I have tried copying the pyodbc.cp37-win_amd64.pyd file into my Python Scripts folder and into the folder where my pip.exe file is.

    • Currently python is my Python37 folder.
    • pyodbc.cp37-win_amd64.pyd is in Python > Lib > site-packages.

    Can anyone help me fix this error please so that I can import pyodbc?

    Do all of the python extensions/modules that I install via pip need to be in the same folder/directory as python.exe?

    Continue reading...

Compartilhe esta Página