The imports work for me if I do this.
Letâs start with an environment in which Python works normally. Iâm using the PowerShell command prompt. Letâs check:
PS gerberw> get-command python
CommandType Name Version Source
----------- ---- ------- ------
Application python.exe 3.11.51... C:\Users\Jeff\AppData\Local\Programs\Python\Python311\python.exe
PS gerberw> python -V
Python 3.11.5
PS gerberw> python -c "print('Hello world!')"
Hello world!
I do this next bit because I donât want to install a lot of Azure code in my system Python. It makes a virtual environment (a sort of project-specific installation of Python). It is optional, but is good practice when installing dependencies. It changes the prompt to remind you.
PS gerberw> python -m venv .\venv
PS gerberw> .\venv\Scripts\activate
(venv) PS gerberw> get-command python
CommandType Name Version Source
----------- ---- ------- ------
Application python.exe 3.11.51... C:\Users\Jeff\Documents\ML\gerberw\venv\Scripts\python.exe
Notice that Python (some of it) is now in the project local directory venv
, and that is on my Windows path.
Now we can get your code into a program. I will use IDLE the simple IDE that comes with Python. Iâll use pythonw
to spin it off so I get my prompt back.
(venv) PS gerberw> pythonw -m idlelib.idle imptest.py
There are nicer ways to launch IDLE but it depends how your PC is set up. That one ought to work anywhere.
In the editor I enter enough of your code to test the import statements:
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
from azure.cognitiveservices.vision.customvision.training.models import ImageFileCreateBatch, ImageFileCreateEntry, Region
from msrest.authentication import ApiKeyCredentials
import time
import os
then I save (ctrl-S) and run (F5). This happens in a new window:
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
= RESTART: C:\Users\Jeff\Documents\ML\gerberw\imptest.py
Traceback (most recent call last):
File "C:\Users\Jeff\Documents\ML\gerberw\imptest.py", line 1, in <module>
from azure.cognitiveservices.vision.customvision.training import CustomVisionTrainingClient
ModuleNotFoundError: No module named 'azure'
which is the sort of message I expected. This is because we havenât installed the Azure modules.
Back in the command prompt I install what it needs:
(venv) PS gerberw> pip install azure-cognitiveservices-vision-customvision
...
When I now re-run the code in IDLE the imports execute perfectly well. (Nothing to see.)
Each time you need to start a new command shell in this directory you will have to do the .\venv\Scripts\activate
bit again, but not anything else. What you installed is still there. You can see it in venv\Lib\site-packages
.