简体   繁体   中英

ModuleNotFoundError: No module named 'pyodbc' - Azure Batch - Ubuntu

I am trying to run a Python job using a VM on Azure Batch, utilizing the Python package Pyodbc. However I am unable to install it correctly (obviously) as run into ModuleNotFoundError: No module named 'pyodbc' . I used the following command (start task) to install the ODBC driver on my VM (Ubuntu) and installation works fine:

/bin/bash -c 'sudo -H apt-get -y update && 
sudo -H dpkg --configure -a && 
sudo -H apt-get install -y python3-pip && 
sudo -H pip3 install --upgrade pip && 
sudo -H su
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo -H apt-get update
sudo -H ACCEPT_EULA=Y apt-get install -y msodbcsql17
sudo -H apt-get install -y unixodbc-dev && 
sudo -H pip3 install pandas &&
sudo -H pip3 -H install egg && 
sudo -H pip3 -H install azure-storage-common && 
sudo -H pip3 install --upgrade pyodbc &&
sudo -H pip3 install azure-storage-blob'

The wierd part is that I can run import pandas and the other packages without any problem. Can someone help me out?

guide for installing ODBC: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

You either might have multiple versions of Python installed alongside each other or are installing the module in one but running the script in another environment.

Some similar issues:

It is always advisable to run your Python code in context of a virtual environment, so it runs in the environment's exact context with specific versions of every library, that can help with avoiding such errors.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM