Skip to content

Fix NameError exception in venv init

If python3.11-venv package is not installed, the following incorrect error message is printed when creating a virtual environment:

  $ python3.11 -m venv my-venv
  Error: name 'cmd' is not defined

This happens because of a typo in which 'cmd' is used as a local variable instead of the attribute of the CalledProcessError exception. Please see reference here: https://docs.python.org/3/library/subprocess.html#subprocess.CalledProcessError.cmd

With this fix, the correct error message gets printed:

  The virtual environment was not created successfully because ensurepip is not
  available.  On Debian/Ubuntu systems, you need to install the python3-venv
  package using the following command.

      apt install python3.11-venv

  You may need to use sudo with that command.  After installing the python3-venv
  package, recreate your virtual environment.

  Failing command: ['/home/penlect/my-venv/bin/python3.11', '-m', 'ensurepip', '--upgrade', '--default-pip']

Merge request reports

Loading