
One project needs an older package while another needs a newer one. Reinstalling packages into the same Python setup can turn that conflict into a daily ritual. I would give each project its own virtual environment before trying another round of global installs.
What a virtual environment solves
Python's tutorial describes a virtual environment as a separate directory tree containing an interpreter and packages for a particular setup. Different projects can then keep different package versions. The environment uses the Python version selected when it is created; it does not automatically upgrade an older interpreter.
A common folder name is .venv. Keep it distinct from a .env file used by some applications for configuration. Similar names do not mean they have the same purpose.
A small setup sequence
From the intended project directory, use your chosen Python command to run python -m venv .venv. On systems where the interpreter is named python3, use that command name instead. Check its version first so the environment starts from the interpreter you actually want.
Activation depends on the shell. Python's tutorial gives source .venv/bin/activate for a typical bash session on macOS or Linux. Windows activation scripts differ between Command Prompt and PowerShell, so use the matching instructions in the packaging guide rather than pasting a command for another shell.
- Confirm the current directory and interpreter version.
- Create the environment.
- Activate it using the correct shell instructions.
- Use
python -m pipso package operations follow that Python interpreter. - Inspect
python -m pip listand the package location when troubleshooting an unexpected import.
Record the setup, then test a fresh one
Python documents python -m pip freeze for producing an installed-package list in requirements-file format. A requirements file can then be used with python -m pip install -r requirements.txt. I would review the list before sharing it, especially if the environment has accumulated unrelated experiments.
For a reproducibility check, create a second disposable environment and install the reviewed requirements there. Run the project's normal checks. The existence of requirements.txt alone does not prove another computer can reproduce the application, particularly when operating-system libraries or external services are involved.
Know the boundary
A virtual environment separates Python packages. It does not make untrusted code safe to execute, grant permission to install software on a managed laptop or replace application data backups. Do not respond to a package error by running every suggested command with administrator privileges.
My stopping point is that the project imports the intended packages from its own environment and its setup instructions name the required interpreter. These commands follow official Python documentation; no particular package combination has been tested for this article.
Sources and scope
Source-checked November 18, 2026. Original explanatory guide, not a hands-on test. Product behavior above is grounded in the official documentation linked below; workflow recommendations are editorial advice.
Comments
Post a Comment