pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

問題描述

我有一個 conda 環(huán)境,在一個 bash 終端中,帶有一個 Intel Python Distribution 解釋器.但是,在導(dǎo)入包時,它們是從系統(tǒng)默認 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

當使用 base 環(huán)境時,這不會發(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)有)另一個 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

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

I expect that this should show the above directory.

由于據(jù)報道 PYTHONPATH 是空的(應(yīng)該是這樣!),因此不能對這種錯誤加載負責,因此我認為是 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/.不過,這可能會導(dǎo)致其他問題.大概你在 PATH 中有它,因為你有其他非開發(fā)的東西在那里.
  2. 專門轉(zhuǎn)儲該 site-packages 目錄.在評論中,有人說這是不再使用的全局 Python 安裝的殘留物,因此擺脫它似乎是一件好事.不過,請備份它,以防有其他依賴項.
  3. 在導(dǎo)入模塊之前從 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)境.可能很難知道你是如何與這個目錄綁定在一起的,所以我會謹慎地假設(shè)其他包對那里的內(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

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

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)境中的包的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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(使用兩個不同的 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 路徑)
主站蜘蛛池模板: 不锈钢散热器,冷却翅片管散热器厂家-无锡市烨晟化工装备科技有限公司 | 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 低浓度恒温恒湿称量系统,强光光照培养箱-上海三腾仪器有限公司 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 诚暄电子公司首页-线路板打样,pcb线路板打样加工制作厂家 | 钛合金标准件-钛合金螺丝-钛管件-钛合金棒-钛合金板-钛合金锻件-宝鸡远航钛业有限公司 | 无机纤维喷涂棉-喷涂棉施工工程-山东华泉建筑工程有限公司▲ | 逗网红-抖音网红-快手网红-各大平台网红物品导航 | 小型手持气象站-空气负氧离子监测站-多要素微气象传感器-山东天合环境科技有限公司 | UV-1800紫外光度计-紫外可见光度计厂家-翱艺仪器(上海)有限公司 | C形臂_动态平板DR_动态平板胃肠机生产厂家制造商-普爱医疗 | Boden齿轮油泵-ketai齿轮泵-yuken油研-无锡新立液压有限公司 | 河南生物显微镜,全自动冰冻切片机-河南荣程联合科技有限公司 | 多米诺-多米诺世界纪录团队-多米诺世界-多米诺团队培训-多米诺公关活动-多米诺创意广告-多米诺大型表演-多米诺专业赛事 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 手机存放柜,超市储物柜,电子储物柜,自动寄存柜,行李寄存柜,自动存包柜,条码存包柜-上海天琪实业有限公司 | 电缆接头_防水接头_电缆防水接头_防水电缆接头_上海闵彬 | 儋州在线-儋州招聘找工作、找房子、找对象,儋州综合生活信息门户! | 活动策划,舞台搭建,活动策划公司-首选美湖上海活动策划公司 | 沈阳液压泵_沈阳液压阀_沈阳液压站-沈阳海德太科液压设备有限公司 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 交通信号灯生产厂家_红绿灯厂家_电子警察监控杆_标志杆厂家-沃霖电子科技 | 萃取箱-萃取槽-PVC萃取箱厂家-混合澄清槽- 杭州南方化工设备 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 氟氨基酮、氯硝柳胺、2-氟苯甲酸、异香兰素-新晨化工 | 西安中国国际旅行社(西安国旅) | 铁艺,仿竹,竹节,护栏,围栏,篱笆,栅栏,栏杆,护栏网,网围栏,厂家 - 河北稳重金属丝网制品有限公司 山东太阳能路灯厂家-庭院灯生产厂家-济南晟启灯饰有限公司 | 扒渣机厂家_扒渣机价格_矿用扒渣机_铣挖机_撬毛台车_襄阳永力通扒渣机公司 | 主题班会网 - 安全教育主题班会,各类主题班会PPT模板 | 长沙一级消防工程公司_智能化弱电_机电安装_亮化工程专业施工承包_湖南公共安全工程有限公司 | 山东臭氧发生器,臭氧发生器厂家-山东瑞华环保设备 | 超声骨密度仪-动脉硬化检测仪器-人体成分分析仪厂家/品牌/价格_南京科力悦 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 云南丰泰挖掘机修理厂-挖掘机维修,翻新,再制造的大型企业-云南丰泰工程机械维修有限公司 | 北京翻译公司_同传翻译_字幕翻译_合同翻译_英语陪同翻译_影视翻译_翻译盖章-译铭信息 | 恒温恒湿试验箱厂家-高低温试验箱维修价格_东莞环仪仪器_东莞环仪仪器 | 悬浮拼装地板_幼儿园_篮球场_悬浮拼接地板-山东悬浮拼装地板厂家 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 杭州用友|用友软件|用友财务软件|用友ERP系统--杭州协友软件官网 | 变压器配件,变压器吸湿器,武强县吉口变压器配件有限公司 |