pipx
pipx copied to clipboard
failure to canonicalize name results in package installations failing
Describe the bug
Attempting to install anything results in error in name canonicalization.
I've reproduced this issue on with:
- Ubuntu
22.04.4 LTS, using Python3.10.12with pipx1.0.0installed viaapt. - Ubuntu
24.04 LTS, using Python3.12.3with pipx1.4.3installed viaapt. - Ubuntu
24.04 LTS, using Python3.12.3with pipx1.5.0ran with thezipapppackaged pipx.
Note: These reproductions are on the same system. I opted to upgrade my operating system after noticing the insanely low pipx version being offered to 22.04 users.
I have run the Debian/Ubuntu Troubleshooting commands and isolated the issue to pipx by attempting package installation in the test_venv.
How to reproduce
pipx install --verbose poetry:
pipx >(setup:860): pipx version is 1.4.3
pipx >(setup:861): Default python interpreter is '/usr/bin/python3'
pipx >(package_name_from_spec:370): Determined package name: poetry
pipx >(package_name_from_spec:371): Package name determined in 0.0s
creating virtual environment...
pipx >(run_subprocess:168): running /usr/bin/python3 -m venv --without-pip /home/dejay/.local/pipx/venvs/poetry
pipx >(run_subprocess:168): running <checking pip's availability>
pipx >(run_subprocess:168): running /home/dejay/.local/pipx/venvs/poetry/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:168): running /home/dejay/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx >(run_subprocess:168): running /home/dejay/.local/pipx/venvs/poetry/bin/python --version
pipx >(_parsed_package_to_package_or_url:137): cleaned package spec: poetry
installing poetry...
pipx >(run_subprocess:168): running /home/dejay/.local/pipx/venvs/poetry/bin/python -m pip --no-input install poetry
pipx >(run_subprocess:168): running <fetch_info_in_venv commands>
pipx >(rmdir:55): removing directory /home/dejay/.local/pipx/venvs/poetry
Traceback (most recent call last):
File "/usr/bin/pipx", line 8, in <module>
sys.exit(cli())
^^^^^
File "/usr/lib/python3/dist-packages/pipx/main.py", line 921, in cli
return run_pipx_command(parsed_pipx_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pipx/main.py", line 219, in run_pipx_command
return commands.install(
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pipx/commands/install.py", line 91, in install
venv.install_package(
File "/usr/lib/python3/dist-packages/pipx/venv.py", line 256, in install_package
self._update_package_metadata(
File "/usr/lib/python3/dist-packages/pipx/venv.py", line 352, in _update_package_metadata
venv_package_metadata = self.get_venv_metadata_for_package(package_name, get_extras(package_or_url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pipx/venv.py", line 338, in get_venv_metadata_for_package
venv_metadata = inspect_venv(package_name, package_extras, self.bin_path, self.python_path, self.man_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pipx/venv_inspect.py", line 282, in inspect_venv
root_dist = get_dist(root_req.name, venv_inspect_info.distributions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/pipx/venv_inspect.py", line 44, in get_dist
if canonicalize_name(dist.metadata["name"]) == canonicalize_name(package):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/packaging/utils.py", line 47, in canonicalize_name
value = _canonicalize_regex.sub("-", name).lower()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
Expected behavior
Ideally, the package is installed.
Hi @DeJayDev
Seems I can not reproduce the error (Windows 11 + WSL (Ubuntu 22.04) + pipx 1.5.0), is there anything I missed?
Thank you for checking, I'm actually not entirely sure what you could be missing. Typically I don't have any issues with pipx and hoped the trace could give a better idea of where I could start looking?
Actually, I have no idea just from the logs. There could be something wrong with the cache. I would suggest to remove all the installation of pipx managed applications and pipx itself, and then try to delete all the cache used by pipx and pip. If that does not help, we may have to debug into the pipx. It should be something like creating developing environment according to the contribution guide, try to reproduce the error with the cloned repo, and print corresponding information around the traceback.