Solving virtualenv Error while finding spec for ‘virtualenvwrapper.hook_loader’ (: No module named ‘virtualenvwrapper’)

Virtualenv Error while finding spec for ‘virtualenvwrapper.hook_loader’ (: No module named ‘virtualenvwrapper’) is a very popular python and virtualenv error which occurs when you use virtualenvwrapper.

I will explain why this error is taking place and how to fix it, while also trying to add other solutions that could help us solve the problem.

Exploring the virtualenv Error while finding spec for ‘virtualenvwrapper.hook_loader’ (: No module named ‘virtualenvwrapper’)

The error is a very popular python and virtualenv error which occurs when you use virtualenvwrapper.

Beware of mixing between different errors. Please make sure you are dealing with the same error.

                                                                       #
Error while finding spec for 'virtualenvwrapper.hook_loader' (<class 'ImportError'>: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.
                                                                       #

Bellow we will describe how the error can be solved. With multiple possible solutions.

Solution 1 : edit the ~/.bashrc file when using virtualenvwrapper

We have already established the fact that this is a python and virtualenv error that occurs when you use virtualenvwrapper.

There are many ways to fix the problem, the best option is to edit the ~/.bashrc file. By making sure, the line bellow

                                                                       #
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
                                                                       #

is replaced by this line. Make sure you put your version of python there.

                                                                       #
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.9
                                                                       #

If that does not work, try using only python3 instead of python3.9 for example.

I hope this method helped you get rid of the error. Try the second method if this one fails.

Solution 2 : install virtualenv and virtualenvwrapper before sourcing using : source $HOME/.bashrc

The second method is a step by step method.

First, we should start by running the command bellow

                                                                       #
sudo apt-get install python3-pip
                                                                       #

Then we should use pip3 to install both virtualenvwrapper and virtualenv

                                                                       #
sudo pip3 install virtualenv virtualenvwrapper
                                                                       #

If go through this entire method and it does not work, please try again and replace the command above with the command bellow instead.

                                                                       #
sudo pip install virtualenv virtualenvwrapper
                                                                       #

Finally, you should run this command

                                                                       #
source $HOME/.bashrc 
                                                                       #

I hope your error is fixed, if not I have another method for you.

Solution 3 : A Combination of the two previous methods

The third method is a mix between the two methods above.

Basically you should follow the steps in Method 2 without using this command.

                                                                       #
source $HOME/.bashrc 
                                                                       #

Then run the commands in Method 1 , if you did that and nothing has changed.

Try again, but now include the command bellow as the last command of the whole process.

                                                                       #
source $HOME/.bashrc 
                                                                       #

I hope this Method and the other methods have solved your problem, thank you for reading this post to the end.

Summing-up : 

The solutions above should be enough to solve your problem, I hope the article helped you get rid of the issue, please keep learning, keep coding and cheers.

Thank you for reading, keep coding and cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/