I have this bug too.  Did some digging, the error message is wrong due
to over-zealous assumptions.

In /usr/lib/python3.6/venv/__init__.py:

   def _setup_pip(self, context):
        """Installs or upgrades pip in a virtual environment"""
        # We run ensurepip in isolated mode to avoid side effects from
        # environment vars, the current directory and anything else
        # intended for the global Python environment
        cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
                                                    '--default-pip']
        # Debian 2015-09-18 ba...@debian.org: <python>-venv is a
separate
        # binary package which might not be installed.  In that case,
the
        # following command will produce an unhelpful error.  Let's
make it
        # more user friendly.
        try:
            subprocess.check_output(
                cmd, stderr=subprocess.STDOUT,
                universal_newlines=True)
        except subprocess.CalledProcessError:
                print(...)

So any failure in the command will invoke the error message.

Trying to call the command line given by the `cmd` variable directly
gets me this:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.6/ensurepip/__main__.py", line 5, in <module>
    sys.exit(ensurepip._main())
  File "/usr/lib/python3.6/ensurepip/__init__.py", line 264, in _main
    default_pip=args.default_pip,
  File "/usr/lib/python3.6/ensurepip/__init__.py", line 176, in
_bootstrap
    return _run_pip(args + _PROJECTS, additional_paths)
  File "/usr/lib/python3.6/ensurepip/__init__.py", line 54, in _run_pip
    import pip._internal
ModuleNotFoundError: No module named 'pip._internal'

Looking at /usr/lib/python3.6/ensurepip/__init__.py we see:

def _run_pip(args, additional_paths=None):
    # Add our bundled software to the sys.path so we can import it
    if additional_paths is not None:
        sys.path = additional_paths + sys.path

    # Install the bundled software
    import pip._internal
    return pip._internal.main(args)

Rummaging through /usr/lib/python3/dist-packages/pip/ I don't find an
`_internal` package but I do find a `pip.main()` method, so I just
change the `_run_pip()` function to call that:

def _run_pip(args, additional_paths=None):
    # Add our bundled
software to the sys.path so we can import it
    if additional_paths is
not None:
        sys.path = additional_paths + sys.path

    # Install the bundled software
    import pip
    return pip.main(args)

And everything APPEARS to work with this ugly hack.

Love,
Simon

Reply via email to