Як активувати віртуальне середовище Python у Windows, macOS і Linux

How to Activate a Python Virtual Environment on Windows, macOS, and Linux

How to activate a Python virtual environment is a basic skill for anyone working on multiple projects and trying to keep dependencies separate. Correct activation lets you use the right package versions inside one project and avoid conflicts after installing libraries.

Activation commands for Windows, macOS, and Linux

How to activate a Python virtual environment depends on the operating system and the folder where the environment was created. In most cases, you use the standard command from the project directory.

  • Windows (Command Prompt): venv\Scripts\activate
  • Windows (PowerShell): .\venv\Scripts\Activate.ps1
  • macOS and Linux: source venv/bin/activate

After activation, the terminal prompt usually shows the environment name, such as (venv). That is the simplest sign that Python is now running inside that environment.

How to check that the environment is actually active

Checking Python virtual environment activation shows whether the terminal is using the correct interpreter and packages. The most reliable check is to look at the Python path and the installed dependencies.

  • Run python –version and confirm that the version matches your project.
  • Run where python on Windows or which python on macOS and Linux to see the interpreter path.
  • Check a package you just installed with pip list.

If the path does not point to the environment folder, activation did not work or the terminal is open in the wrong directory. Go back to the project folder and run the command again.

What to do if activation does not work

Problems with Python virtual environment activation are usually caused by execution policies, an incorrect path, or a missing environment. It is safer to check the folder structure first and only then change system settings.

Check whether the environment exists

The venv folder, or whichever directory name you chose, should contain Scripts on Windows or bin on macOS and Linux. If those folders are missing, recreate the environment with python -m venv venv.

Check the PowerShell policy on Windows

PowerShell can block the activation script from running. If Activate.ps1 does not execute, the cause is often a restricted execution policy. In that case, either allow local scripts for your user account or use Command Prompt instead.

Run the command from the correct directory

The activation command works only when the terminal is open in the folder that contains the environment. If you see an error such as “file not found,” first switch to the project root and try again.

What to do after activation

After activating a Python virtual environment, install dependencies into that environment instead of the global system Python. That keeps the project free from version conflicts and makes it easier to reproduce on another computer.

  • Install packages with pip install package_name.
  • Save dependencies in requirements.txt.
  • When you are done, deactivate the environment with deactivate.

If a package is still missing after activation, you are probably in the wrong environment or installed it into global Python. Check the interpreter path again and repeat the installation after activation.