Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set other Python interpreter to IPython

Tags:

python

ipython

Can we change the version of Python interpreter that IPython uses?

I know there is IPython and IPython3, but the problem is, IPython uses Python2.7, and IPython3 uses Python3.4.2, and I see no way to change that.

What if I wanted IPython to use which ever version of Python interpreter I wanted, could I make it that way?

I want IPython to use the newest Python version, Python3.6. Can I make it that way?

like image 810
Scarass Avatar asked Jun 28 '17 03:06

Scarass


People also ask

How do I change the interpreter in Python Jupyter lab?

To open the server settings, select Configure Jupyter Server in the list of the Jupyter servers. Configure the server options: To customize the default Jupyter server, in the Jupyter Server dialog, select Managed Server and from the Python interpreter list select any local Python interpreter.

How does Python choose interpreter?

To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P). Note: If the Python extension doesn't find an interpreter, it issues a warning.

How do I get Python version in IPython?

To check the Python version in your Jupyter notebook, first import the python_version function with “ from platform import python_version “. Then call the function python_version() that returns a string with the version number running in your Jupyter notebook such as "3.7. 11" .

Which Python is IPython using?

IPython is open source (BSD license), and is used by a range of other projects; add your project to that list if it uses IPython as a library, and please don't forget to cite the project. IPython supports Python 2.7 and 3.3 or newer.


2 Answers

Modifying a distributed file should be a last resort. I suggest this alternative using python3.6 on Ubuntu 17.04 as an example:

python3.6 -m pip install IPython # lots of output, make IPython available to script ipython3
python3.6 `which ipython3`
Python 3.6.1 (default, Mar 22 2017, 06:17:05) 
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
like image 186
mcarifio Avatar answered Sep 23 '22 13:09

mcarifio


First off, please check what version (by version I mean, the path of the interpreter) of python IPython uses using the which ipython command. Once you know the path, open the file and post the contents here.

Try to make it look like this:

#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from IPython import start_ipython

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(start_ipython())

The first line supposedly ensures that your local python interpreter is used. Commonly called a shebang line.

If you are on a Windows system, try the where ipython command instead.

like image 41
hridayns Avatar answered Sep 25 '22 13:09

hridayns