Python venv and .venv: Create an Environment and Check the Interpreter
Create and activate a Python virtual environment or run it directly, diagnose interpreter and pip mismatches, and recreate it when moving projects.
To isolate packages for each Python project, create an environment in the project directory with python -m venv .venv, then use that environment's Python for installation and execution. .venv is a conventional directory name, not a different feature from the venv module. If an import still fails after installation, first check which interpreter is actually running.
Conceptual illustration of separate package environments for projects.
This article uses the official Python venv documentation as of November 13, 2026. Environment creation and interpreter identification were run on Linux with Python 3.12.14. The Windows commands are documentation-based and were not run.
1. What is the difference between venv and .venv?
venv is the standard library module that creates virtual environments. .venv is only the destination folder name; venv or another name works too. By default, each environment's packages are isolated from other environments and system packages. The --system-site-packages option allows access to system packages.
A virtual environment is not a security sandbox. Installed code runs with the permissions of the user running the process.
2. Create an environment with the intended Python
Run the following in the project root. The Python used to create it determines the environment's base version, so check the version first.
On Windows, after checking the installed Python, use:
An existing destination directory is reused. Check that it does not contain project files, and do not casually use --clear, which deletes its contents. Some Linux distributions package venv or ensurepip separately; consult the distribution's instructions if creation fails.
3. Activate it or call the interpreter directly
Activation is a convenience that prepends the environment's executable directory to PATH in the current shell. Activate again when opening a new shell.
| Environment | Activation command |
| Linux/macOS bash/zsh | source .venv/bin/activate |
| Windows PowerShell | .\.venv\Scripts\Activate.ps1 |
| Windows cmd | .venv\Scripts\activate.bat |
Run deactivate to leave the environment. If PowerShell execution policy blocks the script, check your organization's policy. You can also use the interpreter directly without changing the policy. Activation reference
Replace app.py with the project's actual entry point. python -m pip uses pip associated with the selected Python and reduces confusion when a separate pip command points elsewhere.
4. If an import fails after installation
Check the path of the running Python and whether it is in a virtual environment.
The first line is the actual interpreter path; True means it is running in a virtual environment. Compare the path printed by pip with the intended environment as well. IDEs, terminals and service configurations can use different interpreters, so check each one. Do not rely on the (.venv) prompt or VIRTUAL_ENV alone: an environment's interpreter can run directly without activation.
Install required packages with that interpreter. For example, if the project provides a requirements file:
For installation failures or version conflicts, inspect the error and the project's Python and dependency requirements separately.
5. Recreate environments when moving or sharing
Scripts inside an environment can contain absolute paths, so copying its folder or moving the project and continuing to use it is unreliable. Keep the dependency definitions, recreate the environment at the new location, and install the dependencies again. The .venv directory itself is generally not committed to Git. Since Python 3.13, venv creates a Git ignore file inside the environment by default, but also check the team's repository ignore policy. Official portability guidance
The checks actually run here cover environment creation and the sys.prefix comparison on Linux. Platform-specific activation and package installation examples follow the official documentation.