I am using VS Code with WSL and use Miniconda on Windows, what is the best practice for managing Python environments inside WSL?
(answers generated by ChatGPT)
Using a separate Miniconda installation inside WSL gives you the most consistent and manageable Python environment experience (isolated from system Python).
🔧 Steps:
-
Install Miniconda in WSL:
Follow the prompts to install, and allow it to add
conda
to your.bashrc
or.zshrc
.
-
Restart your WSL terminal or run:
Answer yes to make conda available easily. Then immediately run:
This keeps conda available in your shell. Prevents auto-activation of the base environment (you'll be in your system Python unless you explicitly activate a conda env).
-
Create a new environment:
- You can install a conda package also without activating the environment. Just use
orconda install -n <env_name> <package>
conda install -p <path/to/env> <package>
. -
Use it in VS Code:
-
Open your project folder in VS Code using
code.
from inside WSL. -
When the conda environment is active, VS Code should detect it. If not:
-
Press
Ctrl+Shift+P
→ Python: Select Interpreter → Choose themyenv
from conda.
-
-
No comments:
Post a Comment