python-2.7debian-bookworm

How to install python2 virtualenv in debian 12


I found a problem to install pyton2 virtualenv in debian 12.

To install python2 on debian 12 next command can be used:

sudo apt-get install python2

But virtualenv exists only python3-virtualenv

If try use: virtualenv -p /usr/bin/python py2venv Will raised error:

Exception: Wheel for wheel for Python 2.7 is unavailable. apt install python2-wheel-whl

If install virtualenv by pip it return:

error: externally-managed-environment

So it is not obvious how to install python 2 virtualenv on debian 12.


Solution

  • Solution:

    1. remove python3-virtualenv

      sudo apt-get purge python3-virtualenv

    2. sudo apt-get install python2

    3. Install virtualenv version <= 20.21.1.

      sudo pip install virtualenv==20.21.1 --break-system-packages

      Instead --break-system-packages, can be used:

    After virtualenv -p /usr/bin/python2 py2venv

    should work.

    Addition: As @matt noted debian 12 droped python2 support at all, so python distribution should be installed from debian 11 distro or conda is used.