久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Anaconda 不使用激活環(huán)境中的包

Anaconda does not use package from activated environment(Anaconda 不使用激活環(huán)境中的包)
本文介紹了Anaconda 不使用激活環(huán)境中的包的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 conda 環(huán)境,在一個 bash 終端中,帶有一個 Intel Python Distribution 解釋器.但是,在導入包時,它們是從系統(tǒng)默認 Python 的用戶目錄中導入的,而不是從環(huán)境中導入的.查看 pandas 包的版本差異和 __spec__ 來源.

I have a conda environment, in a bash terminal, with an Intel Python Distribution interpreter. However, when importing packages, they are imported from what looks to be the user directory of the system default Python, not the environment. Take a look at the version discrepancy and the __spec__ origin of the pandas package.

 ~  $  conda activate idp
 ~  $  which python
~/anaconda3/envs/idp/bin/python
 ~  $  python
Python 3.6.8 |Intel Corporation| (default, Mar  1 2019, 00:10:45) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux
Type "help", "copyright", "credits" or "license" for more information.
Intel(R) Distribution for Python is brought to you by Intel Corporation.
Please check out: https://software.intel.com/en-us/python-distribution
>>> import pandas
>>> pandas.__version__
'0.22.0'
>>> pandas.__spec__
ModuleSpec(name='pandas', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7f509e184ba8>, origin='/home/torstein/.local/lib/python3.6/site-packages/pandas/__init__.py', submodule_search_locations=['/home/torstein/.local/lib/python3.6/site-packages/pandas'])
>>> 
 ~  $  conda list | head -n 3
# packages in environment at /home/torstein/anaconda3/envs/idp:
#
# Name                    Version                   Build  Channel
 ~  $  conda list | grep pandas
pandas                    0.24.1                   py36_3    intel
 ~  $  conda env list
# conda environments:
#
base                     /home/torstein/anaconda3
idp                   *  /home/torstein/anaconda3/envs/idp
py36                     /home/torstein/anaconda3/envs/py36

當使用 base 環(huán)境時,這不會發(fā)生;從正確的路徑導入包(例如 pandas):

When using the base environment, this does NOT happen; packages (e.g. pandas) are imported from the correct path:

 ~  $  conda deactivate
 ~  $  conda env list
# conda environments:
#
base                  *  /home/torstein/anaconda3
idp                      /home/torstein/anaconda3/envs/idp
py36                     /home/torstein/anaconda3/envs/py36

 ~  $  which python
~/anaconda3/bin/python
 ~  $  python
Python 3.7.0 (default, Oct  9 2018, 10:31:47) 
[GCC 7.3.0] :: Anaconda custom (64-bit) on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
pan>>> pandas.__version__
'0.23.4'
>>> pandas.__spec__
ModuleSpec(name='pandas', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fad808a8e80>, origin='/home/torstein/anaconda3/lib/python3.7/site-packages/pandas/__init__.py', submodule_search_locations=['/home/torstein/anaconda3/lib/python3.7/site-packages/pandas'])

.bashrc的相關部分(路徑中沒有顯式設置anaconda):

The relevant part of .bashrc (no anaconda explicitly set in path):

export PATH="/home/torstein/.cargo/bin:$PATH"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/intel/lib/intel64_lin:/opt/intel/compilers_and_libraries_2018.0.128/linux/mkl/lib/intel64_lin/"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/torstein/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/torstein/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/torstein/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/torstein/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup

分別為 baseidp 環(huán)境生成這些 $PATH:

Which yields these $PATHs, for the base and idp envs respectively:

 ~  $  echo $PATH
/home/torstein/anaconda3/bin:/home/torstein/anaconda3/condabin:/home/torstein/.cargo/bin:/home/torstein/.cargo/bin:/home/torstein/anaconda3/bin:/home/torstein/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/torstein/.local/bin:/home/torstein/bin
 ~  $  conda activate idp
 ~  $  echo $PATH
/home/torstein/anaconda3/envs/idp/bin:/home/torstein/anaconda3/condabin:/home/torstein/.cargo/bin:/home/torstein/.cargo/bin:/home/torstein/anaconda3/bin:/home/torstein/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/home/torstein/.local/bin:/home/torstein/bin

