pipx: ModuleNotFoundError: No module named 'pip._vendor.six' when running "pipx install"

Describe the bug

I have installed a new Debian (unstable) system. On one of my installations pipx runs without problems. The newly installed system behaves differently and I do not know where to look.

How to reproduce

$ pipx install --verbose youtube-dl
pipx > (_package_name_from_spec:93): Determined package name: youtube-dl
pipx > (_package_name_from_spec:94): Package name determined in 0.0s
pipx > (run_subprocess:112): running /usr/bin/python3 -m venv --without-pip /home/kai/.local/pipx/venvs/youtube-dl
pipx > (run_subprocess:112): running /home/kai/.local/pipx/venvs/youtube-dl/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx > (run_subprocess:112): running /home/kai/.local/pipx/shared/bin/python -c import sysconfig; print(sysconfig.get_path('purelib'))
pipx > (run_subprocess:112): running /home/kai/.local/pipx/venvs/youtube-dl/bin/python --version
pipx > (run_subprocess:112): running /home/kai/.local/pipx/venvs/youtube-dl/bin/python -m pip install youtube-dl
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/__main__.py", line 16, in <module>
    from pip._internal.cli.main import main as _main  # isort:skip # noqa
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 10, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
    from pip._internal.cli import cmdoptions
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
    from pip._internal.exceptions import CommandError
  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/exceptions.py", line 10, in <module>
    from pip._vendor.six import iteritems
ModuleNotFoundError: No module named 'pip._vendor.six'
pipx > (install_package:189): '/home/kai/.local/pipx/venvs/youtube-dl/bin/python -m pip install youtube-dl' failed

pipx > (rmdir:18): removing directory /home/kai/.local/pipx/venvs/youtube-dl
Error installing youtube-dl.

If I run python3 from the command line I can import the module:

$ python3 -c "import pip._vendor.six"
$

I have no idea what could be different. I already checked the list of python3-* packages on both systems but that seems to be the same. Any idea what to look for or how to debug the issue?

Expected behavior

The package should be installed.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 34 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Just want to add that I had this problem when installed python3.9, migrating form 3.8. (not on debian) Installing 3.9 made my existing virtual envs not work, and I got this error. Completely removing ~/.local/pipx, then reinstalling my pipx things solved the problem.

Workaround for poor new Ubuntu 20.04 LTS users like little old me:

$ ~/.local/pipx/shared/bin/pip install -I pip

This installs the upstream version of pip 20.0.2 in the shared venv, instead of the patched Debian version of pip 20.0.2.

I imagine when upstream pip releases 20.0.3, this problem will go away on its own, because I expect pipx will keep pip upgraded, while Debian won’t.

Same on Ubuntu 20.04… So we cannot use pipx until Debian team update something? With Debian it can take a while, I’m not even sure my grand childrens will see it.

Generally I recommend people to leave Debian’s Python alone, and install a separate Python to do their work, e.g. pyenv. This would save you endless headaches if you want to stick with Debian for the long run.

Thank you for the suggestion, that’s a good solution for anyone who is blocked at the moment. However one of the reasons I really liked pipsi and decided to pursue pipx was the idea that you could install things with as little hassle as possible. I was trying to ship an app with Python and my user instructions always felt so ridiculous (create a venv, install it there…). Even if one is not necessarily a Python developer they should be able to take advantage of the ecosystem. It’s unfortunate that there is still no good story around this, and requiring casual users who want to use a Python “app” to mess with pyenv is still too high a bar, IMO.

Given the large userbase of Debian/Ubuntu (I am one of them but I guess I haven’t been bit by this because I haven’t upgraded), this will impact a lot of people, so I think it’s worth it to build support into pipx to work around whatever they are doing.

