Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

azure - Visual studio code Python execution

I seem to have some path issue while running Python(v3.9.1) in Visual studio code .The Azure libraries/SDK are not picked up while running the python file. Do I need to set the Azure SDK in the Python path ?

 from azure.core.exceptions import ResourceNotFoundError
ModuleNotFoundError: No module named 'azure'
question from:https://stackoverflow.com/questions/65837332/visual-studio-code-python-execution

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Nope, that's not needed. But for every project, it is recommended that you always create and activate a python virtual environment using:

# This command runs the Python venv module and creates a virtual environment in a folder named .venv.
py -3 -m venv .venv

# Activate the virtual environment
.venvscriptsactivate

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-cli-core==2.11.1
azure-cli-telemetry==1.0.6
azure-common==1.1.25
azure-core==1.8.1
azure-identity==1.4.0
azure-mgmt-compute==17.0.0
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...