diff --git a/news/5477.bugfix.rst b/news/5477.bugfix.rst new file mode 100644 index 0000000000..e6342dbca8 --- /dev/null +++ b/news/5477.bugfix.rst @@ -0,0 +1 @@ +Check if ``venv`` module is available and fallback to prior logic when it is not. diff --git a/pipenv/core.py b/pipenv/core.py index af1e79255e..771e8eea7b 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -989,15 +989,27 @@ def do_create_virtualenv(project, python=None, site_packages=None, pypi_mirror=N err=True, ) - cmd = [ - Path(sys.executable).absolute().as_posix(), - "-m", - "virtualenv", - "--creator=venv", - f"--prompt={project.name}", - f"--python={python}", - project.get_location_for_virtualenv(), - ] + try: + import venv # noqa + + cmd = [ + Path(sys.executable).absolute().as_posix(), + "-m", + "virtualenv", + "--creator=venv", + f"--prompt={project.name}", + f"--python={python}", + project.get_location_for_virtualenv(), + ] + except ImportError: + cmd = [ + Path(sys.executable).absolute().as_posix(), + "-m", + "virtualenv", + f"--prompt={project.name}", + f"--python={python}", + project.get_location_for_virtualenv(), + ] # Pass site-packages flag to virtualenv, if desired... if site_packages: