I want to connect SQL server 2012/2014 from my windows machine using Python. For that I installed pyodbc module to my virtual environment using command below
pip install pyodbc
However, it gave me the message below when I run my script
import pyodbc ImportError: No module named pyodbc
Here is my code:
import pyodbc
db= pyodbc.connect(driver='{SQL Server Native Client 11.0}',
server='127.0.0.1',
database='master',
trusted_connection='yes')
db.close()
The module has already installed and it's listed when I use pip list. I have been searching around but with no luck on finding the solution on what exactly cause that issue.
Any helps will be appropriated.
I had this same problem after using conda to install pyodbc into a conda (virtual) environment and then trying to import into jupyter notebook.
At some point, I tried installing pyodbc into my base miniconda3 and finally the import in the conda env worked.
Edit : That was not much of a solution, though, and realized wasn't able to import any modules installed in the env.
Finally, problem was solved by following both option 1 and 2 on this page . Ie
What did not seem to work: Doing Step 3 above, and then outside the env, c:\\users\\user\\miniconda3\\python -m ipykernel install --user --name=my_env
Try
pip install pyodbc‑4.0.24‑cp37‑cp37m‑win_amd64.whl
You can aquire it here : https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc
Look in to the link and download it based on your CPU architecture : 32/64
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.