How to get an executable Python path out of an Anaconda environment?

Question:

I am trying to profile my pyopencl project with CodeXL, and in order to work with .py files. I can’t think of anything better than pointing at Python.exe and passing path to script as an argument. What makes things complicated is my use of Anaconda virtual environment to resolve conflicts between modules, because this way it is impossible to simply point CodeXL at a python executable in some virtual environment – as far as I understand, this environment has to be activated first, and CodeXL does not support this.

Asked By: Mstislaw

||

Answers:

You can find the location of your python exe using:

where python

Since you’re using Anaconda, you can also try:

where anaconda

You’ll find the python exe in the parent directory of the result.

If this isn’t what you need, you can find more info here.

Answered By: entropy

The Python executable of a conda, virtualenv or venv environment is generally located at

$ENVPATH/bin/python

EDIT: on Windows should be instead (at least for venv)

$ENVPATHScriptspython.exe

where $ENVPATH is the environment path. To get a list of the environments you created along with their paths you can run (from the terminal)

conda env list

Alternatively, if you are using a Python interpreter and you want to know where its executable is located, you can run

import sys
print(sys.executable)
Answered By: rrobby86
  1. This should give you a list of all the environments and their respective paths.
conda env list
  1. copy the path of your desired environment and append /bin to it and call the python version, can be either python3 or python2

  2. In the end, your path should look like for python2 /<your_env_path>/bin/python and this for python3 /<your_env_path>/bin/python3

Answered By: Mujeeb Ishaque
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.