'Conda uses .local packages

I feel like this is a basic question, so feel free to direct me to any resources:

My conda environment uses .local ahead of the package version specified in the yaml file for any package that exists in local. How do I get it to ignore .local, if that's possible?

I'm using PyCharm and Ubuntu.

If I can provide more information, let me know.



Solution 1:[1]

I think all python interpreters will use packages from site.USER_SITE before any others, and by default that location is ~/.local/lib/pythonX.Y/site-packages. That's because site.USER_BASE defaults to ~/.local.

But fortunately, you can override site.USER_BASE to some other value with an environment variable: PYTHONUSERBASE. Since you want to disable it entirely, you should supply a non-empty nonsense value. For example:

$ export PYTHONUSERBASE=intentionally-disabled
$ python -c "import site; print(site.USER_SITE)"
intentionally-disabled/lib/python3.7/site-packages

Docs:

To make sure that variable is set every time you're using that conda environment, you can create a post-activation shell script in ${CONDA_PREFIX}/etc/conda/activate.d/, as explained in this answer.

cat > ${CONDA_PREFIX}/etc/conda/activate.d/disable-PYTHONUSERBASE.sh << EOF
#!/bin/bash
export PYTHONUSERBASE=intentionally-disabled
EOF

chmod +x ${CONDA_PREFIX}/etc/conda/activate.d/disable-PYTHONUSERBASE.sh

But frankly, I think the simplest option is to never use ~/.local for python packages. Just move or delete them. It causes issues like this. I've only encountered it when its causing problems -- I've never seen anyone actually benefit from using that Python feature. I wish they would just disable it by default.


Edit: If your IDE allows you to specify the flags that are passed to python itself, then you can use the python -s option.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1