# Virtual Environment on Windows

**URL:** <https://forum.djangoproject.com/t/virtual-environment-on-windows/8445>\
**Category:** Using Django\
**Created:** [June 21, 2021, 5:39pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445 "2021-06-21T17:39:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wsvincent](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/wsvincent/32/52_2.png) [@wsvincent](https://forum.djangoproject.com/u/wsvincent)\
**Post date:** [June 21, 2021, 5:39pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/1 "2021-06-21T17:39:11Z")

</div>

By default, it is not possible to activate a Python virtual environment in Windows. The [Execution Policy](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1) must be set. My question is: which Execution Policy level do Django developers use?

Seems there are 3 general options:

1. Allow all scripts with `Set-ExecutionPolicy Unrestricted -Force` though that seems a bit unsafe.
2. Set per PowerShell session `Set-ExecutionPolicy Unrestricted -scope process` though a major pain
3. Set per user `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser` which is what the [Python docs](https://docs.python.org/3/library/venv.html) seem to recommend
4. Just use Docker 🙂

My guess is #3 is what most folks would do but just curious, especially if you were telling a junior Python/Django developer how to configure their machine?

PS. I’m asking because of adding full Windows support to my [Django books](https://learndjango.com/books/) for 3.2 and it’s quite the effort to do.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 21, 2021, 6:04pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/2 "2021-06-21T18:04:29Z")

</div>

Option 5: Don’t use power shell, work in the standard command prompt.

Option 6: Work from within the context of your IDE (e.g. Visual Studio)

Option 7: Work within the WSL environment

Option 8: Work within a virtual machine (VirtualBox or VMWare)

I use options 5-8 depending upon the specific project.

---

<div class="post-metadata">

**Author:** ![wsvincent](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/wsvincent/32/52_2.png) [@wsvincent](https://forum.djangoproject.com/u/wsvincent)\
**Post date:** [June 21, 2021, 7:28pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/3 "2021-06-21T19:28:55Z")

</div>

😀 I agree Ken but all the options are overwhelming to someone new to all this. That’s why I’m using PowerShell vs standard prompt or even [Windows Terminal](https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701?activetab=pivot:overviewtab). It’s quite a challenge to make these things “simple” and not overwhelm newbies.

I do think that for my own usage, I’d just go Docker and then WSL. I “think” I’m going to mimic Python and just include the `CurrentUser` command in the setup. Just feels like one more hurdle on Windows vs Mac.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [June 21, 2021, 7:58pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/4 "2021-06-21T19:58:45Z")

</div>

We take a slightly different approach. Since _all_ our deployments are on Linux systems, our new developers start out with using WSL. That gets them started right away with learning the production environments and avoids learning things that only apply to their development environments.

---

<div class="post-metadata">

**Author:** ![wsvincent](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/wsvincent/32/52_2.png) [@wsvincent](https://forum.djangoproject.com/u/wsvincent)\
**Post date:** [June 21, 2021, 8:14pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/5 "2021-06-21T20:14:22Z")

</div>

Yeah. I agree with that in a team environment. In terms of teaching it’s always a question of when to present complexity to people. In my own case–at least for books and online tutorials–I want to succinctly/accurately cover installing Python and get into Django itself as quickly as possible. Means a lot of hand waving around Python, operating systems, etc though 🙂

---

<div class="post-metadata">

**Author:** ![FlipperPA](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/flipperpa/32/181_2.png) [@FlipperPA](https://forum.djangoproject.com/u/FlipperPA)\
**Post date:** [June 21, 2021, 8:34pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/6 "2021-06-21T20:34:02Z")

</div>

Because of muscle memory, I wrote up a shortcuts to use `venv` instead of `virtualenv` mimicking `virtualenvwrapper`, but just for Linux: [Shortcuts for Python 3’s venv for virtualenvwrapper users. (github.com)](https://gist.github.com/FlipperPA/4f4de8e1dcfe0d9a6f11171b733c03b7)

On the GIST, Vince Salvino put in a comment with similar function for PowerShell. Would this help? See: [Shortcuts for Python 3’s venv for virtualenvwrapper users. (github.com)](https://gist.github.com/FlipperPA/4f4de8e1dcfe0d9a6f11171b733c03b7#gistcomment-2981247)

I’ll ping Vince on Twitter about this thread, since it seems to be in his wheelhouse.

---

<div class="post-metadata">

**Author:** ![wsvincent](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/wsvincent/32/52_2.png) [@wsvincent](https://forum.djangoproject.com/u/wsvincent)\
**Post date:** [June 21, 2021, 11:37pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/7 "2021-06-21T23:37:06Z")

</div>

Worth noting that Brett Cannon weighed in with Option 3, 7 (WSL), or [PEP 582](https://t.co/Xfk48OCTm8?amp=1)

> <https://twitter.com/brettsky/status/1407107258043953152>

Thanks @jeff for the Tweet.

---

<div class="post-metadata">

**Author:** ![salvino](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/salvino/32/5033_2.png) [@salvino](https://forum.djangoproject.com/u/salvino)\
**Post date:** [July 5, 2021, 10:59pm UTC](https://forum.djangoproject.com/t/virtual-environment-on-windows/8445/8 "2021-07-05T22:59:34Z")

</div>

Windows 10 has a “Developer Mode” setting (in the settings GUI) which automatically turns on the necessary PowerShell knobs. It also enables SSH command line tools, shows file extensions (rookies get really confused why their files do not say `.py` because File Explorer hides extensions by default) and a lot of other stuff that is a PITA to set up yourself on Windows.

**Settings \> Updates & Security \> For Developers** : Then check the PowerShell box and any other boxes and click apply.

For doing Python development, you will also most likely need a C compiler for installing pip packages. So I would recommend installing [Visual Studio Community 2019](https://visualstudio.microsoft.com/) (which is the free version for individuals and small teams). The installer has a checkbox for Python development which installs everything you need.

Full info on “Developer Mode”: [Developer Mode features and debugging - Windows apps | Microsoft Docs](https://docs.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)

* * *

Once set up, we have our junior devs just manually create and use `venv`s, because it is so much simpler than trying to teach people of varying skill levels the ins and outs of tools like pyenv/poetry. `venv` is included with Python and “just works”.

After you first `git clone` the project:

1. In PowerShell, `cd` to project folder.
2. `python -m venv .venv`

Every time you work on the project:

1. In PowerShell, `cd` to project folder.
2. `.\.venv\Scripts\Activate.ps1`
3. `pip install -r requirements.txt`
