3

Im experimenting with the bing search api from azure. I've installed the module using pip(using python -m pip install azure-cognitiveservices-search-websearch) into the virtual environment I created using venv. Have I done something wrong? Because the module can't be found by the program.

I've tried installing it globally through pip but it still didn't do what it's expected to do. I have read the help that is provided on the azure web page line by line. The module still fails to be found by the program besides the fact that, that the program is saved in the same subdirectory as the virtual environment saves to.

This is the exact code that is provided by microsoft. It isn't mine but it is what is required for the program to work.

from azure.cognitiveservices.search.websearch import WebSearchAPI
from azure.cognitiveservices.search.websearch.models import SafeSearch
from msrest.authentication import CognitiveServicesCredentials

It is expected to import the modules and then continue to run the program.But all I get in the shell is:

Traceback (most recent call last):
from azure.cognitiveservices.search.websearch import WebSearchAPI
ModuleNotFoundError: No module named 'azure'

And obviously that is not what I wanted to have outputted. What have i incorrectly done?

  • Have you activated your virtual environment before installing via pip? – Alex Lucaci Oct 10 '19 at 18:03
  • Yes, I've Just remade the environment (with all the pip installs) to ensure that it is activated and tried again. But the program still refuses to run and outputs the same issue. – RentalLeader Oct 10 '19 at 18:56

1 Answers1

2

I created a python project in VS code on windows os and set,active virtual environments by Powershell below :

python -m venv myvenv
./myvenv/Scripts/Activate.ps1
python -m pip install azure-cognitiveservices-search-websearch

Test the import command ,it works without exception :

enter image description here

Hope it helps .

Stanley Gong
  • 11,522
  • 1
  • 8
  • 16
  • With the Activate.ps1 command, I am getting this: '.' is not recognized as an internal or external command, operable program or batch file. Any idea why? – Azurespot Dec 03 '19 at 01:02
  • Never mind, my error was that I was running in command line, not in the PowerShell terminal of Visual Studio Code. I was able to run `Activate.ps1` from the Scripts folder of my virtual environment. – Azurespot Dec 03 '19 at 01:10
  • I just used the python -m pip install .... it worked, but when just using pip install ... it doesn't. I do not know the reason, could someone explain please? – Franva Feb 23 '20 at 00:29