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

如何找到運行我的代碼的 conda 環境的名稱?

How do I find the name of the conda environment in which my code is running?(如何找到運行我的代碼的 conda 環境的名稱?)
本文介紹了如何找到運行我的代碼的 conda 環境的名稱?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在尋找一種從正在運行的代碼或交互式 python 實例中找出我所在的 conda 環境名稱的好方法.

I'm looking for a good way to figure out the name of the conda environment I'm in from within running code or an interactive python instance.

用例是我正在運行 Jupyter 筆記本,同時安裝了 miniconda 的 Python 2 和 Python 3 內核.默認環境是 Py3.Py2 有一個單獨的環境.在筆記本文件中,我希望它嘗試 conda install foo.我現在使用 subcommand 來執行此操作,因為我找不到與 pip.main(['install','foo']) 等效的編程 conda.

The use-case is that I am running Jupyter notebooks with both Python 2 and Python 3 kernels from a miniconda install. The default environment is Py3. There is a separate environment for Py2. Inside the a notebook file, I want it to attempt to conda install foo. I'm using subcommand to do this for now, since I can't find a programmatic conda equivalent of pip.main(['install','foo']).

問題是如果 notebook 使用 Py2 內核運行,該命令需要知道 Py2 環境的名稱才能在其中安裝 foo.如果沒有該信息,它將安裝在默認的 Py3 環境中.我希望代碼能夠自行確定它所在的環境以及正確的名稱.

The problem is that the command needs to know the name of the Py2 environment to install foo there if the notebook is running using the Py2 kernel. Without that info it installs in the default Py3 env. I'd like for the code to figure out which environment it is in and the right name for it on its own.

到目前為止,我得到的最佳解決方案是:

The best solution I've got so far is:

import sys

def get_env():
    sp = sys.path[1].split("/")
    if "envs" in sp:
        return sp[sp.index("envs") + 1]
    else:
        return ""

有沒有更直接/更合適的方式來實現這一點?

Is there a more direct/appropriate way to accomplish this?

推薦答案

你想要 $CONDA_DEFAULT_ENV$CONDA_PREFIX:

$ source activate my_env
(my_env) $ echo $CONDA_DEFAULT_ENV
my_env

(my_env) $ echo $CONDA_PREFIX
/Users/nhdaly/miniconda3/envs/my_env

$ source deactivate
$ echo $CONDA_DEFAULT_ENV  # (not-defined)

$ echo $CONDA_PREFIX  # (not-defined)

在python中:

In [1]: import os
   ...: print (os.environ['CONDA_DEFAULT_ENV'])
   ...:
my_env

對于通常更有用的絕對完整路徑:

for the absolute entire path which is usually more useful:

Python 3.9.0 | packaged by conda-forge | (default, Oct 14 2020, 22:56:29) 
[Clang 10.0.1 ] on darwin
import os; print(os.environ["CONDA_PREFIX"])
/Users/miranda9/.conda/envs/synthesis


環境變量沒有很好的記錄.您可以找到此處提到的 CONDA_DEFAULT_ENV:https://www.continuum.io/blog/developer/advanced-features-conda-part-1

我能找到的關于 CONDA_PREFIX 的唯一信息是這個問題:https://github.com/conda/conda/issues/2764

The only info on CONDA_PREFIX I could find is this Issue: https://github.com/conda/conda/issues/2764

這篇關于如何找到運行我的代碼的 conda 環境的名稱?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Troubles while parsing with python very large xml file(使用 python 解析非常大的 xml 文件時出現問題)
Find all nodes by attribute in XML using Python 2(使用 Python 2 在 XML 中按屬性查找所有節點)
Python - How to parse xml response and store a elements value in a variable?(Python - 如何解析 xml 響應并將元素值存儲在變量中?)
How to get XML tag value in Python(如何在 Python 中獲取 XML 標記值)
How to correctly parse utf-8 xml with ElementTree?(如何使用 ElementTree 正確解析 utf-8 xml?)
Parse XML from URL into python object(將 XML 從 URL 解析為 python 對象)
主站蜘蛛池模板: 欧美精品久久久 | 成人性视频在线 | 中文字幕乱码一区二区三区 | 四虎永久免费影院 | 亚洲欧美中文字幕 | 亚洲精品久久久久久久不卡四虎 | 成人毛片视频免费 | 成人免费观看男女羞羞视频 | 免费成人在线网站 | 欧美日韩中文字幕在线播放 | 午夜极品| 国产久 | 狠狠ri| 日韩精品视频中文字幕 | 国产乱码精品一区二三赶尸艳谈 | 国产中文区二幕区2012 | 精品中文字幕在线 | 国产精品1区2区3区 一区中文字幕 | 久久国产精品一区二区三区 | 久久久久久黄 | 国产日韩欧美精品一区二区三区 | 国产成人精品一区二区三区四区 | 亚洲天堂久久新 | 黄色骚片 | 天堂一区二区三区 | 午夜影院免费体验区 | 毛片免费看的 | 精品亚洲一区二区三区四区五区高 | 久久久久久国产精品 | 操操日| 成人在线视频免费观看 | www.成人久久 | 精品免费国产一区二区三区四区 | 高清国产午夜精品久久久久久 | 国产成人精品亚洲日本在线观看 | 欧美成人h版在线观看 | 精品国产乱码久久久久久牛牛 | 午夜视频在线观看网址 | 一级大片免费 | 九一视频在线播放 | 男女污污动态图 |