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

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

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

問題描述

我有一個(gè) conda 環(huán)境,在一個(gè) bash 終端中,帶有一個(gè) Intel Python Distribution 解釋器.但是,在導(dǎo)入包時(shí),它們是從系統(tǒng)默認(rèn) Python 的用戶目錄中導(dǎo)入的,而不是從環(huán)境中導(dǎo)入的.查看 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

當(dāng)使用 base 環(huán)境時(shí),這不會(huì)發(fā)生;從正確的路徑導(dǎo)入包(例如 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的相關(guān)部分(路徑中沒有顯式設(shè)置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

要導(dǎo)入的pandas位于這里,應(yīng)該是:

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

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.

我相信這是因?yàn)?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

我希望這應(yīng)該顯示上面的目錄.

I expect that this should show the above directory.

由于據(jù)報(bào)道 PYTHONPATH 是空的(應(yīng)該是這樣!),因此不能對(duì)這種錯(cuò)誤加載負(fù)責(zé),因此我認(rèn)為是 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)境未受影響這一事實(shí)可能是因?yàn)槟鸁o法跨不同的次要版本加載模塊.

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/.不過,這可能會(huì)導(dǎo)致其他問題.大概你在 PATH 中有它,因?yàn)槟阌衅渌情_發(fā)的東西在那里.
  2. 專門轉(zhuǎn)儲(chǔ)該 site-packages 目錄.在評(píng)論中,有人說這是不再使用的全局 Python 安裝的殘留物,因此擺脫它似乎是一件好事.不過,請(qǐng)備份它,以防有其他依賴項(xiàng).
  3. 在導(dǎo)入模塊之前從 sys.path 中清除此路徑.不確定一種干凈的方式來做到這一點(diǎn).
  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.

就個(gè)人而言,我想刪除它并創(chuàng)建新的環(huán)境.可能很難知道你是如何與這個(gè)目錄綁定在一起的,所以我會(huì)謹(jǐn)慎地假設(shè)其他包對(duì)那里的內(nèi)容沒有隱藏的依賴關(guā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

這會(huì)阻止 Conda 加載其他本地 site-packages 目錄.有了這個(gè),你一開始就不應(yīng)該遇到這個(gè)問題.

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

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

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

相關(guā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(使用兩個(gè)不同的 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 永久設(shè)置 Python 路徑)
主站蜘蛛池模板: 在线免费观看一区二区 | 一区二区三区国产好 | 精品国产一区二区三区性色av | 久久新 | 中文字幕一区二区三区不卡 | 亚洲黄色av | 一区二区三区中文字幕 | 日韩免费一区二区 | 日韩欧美一区二区三区 | 久久精品二区亚洲w码 | 6080亚洲精品一区二区 | 国产精品资源在线 | 国产日韩欧美激情 | 一区免费 | 日韩在线精品强乱中文字幕 | 国产欧美日韩综合精品一 | 一区二区免费视频 | 久久久精品网站 | 日本a∨精品中文字幕在线 亚洲91视频 | 精品日韩在线 | 色婷婷久久久亚洲一区二区三区 | 国产欧美精品区一区二区三区 | 中文精品一区二区 | 久久久999国产精品 中文字幕在线精品 | 天天影视综合 | 91久久精品国产 | 亚洲第一天堂 | 亚洲欧美在线一区 | 免费av一区二区三区 | 国产精品爱久久久久久久 | 国产精品国产三级国产aⅴ无密码 | 国产精品毛片一区二区在线看 | 国产一区视频在线 | 国产婷婷色综合av蜜臀av | 日韩欧美国产一区二区三区 | 草逼网站 | 久久精品福利视频 | 夜夜爽99久久国产综合精品女不卡 | 久久久久久国产精品免费免费狐狸 | 久久久久久91 | 亚洲电影一区 |