Skip to main content

Creating PyPy virtualenvs on Ubuntu WSL

It's a tale of desperation and despondency.

Okay so I finally dipped my toe in Ubuntu WSL. I won't get into the details of installing WSL, it's described clearly in many documentations, even Microsoft's WSL Intallation Guide is a model of clarity, for a change.

Rather, I'm about to tell you the sad story of how creating PyPy virtualenvs under Ubuntu is ... not so imple.

So, I began by installing PyPy3, as per instructions, disregarding the warning about outdated PPA.

% sudo add-apt-repository ppa:pypy/ppa
% sudo apt update
% sudo apt install pypy3

Then a check:

% pypy3 -V
Python 3.6.9 (7.3.1+dfsg-4~ppa1~ubuntu18.04, Apr 23 2020, 03:04:13)
[PyPy 7.3.1 with GCC 7.5.0]

Okay, all went swimmingly well, so far.

So next, I try to create a virtualenv:

% pypy3 -m venv nikola-py3-01
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python-pip-whl
package using the following command.

    apt-get install python-pip-whl

You may need to use sudo with that command.  After installing the
python-pip-whl package, recreate your virtual environment.

Failing command: ['/home/pepoluan/Venvs/nikola-py3-01/bin/pypy3-c', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Oookay. Ungood.

Wait, it suggested a package... let's try installing that:

% sudo apt install python-pip-whl
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-pip-whl is already the newest version (9.0.1-2.3~ubuntu1.18.04.1).
python-pip-whl set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Doubly ungood. That means the package was already installed, and thus the previous error was not caused by that missing package.

Not knowing what to do, I install Ubuntu's virtualenv package, which supports the -p option to specify which Python interpreter I want to use.

% sudo apt install virtualenv

No problem there, so let's try:

% virtualenv -p $(which pypy3) pypy3-7.3.6
% source pypy3-7.3.6/bin/activate
% python -V
Python 3.6.9 (7.3.1+dfsg-1~ppa1~ubuntu18.04, Apr 11 2020, 00:13:00)
[PyPy 7.3.1 with GCC 7.5.0]

Yaay! It works! So let's use the virtualenv-ed PyPy to create a virtualenv for Nikola.

% python -m venv nikola-py3-03
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python-pip-whl
package using the following command.

    apt-get install python-pip-whl

You may need to use sudo with that command.  After installing the
python-pip-whl package, recreate your virtual environment.

Failing command: ['/home/pepoluan/Venvs/nikola-py3-03/bin/pypy3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Ugh, same error.

Those of you already saw my stupidity at this point, please hold back your snickering at this time. I promise I'll give you a chance to laugh out loud.

So, a bit miffed at this point, I noticed at the Nikola installation guide, there's a package that I probably missed: python3-venv

Okay, let's try:

% sudo apt install python3-venv
... some output as APT installed the package ...
% pypy3 -m venv nikola-py3-05
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python-pip-whl
package using the following command.

    apt-get install python-pip-whl

You may need to use sudo with that command.  After installing the
python-pip-whl package, recreate your virtual environment.

Failing command: ['/home/pepoluan/Venvs/nikola-py3-05/bin/pypy3-c', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Okay, so you've held back your laugh as I requested? Now, feel free to laugh your arses off.

Yeah, stupid me.

Why should I rely on pypy -m venv if virtualenv already works perfectly.

Back to square ... uh two? Anyways:

% virtualenv -p $(which pypy3) nikola-py3-06
Running virtualenv with interpreter /usr/bin/pypy3
Using base prefix '/usr/lib/pypy3'
New pypy executable in /home/pepoluan/Venvs/nikola-py3-06/bin/pypy3
Also creating executable in /home/pepoluan/Venvs/nikola-py3-06/bin/pypy
Installing setuptools, pkg_resources, pip, wheel...done.

% source nikola-py3-06/bin/activate
% python -V
Python 3.6.9 (7.3.1+dfsg-4~ppa1~ubuntu18.04, Apr 23 2020, 03:04:13)
[PyPy 7.3.1 with GCC 7.5.0]

There is joy in Mudville!! Yay!!!

Moral of the Story, Folks:

Don't be so focused on a procedure (in this case, pypy3 -m venv ...) that you totally overlook a different way to achieve your goal (sudo apt install virtualenv + virtualenv -p ...)