0

How check which python interpreter is used by a given python shell such as ipython or bpython ? Are these shells just relying on a notion of default interpreter installed on the system, which I guess is cpython available for example at /usr/bin/python3?

Note: I was not able to find existing questions dealing with the difference between the python interpreter and the python shell. Maybe this question could be enlarged to integrate this difference.

Manuel Selva
  • 18,554
  • 22
  • 89
  • 134
  • 1
    Not sure to fully understand your problem but if you are in a python shell, you can retrieve the path of the binary by checking `sys.executable` – ThR37 Oct 11 '19 at 09:25
  • What do you mean by "the Python shell"? If you run `python` then whichever command that points to (maybe `/usr/local/bin/ipython` or `/usr/bin/python3.6`) will be run and enter its interactive mode. – tripleee Oct 11 '19 at 09:27
  • Question feels unclear, but `python -V` for python version, `python -c "import platform; print(platform.python_implementation())"` for python implementation, and `which python` for python installation used (on most OSs) – Chris_Rands Oct 11 '19 at 09:27
  • To clarify my question, to me `/usr/local/bin/ipython` (for example) is just a shell allowing to type python code. This code is then interpreted by the interpreter. My question is, does ipython uses `/usr/bin/python3.6` for interpreting ? Am I more clear now ? – Manuel Selva Oct 11 '19 at 09:30
  • @ThR37 launching `/usr/local/bin/ipython` and looking at `sys.executable` gives me `/usr/bin/python3`, exactly what I was looking for. – Manuel Selva Oct 11 '19 at 09:44
  • @Chris_Rands `platform.python_implementation()` is exactly what I was looking for. As a side note, I don't see why my question has been down vote, is it more clear now ? – Manuel Selva Oct 11 '19 at 09:47

1 Answers1

0

That depends on the shell you are using.

On Linux/bash, you can use the command: which python that may answer /usr/bin/python

Then a ls -l /usr/bin/python may give: lrwxrwxrwx 1 root root 9 sept. 17 2018 /usr/bin/python -> python2.7

An other way is to launch python in your shell, you may get something like:

Python 3.8.0rc1 (default, Oct  1 2019, 21:48:24) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Or use the command python --version

vpoulailleau
  • 54
  • 1
  • 4