Virtual environments
On this page
Create a project environmentUse it for the projectLeave the environmentHow this relates to venvInstalling a package changes the environment in which it is installed. If two projects need different package versions, sharing one environment can create conflicts. A separate project environment keeps one project’s requirements from changing another’s.
An environment is not the project folder: the folder holds your program files, while the environment supplies Python and its installed packages.
Create a project environment
For the Anaconda route used in this book, conda can create an isolated environment with its own Python and packages. In Anaconda Prompt on Windows or the configured Terminal on macOS/Linux, enter:
conda create --name book-practice python numpyReview the proposed installation and confirm it. book-practice is the environment’s name; it does not create or replace your project’s source folder. Naming the packages in the command ensures that this new environment has them, regardless of what is installed in base.1
Use it for the project
- Activate the environment in the terminal:
conda activate book-practice- Check the selected Python and NumPy:
python -c "import sys; print(sys.executable)"
python -c "import numpy; print(numpy.__version__)"The path should identify book-practice; the second command should display a version number rather than an import error.
- In VS Code, use Python: Select Interpreter and choose
book-practicefor the open project. Terminal activation and editor selection must agree about which Python the project uses.
For a notebook, select the matching Python kernel—the process that executes its cells. Selecting an interpreter for saved files does not change a notebook that is already running with another kernel.
Leave the environment
conda deactivateThis changes the terminal’s active environment; it does not delete the environment or the program files. Activate book-practice again when returning to the project.
How this relates to venv
Python also provides venv, a tool that creates an environment from an existing Python installation. Its files commonly live in a project’s .venv folder. It serves the same isolation goal, but it is created and activated differently from a conda environment. Use one approach for a project; the commands above follow the book’s conda route.2
With the environment chosen, both saved scripts and interactive sessions can use the same intended packages.
conda, Managing environments. Creation, activation and deactivation checked on 22 October 2026.↩︎
Python documentation, venv — Creation of virtual environments.↩︎