Reputation: 944
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?
Upvotes: 9
Views: 8585
Reputation: 1061
To me it was easier than I'd imagine. I did vim /usr/bin/ipython3
and found the following Bash script:
#! /bin/sh
VERSION="3"
if [ ! -f /usr/bin/python$VERSION ]
then
[...]
To use Python version 3.6.2 I changed the VERSION=3
line to VERSION=3.6
. Please note that setting the VERSION
variable to 3.6.2
did not work on my computer.
Upvotes: 1
Reputation: 115
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.
>>>
Upvotes: 11
Reputation: 944
It seems I've found the solution.
You need to edit the file which starts IPython. On Linux you can enter it with: sudo nano $(which ipython)
.
Once you're inside the file change the shebang line to what ever Python interpreter you like.
And directories that contain Python3.4 modules need to be added to $PYTHONPATH variable.
What is a shebang line? First line in a file that represents the path to python interpreter that will be used.
Thanks to @code_byter.
Upvotes: 3
Reputation: 697
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.
Upvotes: 3