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.