# Infinite loop of virtualenv: Windows

**URL:** <https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139>\
**Category:** Windows\
**Tags:** python\
**Created:** [July 9, 2019, 1:26pm UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139 "2019-07-09T13:26:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![YakDriver](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yakdriver/32/1073_2.png) [@YakDriver](https://travis-ci.community/u/YakDriver)\
**Post date:** [July 9, 2019, 1:26pm UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/1 "2019-07-09T13:26:37Z")

</div>

Python 3.7.4 + virtualenv + Windows results in an infinite loop of sadness.

In the following config, the `source` line (`source $HOME/venv/Scripts/activate`) is never reached because of the death, destruction, and mayhem (i.e., infinite loop, memory error, and timeout).

Config:

```auto
    - stage: test
      os: windows
      language: shell
      env: PATH=/c/Python37:/c/Python37/Scripts:$PATH
      before_install:
        - choco install python
        - python -m pip install virtualenv
        - virtualenv $HOME/venv
        - source $HOME/venv/Scripts/activate

```

Logs:

```auto
    $ virtualenv $HOME/venv
    You are using pip version 19.0.3, however version 19.1.1 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    Running virtualenv with interpreter c:\python37\python.exe
    ...

```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 9, 2019, 6:46pm UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/2 "2019-07-09T18:46:28Z")

</div>

You can debug `virtualenv` by running it via `bash -x` and using a [useful `PS4`](https://wiki-dev.bash-hackers.org/scripting/debuggingtips#making_xtrace_more_useful) and [request debug more](https://docs.travis-ci.com/user/running-build-in-debug-mode/) for better efficiency.

---

<div class="post-metadata">

**Author:** ![YakDriver](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yakdriver/32/1073_2.png) [@YakDriver](https://travis-ci.community/u/YakDriver)\
**Post date:** [July 10, 2019, 1:19am UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/3 "2019-07-10T01:19:52Z")

</div>

The _ **Windows** _ shell doesn’t seem to support `bash -x`. This issue is only affecting our Windows jobs. Using virtualenv on OSX and Linux is working fine.

I’ve tried pipenv on Windows to create the virtualenv and we get the same. Infinite loop until timeout:

```auto
39.82s$ python -m pip install pipenv
Collecting pipenv
  Downloading https://files.pythonhosted.org/packages/13/b4/3ffa55f77161cff9a5220f162670f7c5eb00df52e00939e203f601b0f579/pipenv-2018.11.26-py3-none-any.whl (5.2MB)
Collecting certifi (from pipenv)
  Downloading https://files.pythonhosted.org/packages/69/1b/b853c7a9d4f6a6d00749e94eb6f3a041e342a885b87340b79c1ef73e3a78/certifi-2019.6.16-py2.py3-none-any.whl (157kB)
Collecting virtualenv-clone>=0.2.5 (from pipenv)
  Downloading https://files.pythonhosted.org/packages/ba/f8/50c2b7dbc99e05fce5e5b9d9a31f37c988c99acd4e8dedd720b7b8d4011d/virtualenv_clone-0.5.3-py2.py3-none-any.whl
Requirement already satisfied: pip>=9.0.1 in c:\python37\lib\site-packages (from pipenv) (19.1.1)
Collecting virtualenv (from pipenv)
  Downloading https://files.pythonhosted.org/packages/c4/9a/a3f62ac5122a65dec34ad4b5ed8d802633dae4bc06a0fc62e55fe3e96fe1/virtualenv-16.6.1-py2.py3-none-any.whl (2.0MB)
Requirement already satisfied: setuptools>=36.2.1 in c:\python37\lib\site-packages (from pipenv) (40.8.0)
Installing collected packages: certifi, virtualenv-clone, virtualenv, pipenv
Successfully installed certifi-2019.6.16 pipenv-2018.11.26 virtualenv-16.6.1 virtualenv-clone-0.5.3
174.26s$ pipenv shell
Creating a virtualenv for this project�
Pipfile: C:\Users\travis\build\YakDriver\scratchrelaxtv\Pipfile
Using c:\python37\python.exe (3.7.4) to create virtualenv�
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
...
[800-900 lines later]
...
Running virtualenv with interpreter c:\python37\python.exe
Running virtualenv with interpreter c:\python37\python.exe
FAIL
['Traceback (most recent call last):\n', ' File "c:\\python37\\lib\\site-packages\\pipenv\\utils.py", line 501, in create_spinner\n yield sp\n', ' File "c:\\python37\\lib\\site-packages\\pipenv\\core.py", line 935, in do_create_virtualenv\n extra=[crayons.blue("{0}".format(c.err)),]\n', 'pipenv.exceptions.VirtualenvCreationException: Failed to create virtual environment.\n']
[pipenv.exceptions.VirtualenvCreationException]: File "c:\python37\lib\site-packages\pipenv\cli\command.py", line 390, in shell
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=state.pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "c:\python37\lib\site-packages\pipenv\core.py", line 2156, in do_shell
[pipenv.exceptions.VirtualenvCreationException]: three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "c:\python37\lib\site-packages\pipenv\core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]: File "c:\python37\lib\site-packages\pipenv\core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]: File "c:\python37\lib\site-packages\pipenv\core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]: extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: MemoryError
Failed to create virtual environment.
The command "pipenv shell" failed and exited with 1 during .
Your build has been stopped.

```

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 10, 2019, 2:02am UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/4 "2019-07-10T02:02:20Z")

</div>

Sorry, I forgot that `virtualenv` is a Python script :-\  
(It creates a bash `activate` script even in Windows, and Travis runs things via Git Bash, so if the problem was in `activate`, this would do.)

In that case, I would run `virtualenv` via `<python> -m pdb` or add some debug printing into `site-packages\virtualenv.py` around the place where the repeating line is printed.

---

<div class="post-metadata">

**Author:** ![YakDriver](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yakdriver/32/1073_2.png) [@YakDriver](https://travis-ci.community/u/YakDriver)\
**Post date:** [July 10, 2019, 1:48pm UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/5 "2019-07-10T13:48:12Z")

</div>

Looks like this is an issue with virtualenv and Python 3.7.4 running on _ **Windows** _. _(“Windows, why u do me that way?!”)_

> <https://github.com/pypa/virtualenv/issues/1380>

You can fix your config with this:

```auto
choco install python --version 3.7.3

```

---

<div class="post-metadata">

**Author:** ![YakDriver](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/yakdriver/32/1073_2.png) [@YakDriver](https://travis-ci.community/u/YakDriver)\
**Post date:** [July 18, 2019, 8:10pm UTC](https://travis-ci.community/t/infinite-loop-of-virtualenv-windows/4139/6 "2019-07-18T20:10:28Z")

</div>

In Windows, it’s no longer necessary to pin Python at 3.7.3. The maintainers fixed the issue in virtualenv version 16.6.2, currently the latest release.
