判断用户的python环境是否为蟒蛇的任何方法 [英] any way to tell if user's python environment is anaconda

查看:53
本文介绍了判断用户的python环境是否为蟒蛇的任何方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分发一个内部python库,我想在该库中进行分发,以便如果用户在运行此文件时使用anaconda,则将自动对库的依赖项进行更新. (这是应要求提供的.如果由我决定,我可以让用户控制自己的程序包.)

i'm distributing an in-house python lib where i'd like to make it such that if the user is using anaconda when running this file, that updates to the dependencies of the library will be made automatically. (this is by request. if it were up to me, i would let the users control their own packages.)

到目前为止,我想出了

def _user_has_conda():
    cmd = 'conda --help'
    p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = p.communicate()
    if len(out) > 0 and len(err) == 0:
        return True
    else:
        return False

但这实际上只能告诉我用户是否在系统上安装了anaconda,而不是告诉我当前的python进程是否正在anaconda环境中运行.

but this really only tells me if the user has anaconda installed on their system, and not whether the current python process is running in the anaconda environment.

我注意到的是,当我启动python或ipython shell时,我看到"Python 3.3.3 | Continuum Analytics,Inc |"在顶部.我的下一个想法是尝试找到如何获取此字符串以查看是否存在"Continuum Analytics",如果存在,则假定用户正在anaconda中运行.

what i notice is that when i start a python or ipython shell, i see "Python 3.3.3 |Continuum Analytics, Inc|" at the top. my next idea would be to try to find how to get this string to see if "Continuum Analytics" is there, and if so, assume that the user is running in anaconda.

我确定那里有更好的主意,这就是为什么我在这里.

i'm sure there are better ideas out there, and that's why i'm here.

谢谢.

推荐答案

文档: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