From 257deabbbeee8ae070658bc08bcb519a3b9d306a Mon Sep 17 00:00:00 2001 From: Manuel McLure Date: Sat, 10 Oct 2020 14:30:29 -0700 Subject: [PATCH] Improve detection of virtual env. --- AUTHORS.md | 1 + src/octoprint/util/pip.py | 4 +++- src/octoprint/util/piptestballoon/setup.py | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 57335f17c..2e4c54f02 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -128,6 +128,7 @@ date of first contribution): * [Charlie Powell](https://github.com/cp2004) * [Ollis Git](https://github.com/OllisGit) * [Sophist](https://github.com/Sophist-UK) + * [Manuel McLure](https://github.com/ManuelMcLure) OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by [Daid Braam](https://github.com/daid). Parts of its communication layer and diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 92fbf1203..53ff20a14 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -544,7 +544,9 @@ class LocalPipCaller(PipCaller): import sys from distutils.sysconfig import get_python_lib - virtual_env = hasattr(sys, "real_prefix") + virtual_env = hasattr(sys, "real_prefix") or ( + hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix + ) install_dir = get_python_lib() writable = os.access(install_dir, os.W_OK) diff --git a/src/octoprint/util/piptestballoon/setup.py b/src/octoprint/util/piptestballoon/setup.py index 90d2c9098..036d9a56f 100644 --- a/src/octoprint/util/piptestballoon/setup.py +++ b/src/octoprint/util/piptestballoon/setup.py @@ -29,7 +29,9 @@ def produce_output(stream): cmd.finalize_options() install_dir = cmd.install_lib - virtual_env = hasattr(sys, "real_prefix") + virtual_env = hasattr(sys, "real_prefix") or ( + hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix + ) writable = os.access(install_dir, os.W_OK) lines = [