3

After upgrading from Ubuntu 20.04 to 22.04 I get this error whenever I open a terminal:

    /usr/bin/python3: Error while finding module specification for 'virtualenvwrapper.hook_loader' (ModuleNotFoundError: No module named 'virtualenvwrapper')
virtualenvwrapper.sh: There was a problem running the initialization hooks.

If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH is set properly.

This is what is in my ~/.bashrc file:

#Virtualenvwrapper settings:
export WORKON_HOME=$HOME/.virtualenvs
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
. /usr/local/bin/virtualenvwrapper.sh

I note there is a space after the dot on the last line. Should that be there?

mike@orac:/usr/bin$ ls -la /usr/bin/python3
lrwxrwxrwx 1 root root 10 Aug 18 22:39 /usr/bin/python3 -> python3.10

Edit:

After upgrading to 24.04 this solution no longer works:

root@orac:~# pip3 install -U virtualenvwrapper
error: externally-managed-environment

× This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.

If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.

If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

See /usr/share/doc/python3.12/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.

What is the best option? Is virtualenvwrapper a non-Debian-packaged or Debian-packaged application?

Should I do

apt install python3-virtualenvwrapper

or

pipx install virtualenvwrapper

So I went with

sudo apt install virtualenvwrapper

Thank you to itsfoss

Jedi
  • 599

1 Answers1

7

The space after the dot . in:

. /usr/local/bin/virtualenvwrapper.sh

should be there ... That is a way of how a file is sourced ... But, the error:

(ModuleNotFoundError: No module named 'virtualenvwrapper')

Indicates that the module virtualenvwrapper is either not installed or outdated ... You can fix both with:

pip3 install -U virtualenvwrapper

If pip3 isn't installed, install it first with:

sudo apt install python3-pip

Why after the upgrade?

/usr/bin/python3

will always be a symbolic link to the current system python version ... i.e. it will point to the newly upgraded Ubuntu 22.04 python3.10 like so:

ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 10 Aug 18 13:39 /usr/bin/python3 -> python3.10

While it previously pointed to the previous Ubuntu 20.04 python3.8 like so:

ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 10 Aug 18 13:39 /usr/bin/python3 -> python3.8

This change might require reinstalling or upgrading previously installed modules to work correctly with the new system python.

Raffa
  • 34,963