0
0
MLOpsdevops~10 mins

Environment management with conda and pip in MLOps - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Environment management with conda and pip
Start: Need new environment
Create conda env
Activate env
Install packages with conda
If package missing
Yes
Install package with pip
Use environment
Deactivate env
Delete env if needed
End
This flow shows how to create and manage a Python environment using conda, install packages with conda or pip, then use and clean up the environment.
Execution Sample
MLOps
conda create -n myenv python=3.12
conda activate myenv
conda install numpy
pip install requests
conda deactivate
Create a conda environment, activate it, install numpy with conda, install requests with pip, then deactivate the environment.
Process Table
StepCommandActionResult/Output
1conda create -n myenv python=3.12Create environment named myenv with Python 3.12Environment 'myenv' created with Python 3.12
2conda activate myenvActivate the environment myenvPrompt changes to (myenv), environment active
3conda install numpyInstall numpy package using condanumpy installed successfully
4pip install requestsInstall requests package using pip inside conda envrequests installed successfully
5conda deactivateDeactivate the current environmentPrompt returns to base, environment deactivated
6conda env listList all conda environmentsShows 'myenv' and 'base' environments
7conda remove -n myenv --allDelete the environment myenvEnvironment 'myenv' deleted successfully
💡 Environment deleted or deactivated, no active conda environment
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 7
Active Environmentbasebasemyenvmyenvmyenvbasebase
Installed Packagesbase packagesbase packagesbase packagesbase + numpybase + numpy + requestsbase packagesbase packages
Key Moments - 3 Insights
Why do we sometimes use pip inside a conda environment instead of conda?
Some packages are not available in conda repositories, so pip is used inside the active conda environment to install those packages, as shown in step 4 of the execution_table.
What happens if you try to install packages without activating the conda environment?
Packages will install in the base environment or system Python, not the intended environment. Step 2 shows activation is needed before installing packages in 'myenv'.
Why do we deactivate the environment after use?
Deactivating returns you to the base environment or system Python, preventing accidental package installs or runs in the wrong environment, as shown in step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the active environment after step 3?
ANone
Bbase
Cmyenv
Droot
💡 Hint
Check the 'Active Environment' row in variable_tracker after step 3
At which step does the environment become inactive?
AStep 4
BStep 5
CStep 6
DStep 7
💡 Hint
Look at the 'Active Environment' variable in variable_tracker and the command in execution_table
If you skip step 2 and run 'conda install numpy', where will numpy be installed?
AIn the base environment
BIn the 'myenv' environment
CNowhere, command fails
DIn a new environment
💡 Hint
Refer to key_moments about activating environment before installing packages
Concept Snapshot
conda create -n envname python=3.12  # create env
conda activate envname                # activate env
conda install package                  # install with conda
pip install package                    # install with pip if missing
conda deactivate                      # leave env
conda remove -n envname --all         # delete env
Use conda envs to isolate projects and avoid conflicts.
Full Transcript
This lesson shows how to manage Python environments using conda and pip. First, you create a new environment with a specific Python version using 'conda create'. Then you activate it with 'conda activate' to work inside it. You install packages preferably with 'conda install', but if a package is missing, you use 'pip install' inside the active environment. After finishing work, you deactivate the environment with 'conda deactivate' to return to the base system. You can list environments with 'conda env list' and delete an environment with 'conda remove -n envname --all'. Activating the environment before installing packages ensures they go to the right place. Deactivating prevents accidental installs in the wrong environment. This process helps keep projects clean and dependencies separate.