pypa / packaging-problems

An issue tracker for the problems in packaging
151 stars 35 forks source link

NameError 'cmd' is not defined when building package #641

Closed Enderbyte09 closed 1 year ago

Enderbyte09 commented 1 year ago

Problem description

I am trying to build by first package. However, when I run python3 -m build, I get a NameError that cmd is not defined.

Here is the full command output


* Creating venv isolated environment...

Traceback (most recent call last):
  File "/usr/lib/python3.10/venv/__init__.py", line 329, in _setup_pip
    self._call_new_python(context, '-m', 'ensurepip', '--upgrade',
  File "/usr/lib/python3.10/venv/__init__.py", line 324, in _call_new_python
    subprocess.check_output(args, **kwargs)
  File "/usr/lib/python3.10/subprocess.py", line 421, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.10/subprocess.py", line 526, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/build-env-uvrk3vkh/bin/python3', '-m', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/__main__.py", line 375, in main
    built = build_call(
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/__main__.py", line 235, in build_package_via_sdist
    sdist = _build(isolation, builder, outdir, 'sdist', config_settings, skip_dependency_check)
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/__main__.py", line 145, in _build
    return _build_in_isolated_env(builder, outdir, distribution, config_settings)
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/__main__.py", line 109, in _build_in_isolated_env
    with _IsolatedEnvBuilder() as env:
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/env.py", line 107, in __enter__
    executable, scripts_dir = _create_isolated_env_venv(self._path)
  File "/home/enderbyte09/.local/lib/python3.10/site-packages/build/env.py", line 272, in _create_isolated_env_venv
    venv.EnvBuilder(with_pip=True, symlinks=symlinks).create(path)
  File "/usr/lib/python3.10/venv/__init__.py", line 75, in create
    self._setup_pip(context)
  File "/usr/lib/python3.10/venv/__init__.py", line 345, in _setup_pip
    """.format(sysconfig.get_python_version(), cmd))
NameError: name 'cmd' is not defined

ERROR name 'cmd' is not defined
henryiii commented 1 year ago

Can you try installing virtualenv too? I bet that will just cause it to work, as that looks like something is wrong with venv ensurepip, which is built into Python. Looking at /usr/lib/python3.10/venv/__init__.py to see how you can get to that line without defining cmd would be interesting. What system are you on? Exactly what version of Python is that? 3.10.what?

Ahh, wasn't reading the exception correctly, ensurepip (also a standard library module) is not able to get pip.

Enderbyte09 commented 1 year ago

I am on Kubuntu 23.04 Beta, with Python 3.10.9. Indeed, venv was the issue and reinstalling virtualenv somehow fixed it. Repeated apologies for clogging up issues.

henryiii commented 1 year ago

virtualenv is used instead of venv if it's present. My guess is ubuntu is messing with these files as usual (that's not the actual line number in the CPython venv source for 3.10.9), so they've broken venv. Debian strips out ensurepip, so they are doing something to cause venv to not use it (which obviously is currently broken). You might want to raise an issue before 23.04 final ships. :)