要導入的pandas位于這里,應該是:

The pandas that I do want to import is located here, where it should be:

/home/torstein/anaconda3/envs/idp/lib/python3.6/site-packages/pandas

推薦答案

診斷

PATH 中似乎有(或曾經有)另一個 Python 3.6,我懷疑 Conda 依賴解析器最終以某種方式將一些包解析為這個替代 site-packages 并且無意中將這個目錄包含在 sys.path 中.這似乎是一個已知問題.

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.

我相信這是因為 pandas 模塊是從這里加載的:

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

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

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

如果你簽入 Python

If you check in Python

import sys

sys.path

我希望這應該顯示上面的目錄.

I expect that this should show the above directory.

由于據(jù)報道 PYTHONPATH 是空的(應該是這樣!),因此不能對這種錯誤加載負責,因此我認為是 Conda 以某種方式配置了 env.

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.

此外,您的 Python 3.7 環(huán)境未受影響這一事實可能是因為您無法跨不同的次要版本加載模塊.

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

您需要以某種方式擺脫這種依賴.有一些事情可以嘗試

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

  1. 從您的 PATH 中刪除該 /home/torstein/.local/.不過,這可能會導致其他問題.大概你在 PATH 中有它,因為你有其他非開發(fā)的東西在那里.
  2. 專門轉儲該 site-packages 目錄.在評論中,有人說這是不再使用的全局 Python 安裝的殘留物,因此擺脫它似乎是一件好事.不過,請備份它,以防有其他依賴項.
  3. 在導入模塊之前從 sys.path 中清除此路徑.不確定一種干凈的方式來做到這一點.
  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.

就個人而言,我想刪除它并創(chuàng)建新的環(huán)境.可能很難知道你是如何與這個目錄綁定在一起的,所以我會謹慎地假設其他包對那里的內容沒有隱藏的依賴關系.

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.

GitHub 問題推薦的解決方法是添加以下環(huán)境變量,

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

export PYTHONNOUSERSITE=True

這會阻止 Conda 加載其他本地 site-packages 目錄.有了這個,你一開始就不應該遇到這個問題.

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

這篇關于Anaconda 不使用激活環(huán)境中的包的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to install Selenium in a conda environment?(如何在 conda 環(huán)境中安裝 Selenium?)
get the CUDA and CUDNN version on windows with Anaconda installe(使用 Anaconda installe 在 Windows 上獲取 CUDA 和 CUDNN 版本)
How can I download Anaconda for python 3.6(如何下載適用于 python 3.6 的 Anaconda)
Using two different Python Distributions(使用兩個不同的 Python 發(fā)行版)
How can I install Anaconda aside an existing pyenv installation on OSX?(除了 OSX 上現(xiàn)有的 pyenv 安裝之外,如何安裝 Anaconda?)
Permanently set Python path for Anaconda within Cygwin(在 Cygwin 中為 Anaconda 永久設置 Python 路徑)
主站蜘蛛池模板: 欧美日韩一区二区三区视频 | 久久网av | www.草| 老司机午夜视频 | 黄色片免费网站 | 欧美精品第一页 | 四虎永久在线 | 青青草伊人网 | 午夜婷婷 | 免费的黄色小视频 | 欧美黄色片网站 | 久久国产精 | 久久久久久97 | 日韩欧美小视频 | 午夜视频在线免费观看 | 日韩精品一区二区三区免费视频 | 成人综合网站 | 天堂免费av | 久久这里有精品 | 97色婷婷 | 日韩欧美在线播放 | www.99色| 国产精品一区二区三区四区五区 | 欧美激情综合 | 日韩资源在线 | 一级片av | 九九九免费视频 | 午夜视频在线免费观看 | 黄色特级毛片 | 中国农村毛片免费播放 | 成人手机在线视频 | 青青久久| 成年人午夜视频 | 日本福利在线 | 黄色一级小说 | 黄色在线播放 | 国产一级视频在线观看 | 亚洲精品影院 | 国产精品2| 高清乱码男女免费观看 | 国产日韩中文字幕 |