2 minute read

The greatest glory in living lies not in never falling, but in rising every time we fall. - Nelson Mandela

Solutions for Configuring Python 3.8 Environment and Resolving Pipenv Errors in WSL2

In the captivating world of programming, environment setup is like a never - ending journey filled with twists and turns. Recently, numerous developers have been on the verge of pulling their hair out due to Pipenv errors while attempting to install and configure the Python 3.8 environment within WSL2. But hold your horses! Today, we’re diving deep into this issue, equipping you with the know - how to sail smoothly through these hurdles.

Preparation Before Environment Setup

The first order of business is to ensure our system is in prime condition. Fire up your WSL2 terminal and execute these two commands:

sudo apt update

sudo apt upgrade -y

Think of this as giving your computer a comprehensive makeover, getting it fully prepped to take on what lies ahead.

Installing Python 3.8

To bring Python 3.8 into the picture, we’ll be calling in the deadsnakes PPA as our trusty sidekick. First, let’s welcome this helper with open arms using these commands:

sudo apt install software-properties-common -y

sudo add-apt-repository ppa:deadsnakes/ppa -y

Once it’s on board, installing Python 3.8 is a breeze:

sudo apt install python3.8 -y

After getting Python 3.8 installed, we need to pair it with its essential companion, pip. Here’s how:

sudo apt install python3.8-distutils -y

wget https://bootstrap.pypa.io/get-pip.py

sudo python3.8 get-pip.py

Voila! Python 3.8 and pip are now ready for action.

Installing and Using Pipenv

Next up, let’s install pipenv using Python 3.8’s pip:

python3.8 -m pip install pipenv

Head over to your project directory and create a virtual environment with Python 3.8 using pipenv:

pipenv --python 3.8

At this stage, you might think everything is going swimmingly. However, when you attempt to run pipenv --python 3.8 install, you could be met with a variety of errors. But don’t fret! We’ll take them on one by one.

Solving Pipenv Error Issues

ModuleNotFoundError: No module named ‘distutils.cmd’

If you encounter the ModuleNotFoundError: No module named 'distutils.cmd' error, resist the urge to hurl your computer across the room. Start by reinstalling the Python 3.8 distutils module. Execute this command:

sudo apt install python3.8-distutils -y

If that doesn’t do the trick, it’s time to check the path of pipenv. Use the which pipenv command to see if it’s pointing to the pipenv in the Anaconda Python 3.11 environment. If it is, reinstall pipenv using Python 3.8’s pip:

python3.8 -m pip install --force-reinstall pipenv

Outdated Pipfile.lock

If you receive a prompt indicating that your Pipfile.lock is outdated, follow the prompt and run the pipenv lock command to update it. Then, give installing the dependencies another shot:

pipenv lock

pipenv install

Cache Issues

Sometimes, cache files can be like little troublemakers in your computer, causing all sorts of chaos. In such cases, we can clear the caches of pip and pipenv and reinstall the dependencies:

python3.8 -m pip cache purge

pipenv --rm

pipenv --python 3.8 install

Conclusion

By following these steps, you should be able to successfully configure the Python 3.8 environment in WSL2 and use pipenv to install your project dependencies. While environment setup can be a real headache at times, with the right approach, you’ll be handling it like a pro. I hope this article has been a great help to you. If so, don’t forget to bookmark and share it! Odds are, your fellow developers are grappling with the same issue.

Updated: