Virtual environment (venv)
What this is about
A virtual environment (VENV) keeps the Python dependencies of one specific project isolated. This is particularly useful for avoiding conflicts between different projects, because each environment manages its own dependencies and packages, independently of any other Python installation on the system.
-
Step 1 of 6 Open the command prompt (CMD)
Drücken Sie Win + R, geben Sie
cmdand confirm with Enter. -
Step 2 of 6 Navigate to the desired location
If the virtual environment (VENV) is to be created in a particular directory, navigate there. Example:
cd "C:\Users\<your User>\pythonEnv"If the directory does not exist yet, create it with the following command and then change into the folder:
mkdir "C:\Users\<your User>\pythonEnv"cd "C:\Users\<your User>\pythonEnv" -
Step 3 of 6 Create the virtual environment
Run the following command to create a new virtual environment named myFirstEnv:
py -3.13 -m venv myFirstEnvRunning it creates a new folder ‚myFirstEnv‘ in the current directory. That folder holds every file the virtual environment needs, including the interpreter binaries, libraries and configuration files.
-
Step 4 of 6 Navigate into the environment folder and activate it
Change into the Scripts folder of the virtual environment you created. Then run the following command to activate the virtual environment:
cd "C:\Users\<your User>\pythonEnv\myFirstEnv\Scripts"activateOnce activated, the command line prompt shows the name of the environment in brackets, for example:
(myFirstEnv) C:\Users\<your User>\pythonEnv\myFirstEnv\Scripts>This indicates that the virtual environment has been activated successfully.
-
Step 5 of 6 Install packages in the activated environment
Once the virtual environment has been activated successfully,
(myFirstEnv)appears in front of the input line, indicating that the environment is active. Every package the project needs can now be installed inside this environment. Example installations:pip install numpypip install pandasThe following command gives an overview of the packages already installed and their versions:
pip list -
Step 6 of 6 Install the Spyder kernels for use with Spyder
If Spyder is to be used as the development environment, the Spyder kernels have to be installed. This can be done with the following command:
pip install spyder-kernels==3.0.*