Anaconda does not use package from activated environment

后端 未结 2 441
长情又很酷
长情又很酷 2020-12-20 00:05

I have a conda environment, in a bash terminal, with an Intel Python Distribution interpreter. However, when importing packages, they are imported from what loo

相关标签:
2条回答
  • 2020-12-20 00:26

    Solution is: in anaconda\env\xyz (as well as in other implementations), set the path environment variable to the directory where 'python.exe' is installed.

    As a default, the python.exe file in anaconda is in:

    c:\.....\anaconda\env\xyz
    

    after you do that, obviously, the python command works, in my case, yielding the following.

    python
    Python 3.4.3 |Anaconda 2.2.0. (64|bit)|(default, Nov 7 2015), etc, etc
    
    0 讨论(0)
  • 2020-12-20 00:36

    Diagnosis

    There appears to be (or have been) another Python 3.6 in the PATH, and I suspect that somehow the Conda dependency resolver ended up resolving some packages to this alternative site-packages and inadvertently including this directory in sys.path. This appears to be a known issue.

    Evidence

    The reason I believe this is because the pandas module is being loaded from here:

    /home/torstein/.local/lib/python3.6/site-packages/pandas

    If you check in Python

    import sys
    
    sys.path
    

    I expect that this should show the above directory.

    Since it was reported that PYTHONPATH is empty (as it should be!), that can't be responsible for this misloading, hence I think it was Conda that somehow configured the env this way.

    Also, the fact that your Python 3.7 env is unaffected is likely because you can't load modules across different minor versions.

    Immediate Solution

    Somehow you need to get rid of that dependency. There are a few things to try

    1. Remove that /home/torstein/.local/ from your PATH. This could cause other issues though. Presumably you have it in PATH because you have other non-development things in there.
    2. Dump specifically that site-packages directory. In comments, it was stated that this is residual from a global Python installation no longer in use, so it seems like a good thing to just get rid of. Do back it up, though, in case there are other dependencies on it.
    3. Clear this path from sys.path before importing modules. Not sure of a clean way to do this.

    Personally, I'd want to delete it and create new envs. It can be hard to know how tied into this directory you are, so I'd be wary of assuming that other packages don't somehow have hidden dependencies on what is in there.

    Long-Term Workaround

    The recommended workaround from the GitHub issue is to add the following environment variable,

    export PYTHONNOUSERSITE=True
    

    which prevents Conda from loading other local site-packages directories. With this, you shouldn't have encountered the problem in the first place.

    0 讨论(0)
提交回复
热议问题