Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BDadmehr0/4a9f2907be3d495ade83dbea2149087b to your computer and use it in GitHub Desktop.

Select an option

Save BDadmehr0/4a9f2907be3d495ade83dbea2149087b to your computer and use it in GitHub Desktop.
### Error:
``` ps
.\.env\Scripts\Activate.ps1 : File C:\Users\Dadmehr\Documents\Github\Yadgah\.env\Scripts\Activate.ps1 cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\.env\Scripts\Activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
```
The error you're seeing occurs because **PowerShell’s execution policy** is set to restrict script execution for security reasons. You’re trying to activate a Python virtual environment using `Activate.ps1`, but PowerShell is blocking it.
---
### 🔧 Solution: Change the PowerShell Execution Policy
You can allow local scripts (like `Activate.ps1`) to run by changing the execution policy.
---
#### ✅ **Temporarily Allow Scripts for Current Session**
This is the **safest option**:
```powershell
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
```
Then run:
```powershell
.\.env\Scripts\Activate.ps1
```
This change only affects the **current PowerShell session**. When you close the window, it reverts to your default policy.
---
#### 🔁 **Or: Permanently Allow Scripts (Optional & Riskier)**
If you don't want to do this every time, you can allow scripts to run permanently (still reasonably safe if you choose `RemoteSigned`):
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
* `RemoteSigned` allows local scripts to run, but requires downloaded scripts to be signed.
---
### 🔍 To Check Current Policy
```powershell
Get-ExecutionPolicy -List
```
This will show the policy at each scope (`MachinePolicy`, `UserPolicy`, `Process`, etc.).
---
Let me know if you want help resetting the policy afterward or applying this to all projects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment