Search code examples
pythoncondaminicondapython-venv

Where should you store virtual environments for Python? (Conda framework via Miniconda on Windows)


I've been reading about virtual environments, and want to create one for working on some discord bots. I've identified the relevant libraries and read about the basics of virtual environments but I'm not entirely clear on a few things.

My primary question is: where exactly am I actually supposed to create them though? My file structure (in Windows) for the relevant files looks like the following, where I would like each project to be associated with a separate virtual environment. My reason for this structure is just to keep all my code in one place and keep track of stuff/upload to Github easily.

E:\code\project1
E:\code\project2
etc.

Any virtual environments I create are, by default, stored at:

C:\Users\<user>\Miniconda3\envs.

The root (base) environment's Python installation is simply at:

C:\Users\<user>\Miniconda3

Should I create the environment for each project within the relevant directory for that project, or store them all in the ...\envs folder of Miniconda? If it is the latter, how exactly do I 'link' or associate a project with that environment so that I don't have to keep track of it manually?

Sorry if the question is a bit vague or confusing, I'm trying to get my head around this.

EDIT: I think I figured it out, so I've posted my own answer in a comment as well as a separate answer (didn't realize at first I could do that).


Solution

  • Tl;DR: virtual environments are just handling the interpreter side of things, and can be accessed from anywhere through the terminal (in this case, the Anaconda Prompt terminal), and activated, then used to run code from wherever it's stored on the PC.

    For Conda, creating environments using conda create --name testenv will create a subdirectory in \Conda\envs containing the relevant files. To use it, navigate to it and activate the environment, then once you're finished using it, simply deactivate it to return the root interpreter.