pipenv: `pipenv install` errors out with `ModuleNotFoundError: No module named 'distutils.cmd'` even though it is present on the system
Hi,
while running pipenv install
, I get a long list of errors, but I think the most important one is the following few lines:
[pipenv.exceptions.InstallError]: Traceback (most recent call last):
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/__pip-runner__.py", line 50, in <module>
[pipenv.exceptions.InstallError]: runpy.run_module("pip", run_name="__main__", alter_sys=True)
[pipenv.exceptions.InstallError]: File "/usr/lib/python3.9/runpy.py", line 225, in run_module
[pipenv.exceptions.InstallError]: return _run_module_code(code, init_globals, run_name, mod_spec)
[pipenv.exceptions.InstallError]: File "/usr/lib/python3.9/runpy.py", line 97, in _run_module_code
[pipenv.exceptions.InstallError]: _run_code(code, mod_globals, init_globals,
[pipenv.exceptions.InstallError]: File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
[pipenv.exceptions.InstallError]: exec(code, run_globals)
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/__main__.py", line 35, in <module>
[pipenv.exceptions.InstallError]: spec.loader.exec_module(pipenv)
[pipenv.exceptions.InstallError]: File "<frozen importlib._bootstrap_external>", line 850, in exec_module
[pipenv.exceptions.InstallError]: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/__init__.py", line 63, in <module>
[pipenv.exceptions.InstallError]: from .cli import cli
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/cli/__init__.py", line 1, in <module>
[pipenv.exceptions.InstallError]: from .command import cli # noqa
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/cli/command.py", line 7, in <module>
[pipenv.exceptions.InstallError]: from pipenv.cli.options import (
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/cli/options.py", line 3, in <module>
[pipenv.exceptions.InstallError]: from pipenv.project import Project
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/project.py", line 19, in <module>
[pipenv.exceptions.InstallError]: from pipenv.environment import Environment
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/environment.py", line 17, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.commands.install import InstallCommand
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/commands/__init__.py", line 9, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.cli.base_command import Command
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/cli/base_command.py", line 15, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.cli import cmdoptions
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/cli/cmdoptions.py", line 24, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.cli.parser import ConfigOptionParser
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/cli/parser.py", line 12, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.configuration import Configuration, ConfigurationError
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/configuration.py", line 26, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.utils.logging import getLogger
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/utils/logging.py", line 29, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.utils.misc import ensure_dir
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/utils/misc.py", line 42, in <module>
[pipenv.exceptions.InstallError]: from pipenv.patched.pip._internal.locations import get_major_minor_version
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/locations/__init__.py", line 67, in <module>
[pipenv.exceptions.InstallError]: from . import _distutils
[pipenv.exceptions.InstallError]: File "/usr/lib/python3/dist-packages/pipenv/patched/pip/_internal/locations/_distutils.py", line 20, in <module>
[pipenv.exceptions.InstallError]: from distutils.cmd import Command as DistutilsCommand
[pipenv.exceptions.InstallError]: ModuleNotFoundError: No module named 'distutils.cmd'
I have searched for the common causes of this and I can say the following:
- I have
python3-distutils
andpython3-apt
installed, I also tried reinstalling them - I can import the
distutils
module from my system python:❯ python3 Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from distutils.cmd import Command >>>
- I can also import the
distutils
module frompipenv shell
:❯ python Python 3.9.13 (main, Jun 8 2022, 09:45:57) [GCC 11.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from distutils.cmd import Command >>>
So… What gives? The module is obviously there, but somehow pipenv cannot find it
Please run $ pipenv --support
, and paste the results here. Don’t put backticks (`
) around it! The output already contains Markdown formatting.
If you’re on Linux, run the following:
$ pipenv --support
Pipenv version: '2022.12.19'
Pipenv location: '/usr/lib/python3/dist-packages/pipenv'
Python location: '/usr/bin/python3'
OS Name: 'posix'
User pip version: '22.3.1'
user Python installations found:
3.11.2
:/usr/bin/python3
3.11.2
:/bin/python3
3.9.13
:/usr/bin/python3.9
3.9.13
:/bin/python3.9
3.8.5
:/opt/miniconda3/bin/python3
3.8.5
:/opt/miniconda3/bin/python3.8
3.8.5
:/opt/miniconda3/bin/python
2.7.18
:/usr/bin/python2
2.7.18
:/usr/bin/python2.7
2.7.18
:/bin/python2
2.7.18
:/bin/python2.7
PEP 508 Information:
{'implementation_name': 'cpython',
'implementation_version': '3.11.2',
'os_name': 'posix',
'platform_machine': 'x86_64',
'platform_python_implementation': 'CPython',
'platform_release': '6.1.0-7-amd64',
'platform_system': 'Linux',
'platform_version': '#1 SMP PREEMPT_DYNAMIC Debian 6.1.20-2 (2023-04-08)',
'python_full_version': '3.11.2',
'python_version': '3.11',
'sys_platform': 'linux'}
System environment variables:
ALACRITTY_LOG
ALACRITTY_SOCKET
ALACRITTY_WINDOW_ID
ANDROID_HOME
COLORTERM
CONDA_DEFAULT_ENV
CONDA_EXE
CONDA_PREFIX
CONDA_PROMPT_MODIFIER
CONDA_PYTHON_EXE
CONDA_SHLVL
DBUS_SESSION_BUS_ADDRESS
DESKTOP_SESSION
DISPLAY
EDITOR
GDMSESSION
GDM_LANG
GIO_LAUNCHED_DESKTOP_FILE
GIO_LAUNCHED_DESKTOP_FILE_PID
GJS_DEBUG_OUTPUT
GJS_DEBUG_TOPICS
GNOME_DESKTOP_SESSION_ID
GNOME_SETUP_DISPLAY
GTK_MODULES
HOME
INVOCATION_ID
JOURNAL_STREAM
JULIA_NUM_THREADS
LANG
LANGUAGE
LC_MEASUREMENT
LC_MONETARY
LC_NUMERIC
LC_PAPER
LC_TIME
LESS
LOGNAME
LSCOLORS
LS_COLORS
MANAGERPID
MOZ_ENABLE_WAYLAND
OLDPWD
P9K_TTY
PAGER
PATH
POWERLINE_COMMAND
PWD
QTWEBENGINE_DICTIONARIES_PATH
QT_ACCESSIBILITY
QT_IM_MODULE
SESSION_MANAGER
SHELL
SHLVL
SKIM_CTRL_T_COMMAND
SKIM_DEFAULT_COMMAND
SSH_AGENT_LAUNCHER
SSH_AUTH_SOCK
SYSTEMD_EXEC_PID
TERM
TERM_PROGRAM
TERM_PROGRAM_VERSION
TMUX
TMUX_PANE
TMUX_PLUGIN_MANAGER_PATH
USER
USERNAME
VISUAL
WAYLAND_DISPLAY
WINDOWID
XAUTHORITY
XDG_CURRENT_DESKTOP
XDG_MENU_PREFIX
XDG_RUNTIME_DIR
XDG_SESSION_CLASS
XDG_SESSION_DESKTOP
XDG_SESSION_TYPE
XMODIFIERS
ZSH
_
_CE_CONDA
_CE_M
_P9K_SSH_TTY
_P9K_TTY
is_vim
P9K_SSH
PIP_DISABLE_PIP_VERSION_CHECK
PIP_PYTHON_PATH
PYTHONDONTWRITEBYTECODE
PYTHONFINDER_IGNORE_UNSUPPORTED
Pipenv–specific environment variables:
Debug–specific environment variables:
PATH
:/home/user/.local/bin:/opt/miniconda3/bin:/opt/miniconda3/condabin:/home/user/.local/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
SHELL
:/bin/zsh
EDITOR
:nvim
LANG
:en_US.UTF-8
PWD
:/home/user/project
Contents of Pipfile
(‘/home/user/project/Pipfile’):
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[[source]]
name = "redacted"
url = "redacted"
verify_ssl = true
[dev-packages]
notebook = "== 6.4.12"
jupyterhub = "== 1.5.0"
jupyterlab = "== 3.3.2"
dask-labextension = "== 5.2.0"
bokeh = "== 2.4.3"
ipywidgets = "== 7.7.0"
# Research
matplotlib = "*"
scikit-learn = "*"
scipy = "*"
cryptography = ">=38.0.3"
[packages]
## DASK
kubernetes = "== 17.17.0"
dask = { extras = ["complete", "dataframe"], version = "== 2022.09.2" }
dask-kubernetes = "== 2022.9.0"
distributed = "== 2022.09.2"
click = "== 8.0.2"
# Research
aiohttp = ">=3.7.4"
fastparquet = "*"
python-snappy = "*"
pandas = "1.5.0"
pyarrow = "*"
pyathena = "*"
pytest = "*"
pytest-cov = "*"
pytest-mock = "*"
s3fs = "*"
smart_open = "*"
numpy = "*"
hypothesis = "*"
threatqsdk = { version = "*", index = "cognitive-intelligence" }
vt-py = "==0.17.3"
tldextract = "*"
aiofiles = "*"
pytest-asyncio = "*"
[requires]
python_version = "3.9"
#TODO: doens't work with jupyterhub
[pipenv]
allow_prereleases = false
Contents of Pipfile.lock
(‘/home/user/project/Pipfile.lock’):
{
"_meta": {
"hash": {
"sha256": "d743e6571b658ebc0baf48d5cc01fe2170bd3f490330ab917bec86b7c763e859"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.9"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
},
{
"name": "redacted",
"url": "redacted",
"verify_ssl": true
}
]
},
"default": {
}
}
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 1
- Comments: 18 (7 by maintainers)
I had a similar issue with
v2023.6.18
andv2023.6.12
both failing whilev2023.6.11
worked. It may be unrelated to your issue but I eventually tracked it down to another pipenv install in my environment. The removal of thesys.path
manipulation in 1cc03eaa3b13114fca0d84fcad25148f71f413ff exposes pipenv to issues with module resolution confusion.I’m suspecting that
pipenv
is importing a module from a different install which is resulting in the downstream errors - this snippet in particularthere looks like there could be 2 different venvs involved
and
In my case, I had a global
pipenv
install in mypython 3.11
and another install inpython 3.7
- runningpipenv
from apython 3.7
venv was using the install from thepython 3.11
but resolving internal pipenv modules from thepython 3.7
installHaving exactly the same issue, can someone help with this?
Doesn’t help 😦