I’m trying to get back into python, working on a unix system.
I’m trying to understand virtual environments, to keep all my packages organized, and am struggling with the difference between conda environments localized in a project directory with a /.conda/ subdirectory, and conda environments that live in conda_intallation_folder/envs/
I was reading the VSCode docs on venvs and understand the following:
A virtual environment creates a folder that contains a copy (or symlink) to a specific interpreter. When you install packages into a virtual environment it will end up in this new folder, and thus isolated from other packages used by other workspaces.
My question is specifically about the difference between conda enviroments that could be created with
conda create -n ENV_NAME python=PYTHON_VERSION
which I understand I would have to activate, with
conda activate env_name_or_prefix
and the conda environments I created through VSCode’s Command Pallet, choosing Select Interpreter –> create virutal environment, which creates the local /.conda/ subdirectory.
I understand that both of these operations create an isolated interpreter with a unique set of packages.
I want to better understand the difference between these two approaches to creating the isolated interpreter, so I can make sure I’m accessing the environment I want and not accidentally tossing everything into global. Many thanks!
2
Answers
My question was asking about difference between two approaches to creating a virtual environment, 1) from inside VSCode's GUI, and 2) from CLI, with both approaches using Conda as an environment manager.
The first approach, using VSCode's GUI, creates a local hidden folder
/.conda
, which contains an isolated python interpreter at/.conda/bin/python
. Creating a conda environment this way is the same as using the commandconda create -n environmentName -p path/to/dir
, and the environment's unique interpreter can be used to run a.py
file withpath/to/dir/.conda/bin/python fileName.py
The difference between this approach and using
conda create -n environmentName
is only that this command puts the.conda
folder incondaInstallFolder/anaconda3/envs
by default, andconda activate envName
is a utility which simply calls the python interpreter atcondaInstallFolder/anaconda3/envs/environmentName/python
.welcome to Stackoverflow.
If your only goal is to ensure that you do not mix up the environments, it does not matter whether you use venv or conda to create the environments. VScode can even detect ( or you can help find it ) if you have python installed in your own directory outside of venv or conda.
As an example, you can