Just an update that this issue (filed as Debian Bug #958764) has now been fixed by in the latest python3-pip package in Debian Unstable (Version: 20.1-1). The patch of interest for Debian derivatives entails switching to using sys.base_prefix in place of sys.prefix for the unbundling logic, see this commit.

Same issue here when using pyenv and pipenv:

[pipenv.exceptions.InstallError]: from pip._vendor.six import iteritems [pipenv.exceptions.InstallError]: ModuleNotFoundError: No module named ‘pip._vendor.six’ ERROR: Couldn’t install package: certifi

When preparing to use pyenv, I mistakenly included python3-dev during apt install. This apparently installs a local version of pip which leads to a conflict of some kind when running pipenv install ....

I resolved the issue by removing python3-dev and installing the necessary packages separately:

# remove python3-dev
sudo apt remove python3-dev

# re-add packages needed for compiling python
# from:
# https://devguide.python.org/setup/
sudo apt-get install build-essential gdb lcov libbz2-dev libffi-dev \
      libgdbm-dev liblzma-dev libncurses5-dev libreadline6-dev \
      libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev

After cleaning this up I was able to run pipenv install .. as expected.

Examine the pip in your pipx shared environment. If it looks like this:

$ grep -B4  ^WHEEL_DIR ~/.local/pipx/shared/lib/python3.8/site-packages/pip/_vendor/__init__.py
# wish to create their own Wheels for our dependencies to aid in debundling.
prefix = sys.prefix
if sys.prefix.startswith('/usr/lib/pypy'):
    prefix = '/usr'
WHEEL_DIR = os.path.abspath(os.path.join(prefix, 'share', 'python-wheels'))

Then that’s the one from Debian. The relevant code in the wheel for pip on PyPI looks like this:

grep -B4  ^WHEEL_DIR pip/_vendor/__init__.py
# By default, look in this directory for a bunch of .whl files which we will
# add to the beginning of sys.path before attempting to import anything. This
# is done to support downstream re-distributors like Debian and Fedora who
# wish to create their own Wheels for our dependencies to aid in debundling.
WHEEL_DIR = os.path.abspath(os.path.dirname(__file__))

I had the same issue to report here, and tracked it down to the fact that venv is passed the --without-pip flag. If I take that flag away (which is how the previous version of pipx that’s currently in Debian - 0.12.3.1- used to work) - then pipx and pip are all happy.

This is because Debian patches pip and

$ python3 -c "import pip._vendor as v; print(v.DEBUNDLED)"
True

On import of pip._vendor, a bunch of the wheel contents for these debundled dependencies get added to sys.path. $ python3 -c "import sys; print(sys.path); import pip._vendor; print(sys.path)"

[‘’, ‘/usr/lib/python38.zip’, ‘/usr/lib/python3.8’, ‘/usr/lib/python3.8/lib-dynload’, ‘/home/pi/.local/lib/python3.8/site-packages’, ‘/home/pi/code/pipx2/src’, ‘/usr/local/lib/python3.8/dist-packages’, ‘/usr/lib/python3/dist-packages’, ‘/usr/lib/python3.8/dist-packages’] [‘/usr/share/python-wheels/distro-1.4.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/setuptools-44.0.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/pyparsing-2.4.6-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/progress-1.5-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/packaging-20.3-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/retrying-1.3.3-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/pip-20.0.2-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/CacheControl-0.12.6-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/lockfile-0.12.2-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/webencodings-0.5.1-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/contextlib2-0.6.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/urllib3-1.25.8-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/distlib-0.3.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/six-1.14.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/colorama-0.4.3-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/chardet-3.0.4-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/html5lib-1.0.1-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/msgpack-0.6.2-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/wheel-0.34.2-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/certifi-2019.11.28-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/pytoml-0.1.21-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/pep517-0.8.2-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/appdirs-1.4.3-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/requests-2.23.0-py2.py3-none-any.whl’, ‘/usr/share/python-wheels/idna-2.8-py2.py3-none-any.whl’, ‘’, ‘/usr/lib/python38.zip’, ‘/usr/lib/python3.8’, ‘/usr/lib/python3.8/lib-dynload’, ‘/home/pi/.local/lib/python3.8/site-packages’, ‘/home/pi/code/pipx2/src’, ‘/usr/local/lib/python3.8/dist-packages’, ‘/usr/lib/python3/dist-packages’, ‘/usr/lib/python3.8/dist-packages’]

(Shameless plug)

I have looked at pyenv instructions several times over the years, and readme always scares me away. I just go to python.org and install from there and things always work fine.

I have a tool that strips with shell script shim thing, which hopefully makes it more approachable 🙂

https://github.com/uranusjr/pythonup-posix

Thanks for the advise. I’ve installed python rom the source code on my ubuntu 20.04.

I have updated with sudo update-alternatives --config python3

python3 --version

Then I installed pipx with sudo pip3 install pipx

And now when I try to install something

pipx install ansible  
/home/nico/.local/pipx/venvs/ansible/bin/python: No module named pip

Do you have an idea what is missing here? Thanks for your help.

WHat would be the best way to repair the pip installation in this case? Would pipx re-build the shared lib directory if we delete it?

Yes, you can erase the dir and pipx will recreate it.

https://github.com/pipxproject/pipx/blob/master/src/pipx/shared_libs.py#L38 https://github.com/pipxproject/pipx/blob/master/src/pipx/shared_libs.py#L32

This looks like a problem with pip to me. For some reason pip is looking for a submodule that is not installed.

  File "/home/kai/.local/pipx/shared/lib/python3.8/site-packages/pip/_internal/exceptions.py", line 10, in <module>
    from pip._vendor.six import iteritems
ModuleNotFoundError: No module named 'pip._vendor.six'

I don’t think this is a pipx error, but looks to me like a problem with the pip installation on that system.