skip to Main Content

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


  1. Chosen as BEST ANSWER

    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 command conda create -n environmentName -p path/to/dir, and the environment's unique interpreter can be used to run a .py file with path/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 in condaInstallFolder/anaconda3/envs by default, and conda activate envName is a utility which simply calls the python interpreter at condaInstallFolder/anaconda3/envs/environmentName/python.


  2. 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

    • Create conda environments outside of vscode – using conda cli.
    • Run conda activate to use one of those environmets
    • Launch vscode, and tell it to use another conda environment
    • or Launch vscode, tell it to use another venv or python installed in your own custom directory.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search