diff --git a/internal/backends/python/python.go b/internal/backends/python/python.go index 7df1f080..bd089a4a 100644 --- a/internal/backends/python/python.go +++ b/internal/backends/python/python.go @@ -284,6 +284,11 @@ func makePythonPoetryBackend(python string) api.LanguageBackend { return venv } + // Take PYTHONUSERBASE into consideration, if set + if userbase := os.Getenv("PYTHONUSERBASE"); userbase != "" { + return userbase + } + // Terminate early if we're running inside a repl. // This will suppress the following poetry commands // from showing up in the Packager pane. @@ -417,9 +422,14 @@ func makePythonPipBackend(python string) api.LanguageBackend { return venv } + // Take PYTHONUSERBASE into consideration, if set + if userbase := os.Getenv("PYTHONUSERBASE"); userbase != "" { + return userbase + } + if outputB, err := util.GetCmdOutputFallible([]string{ "python", - "-c", "import site; print(site.USER_SITE)", + "-c", "import site; print(site.USER_BASE)", }); err == nil { return string(outputB) } diff --git a/internal/cli/cmds.go b/internal/cli/cmds.go index de10c8bf..338333dd 100644 --- a/internal/cli/cmds.go +++ b/internal/cli/cmds.go @@ -247,7 +247,11 @@ func maybeInstall(ctx context.Context, b api.LanguageBackend, forceInstall bool) if !util.Exists(b.Specfile) { return } - if forceInstall || store.HasSpecfileChanged(b) { + var needsPackageDir bool + if packageDir := b.GetPackageDir(); packageDir != "" { + needsPackageDir = !util.Exists(packageDir) + } + if forceInstall || store.HasSpecfileChanged(b) || needsPackageDir { b.Install(ctx) } }