How to delete a certain path in sys.path in anaconda env (base)?
Asked Answered
F

0

0

I have installed a package with

python setup.py install --user

It looks it had been done in anaconda (base), though I can't remember. The module was installed in $HOME/.local/lib/python3.6/site-packages and the path is included in sys.path in anaconda (base). But even though I make another env, the path is still included in sys.path in new env. How can I completely remove the path?

In the installed directory ($HOME/.local/.../site-packages), there are only two files of module directory and ...egg-info file. There is no other files such as *pth file.

In anaconda env (base), python setup.py install will install at

  • $HOME/anaconda3/lib/python3.6/site-packages

And after conda activation env_name, it will install at

  • $HOME/anaconda3/envs/env_name/lib/python3.6/site-packages

And both are not mixed in sys.path. So no need to use --user option in anaconda. '--user' option is needed to write at home rather than root. The problem is that the path to ~/.local/.. always remains in front of the above two paths so I want to remove the path to .local completely.

Freund answered 21/7, 2020 at 9:5 Comment(7)
Do you still need the package in the home directory? If not, you could just delete that folder entirelyCathee
OK, it looks the last method. Then still the path to $HOME/.local/... remains but it will not be effective.Freund
I ran into similar issue. I think this might help: https://mcmap.net/q/298035/-how-to-prevent-anaconda-environment-from-reading-libraries-installed-in-localGarbers
@Jonathan: -s option (ENABLE_USER_SITE: False) is a kind of useful pythonic method if USER_SITE can't be completely remove.Freund
@JoonhoPark You could also set environment variable PYTHONNOUSERSITE to any value in conda activate scripts so you don't have to use -s to invoke python every time.Garbers
It seems there is the keyword of PYTHONNOUSERSITE. But I can't figure out how it works. I tried put (PYTHONNOUSERSITE=1) in several places but it doesn't work in my conda version of 4.5.11. I tried in $anahome/etc/profile.d/conda.sh (main part and _conda_activate() etc) and $anahome/bin/activate. Everytime, it shows ENABLE_USER_SITE: True.Freund
@JonathanTsai, it works. It's environment variable so it needs to be exported in bash rather than just a variable setting. "export PYTHONNOUSERSITE=1" is working.Freund

© 2022 - 2024 — McMap. All rights reserved.