Bug#1026268: python3.10: `$ python3 -m venv dir` outputs "Error: name 'cmd' is not defined" if python3-venv is not installed.

2023-02-01 Thread Julian Gilbey
tags -1 + patch
thanks

On Sun, Dec 18, 2022 at 01:17:45AM +0900, Yu Sugawara wrote:
> Package: python3.10
> Version: 3.10.9-1
> Severity: normal
> X-Debbugs-Cc: gusmachine+deb...@gmail.com
> 
> Dear Maintainer,
> 
> When I tried to create a python3 venv environment, I got an error message
> "Error: name 'cmd' is not defined" and got partially-created venv environment
> [...]

> I found the following code snippet in /usr/lib/python3.10/venv/__init__.py
> is suspicious. It uses a variable 'cmd' without defining it.
> 
> > def _setup_pip(self, context):
> > [...]
> > Failing command: {}
> > """.format(sysconfig.get_python_version(), cmd))
> > sys.exit(1)

I just hit the same bug, and I think others will if they try to set up
a Python 3.10 venv on bookworm (assuming that Python 3.10 still ships
with bookworm), as there are still many Python packages on PyPI that
do not yet support 3.11.

Simply change the last lines in this quoted section of _setup_pip
to read:

Failing command: {} -m ensurepip --upgrade --default-pip
""".format(sysconfig.get_python_version(), context.env_exec_cmd))
sys.exit(1)

Best wishes,

   Julian



Bug#1026268: python3.10: `$ python3 -m venv dir` outputs "Error: name 'cmd' is not defined" if python3-venv is not installed.

2022-12-17 Thread Yu Sugawara
Package: python3.10
Version: 3.10.9-1
Severity: normal
X-Debbugs-Cc: gusmachine+deb...@gmail.com

Dear Maintainer,

When I tried to create a python3 venv environment, I got an error message
"Error: name 'cmd' is not defined" and got partially-created venv environment.

Steps I did:
- Ran ` $ python3 -m venv venv ` to create a venv directory under the
  current directory, without installing python3-venv.

Expected:
- Have an error message "The virtual environment was not created successfully
  because ensurepip is not available."

Actual:
- Got an error message "Error: name 'cmd' is not defined" instead.

I found the following code snippet in /usr/lib/python3.10/venv/__init__.py
is suspicious. It uses a variable 'cmd' without defining it.

> def _setup_pip(self, context):
> """Installs or upgrades pip in a virtual environment"""
> try:
> self._call_new_python(context, '-m', 'ensurepip', '--upgrade',
>   '--default-pip', stderr=subprocess.STDOUT)
> except subprocess.CalledProcessError:
> stdlib = sysconfig.get_path('stdlib')
> if not os.path.exists(f'{stdlib}/ensurepip/__main__.py'):
> print("""\
> 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 python{}-venv
> 
> You may need to use sudo with that command.  After installing the python3-venv
> package, recreate your virtual environment.
> 
> Failing command: {}
> """.format(sysconfig.get_python_version(), cmd))
> sys.exit(1)

I installed python3-venv and now venv works for me.
But I'd be glad if I could get the correct error message.

Thanks,

-- System Information:
Debian Release: bookworm/sid
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.0.0-5-amd64 (SMP w/8 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages python3.10 depends on:
ii  libpython3.10-stdlib  3.10.9-1
ii  media-types   8.0.0
ii  mime-support  3.66
ii  python3.10-minimal3.10.9-1

python3.10 recommends no packages.

Versions of packages python3.10 suggests:
ii  binutils 2.39.50.20221208-5
pn  python3.10-doc   
ii  python3.10-venv  3.10.9-1

-- no debconf information