Skip to content

isolating Python in conda environments from site-packages #13337

@itcarroll

Description

@itcarroll

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

I am sorry to create a new issue for an old feature request, but it appears that previous issues requesting the same feature have been closed without resolution:

The core problem is that the search path Python uses for packages is configurable, but conda does not leverage that to remove search paths that are outside the conda environment. Many users find the resulting behavior unintuitive, and it is different from the default behavior of Python's venv library for virtual environment creation. So this feature request has two parts

  1. Environment creation needs an argument (default or not, I don't care) analagous to --system-site-packages.
  2. Do it without using PYTHONNOUSERSITE environment variable.

The second part refers to current workarounds including the conda-ecosystem-user-package-isolation package or setting PYTHONNOUSERSITE manually. Here is a case where this workaround is not useful.

A command line tool installed outside a given conda environment using pip install --user, goes in ~/.local/bin/ and includes as its first line #!/path/to/a/python. THAT Python is outside the conda environment, but if PYTHONNOUSERSITE is active for the conda environment, site packages are disabled for ALL Python interpreters. This breaks the command line tool when invoked inside the conda environment.

Although conda does not create a virtual environment (as far as I understand ... and I may not), a pyvenv.cfg file is checked by the site module regardless. So, conda can do what venv does and create a pyvenv.cfg file with the line include-system-site-packages = false. I don't know what other repercussions that has involving sys.prefix, but so far so good when I do it manually. Needs expert input.

Why is this needed?

No response

What should happen?

No response

Additional Context

No response

Metadata

Metadata

Labels

duplicate::primaryif an issue/PR has duplicates, this is the consolidated, primary issue/PRin-progressissue is actively being worked onsource::communitycatch-all for issues filed by community memberstype::featurerequest for a new feature or capability

Type

No type

Projects

Status

👀 In Review

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions