What is a Python virtual environment?
A Python virtual environment (venv) is simply a directory with
a particular file structure. It has a Scrips subdirectory that
includes links to a Python interpreter as well as subdirectories
that hold packages installed in the specific venv.
Links
Virtual Environments and Packages
(Python Docs)
Create and Use Virtual Environments
How to launch python Idle from a virtual environment (virtualenv)
Steps (Windows 10)
The following are executed in a single command window.
"my-venv-projects" and "project-venv"
are place holders. Create your own directories.
- Create a directory to hold one or more VENV projects
mkdir c:\Users\my-venv-projects
dir c:\Users\my-venv-projects
- Create a directory for a project's VENV
cd c:\Users\my-venv-projects
python -m venv project-venv
dir
- Go to the project's VENV directory
cd project-venv
dir
- Create The Project's VENV
python -m venv project-venv
dir
- Activate the Project's VENV
.\Scripts\activate.bat
Note: The command prompt will change.
# After activating a VENV you are using
# a modified environment. To see the
# modified environment's path variable,
# Run the following program in an
# activated VENV. (try before and after)
import sys
for p in sys.path:
print(p)
- Install Modules (for example pandas)
python -m pip install pandas
...
...
...
You only need to do this once.
The modules become part of the VENV.
- Start The IDLE
python -m idlelib.idle
Do your work in the IDLE.
The command window will "hang" until the IDLE exits.
- Deactivate the Project's VENV
.\Scripts\deactivate.bat
Note: The command prompt will change.
-
To delete the project completely,
delete the directory
project-venv
and all of the files under it.
rmdir c:\Users\my-venv-projects\project-venv /s