0

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://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
FAHRB
  • 39
  • 1
  • 7

1 Answers1

0

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.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30