Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

any way to tell if user's python environment is 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.)

so far, i've come up with something like

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

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.

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.

thank you.

like image 999
badideas Avatar asked Jan 22 '14 12:01

badideas


People also ask

How do I know if my Python is Anaconda?

Python Anaconda Version: To check the Anaconda version, run conda list anaconda$ To check the Python version in a conda environment, run conda list python -f. To check the versions of all packages installed in your conda environment, run conda list. To check environment details of your conda installation, run conda ...

Is Anaconda a Python environment?

Anaconda works for R and Python programming language. Package versions are managed by the package management system conda. Installing Anaconda : Head over to anaconda.com and install the latest version of Anaconda.


1 Answers

I'm from Continuum, so let me make a quick note: You'll get a different sys.version string depending on whether you used conda to install the Anaconda Python Distribution or simply Python. So from conda create -n full_apd anaconda you'd get a sys.version string as follows:

$ python -c "import sys; print sys.version"
2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)]

This is what you get if you use miniconda or are working from a conda environment where you have just specified python (e.g. conda create -n base_py27 python=2.7):

$ python -c "import sys; print sys.version"
2.7.6 |Continuum Analytics, Inc.| (default, Jan 10 2014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)]

If you have simply downloaded and installed the full Anaconda Python Distribution directly, you'll get the former:

$ python -c "import sys; print sys.version"
2.7.6 |Anaconda 1.8.0 (x86_64)| (default, Jan 10 2014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)]
like image 131
IanSR Avatar answered Oct 14 '22 17:10

IanSR