Installing venv for python3 in WSL (Ubuntu)

Nothing here worked for me, but this did in WSL2:

sudo apt-get update
sudo apt-get install libpython3-dev
sudo apt-get install python3-venv
python3.8 -m venv whatever

Good luck!

The error occurs when you're in /mnt/XXX (under Windows part).

Switch to Linux part by cd and run python3 -m venv ./venv again and that should be fine

This was more of a headache than it needed to be. It seems that it relates to WSL<->Windows file system mapping issues. This blog post perhaps describes it better, but the net is you need to store additional metadata with files on a particular mount, as described in this MS devblog.

I fixed the issue by running:

sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata

After which I was able to create python venv without needing to sudo.

Give this approach a shot:

Install the pip:

sudo apt-get install python-pip

Install the virtual environment:

sudo pip install virtualenv

Store your virtual environments somewhere:

mkdir ~/.storevirtualenvs

Now you should be able to create a new virtualenv

virtualenv -p python3 yourVenv

To activate:

source yourVenv/bin/activate

To exit your new virtualenv, just deactivate