Skip to content Skip to sidebar Skip to footer

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 wi

Solution 1:

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 102014, 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 102014, 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 102014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)]

Solution 2:

For version <= 3.6:

In [109]: import sys

In [110]: 'conda'in sys.version
Out[110]: True

For version >= 3.7, the version info has changed like:

In [2]: sys.version
Out[2]: '3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)]'

From this post The solution should be changed to:

import sys, os
is_conda = os.path.exists(os.path.join(sys.prefix, 'conda-meta'))

Solution 3:

Documentation: http://docs.python.org/2/library/sys.html#sys.version

In [1]: import sys; sys.version
Out[1]: '2.7.5 |Anaconda 1.8.0 (64-bit)| (default, Jul  1 2013, 12:37:52) [MSC v.1500 64 bit (AMD64)]'

Post a Comment for "Any Way To Tell If User's Python Environment Is Anaconda"