3

I am trying to use the microsoft azure custom vision service on a mac from Jupyter in VS Code

I have Python 3.8.3 installed.

I have done pip install azure.cognitiveservices.vision.customvision and confirmed it is there using pip show.

When I execute the command from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient

I get the error:

ModuleNotFoundError: No module named 'azure.cognitiveservices.vision.customvision'

I have tried adding the location where the package is installed to $PATH but that does not fix the problem.

Any thoughts gratefully received! thx

rickster04
  • 31
  • 3
  • Please check whether the python currently used by the VS Code terminal is the same as the one displayed in the lower left corner of the VS Code. ("python --version" or "pip --version") – Jill Cheng Apr 26 '21 at 08:00

2 Answers2

0

It is recommended that you always create and activate a python virtual environment to work with Jupyter notebooks, like an Anaconda environment, or any other environment in which you've installed the Jupyter package.

To select an environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). Once the appropriate environment is activated, you can create and open a Jupyter Notebook and connect to a remote Jupyter server for running code cells. Check Working with Jupyter Notebooks in Visual Studio Code for more info.

This is true for application development in Python in general as well.

A virtual environment is a folder within a project that isolates a copy of a specific Python interpreter. Once you activate that environment (which Visual Studio Code does automatically), running pip install installs a library into that environment only.

When you then run your Python code, it runs in the environment's exact context with specific versions of every library. You can create a requirements.txt file for the libraries you need, then use pip install -r requirements.txt.

Here is a snippet from a sample requirements.txt file:

azure-mgmt-core==1.2.0
azure-mgmt-network==16.0.0
azure-mgmt-resource==10.2.0

If you don't use a virtual environment, then Python runs in its global environment that is shared by any number of projects.

Refer to the Azure SDK for Python Developer docs for more information on configuring your local Python dev environment for Azure.

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

Whenever U get: ModuleNotFoundError, the simple solution is to install the module using

pip install (module name)

For example, in your case try to run the following line:

!pip install azure

The ! is to run a command in a notebook.

Yoni Kremer
  • 11
  • 1
  • 4