The error "'source' is not recognized as an internal or external command,
operable program or batch file" occurs when we use the
source command to
activate a virtual environment on Windows.
To solve the error, use the
venv\Scripts\activate command instead.
Open your shell in your project's root directory and run the following command to activate your virtual environment.
# 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1
venv. If you name it something else, make sure to update the start of the command.
Make sure to use the correct command for CMD and PowerShell.
You can use the
deactivate command if you need to deactivate the virtual
# 👇️ deactivate virtual environment deactivate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1
Alternatively, you can use the universal
venv\Scripts\activate command which
works regardless if you use CMD or PowerShell.
# 👇️ works for both CMD and PowerShell venv\Scripts\activate
And here is the activation command for macOS and Linux.
# 👇️ activate on Linux or MacOS source venv/bin/activate
If you haven't created a virtual environment, make sure to create one first.
# 👇️ use correct version of Python when creating VENV python -m venv venv # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ install modules in virtual environment pip install requests
python -m venv venv command doesn't work, try the following 2 commands:
py -m venv venv
python3 -m venv venv
Your virtual environment will use the version of Python that was used to create it.
If you use Git Bash, you would have to use the
python -m venv venv # 👇️ activate when using Git Bash source venv/Scripts/activate # 👇️ install modules in virtual environment pip install requests
If you still get an error when activating or creating your virtual environment, you have to add Python to your user's PATH environment variable.
To add Python to your user's PATH environment variable:
python -c "import os, sys; print(os.path.dirname(sys.executable))" where python
For me, the path is the following.
Note that I have Python 3.10 installed, which is reflected in the PATH.
Scriptsdirectory that is located in your Python3X folder. This is where the executable files are located.
For me, it is the following path.
You might also have to restart your PC, but that's not always necessary.
If you still encounter issues, try to add Python to your PATH using the official installer.
Download the installer from the official python.org website.
If you have Python already installed, start the installer and click on "Modify".
You can leave the optional features ticked.
If that didn't work, your Python installation might be corrupted.
Start the installer again and click on "Uninstall".
Now that you don't have Python installed on your machine, start the installer again and make sure to tick the "Add python.exe to PATH" option.
The checkbox won't be checked by default.
Once the "Add python.exe to PATH" checkbox is checked, click on "Install Now".
After the installation, Python will be installed and configured properly.
You can learn more about the related topics by checking out the following tutorials: