pipenv ImportError: cannot import name 'InstallCommand'
Symptom
# pipenv install
Creating a virtualenv for this project...
Pipfile: /root/aa/Pipfile
Using /usr/bin/python3 (3.6.8) to create virtualenv...
⠴ Creating virtual environment...created virtual environment CPython3.6.8.final.0-64 in 247ms
creator CPython3Posix(dest=/root/.local/share/virtualenvs/aa-U57avQvB, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==21.3.1, setuptools==59.6.0, wheel==0.37.1
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
✔ Successfully created virtual environment!
Virtualenv location: /root/.local/share/virtualenvs/aa-U57avQvB
Creating a Pipfile for this project...
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 8, in
sys.exit(cli())
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/cli/options.py", line 56, in main
return super().main(*args, **kwargs, windows_expand_args=False)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 84, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/cli/command.py", line 241, in install
site_packages=state.site_packages,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1972, in do_install
site_packages=site_packages,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 594, in ensure_project
system=system_or_exists,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 296, in ensure_pipfile
project.create_pipfile(python=python)
File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 682, in create_pipfile
from .vendor.pip_shims.shims import InstallCommand
ImportError: cannot import name 'InstallCommand'
Reason
Latest pipenv
is not backward compatible and this error doesn't show any hint about this.
Solution
Install an older version of pipenv
pip3 install pipenv==2022.3.23