SyneRBI / SyneRBI_VM

Virtual Machine with pre-installed SyneRBI software
http://www.ccpsynerbi.ac.uk
Apache License 2.0
3 stars 7 forks source link

use python3 #122

Closed KrisThielemans closed 3 years ago

KrisThielemans commented 5 years ago

Python2 becomes more and more of a problem. We now fail to install spyder, see https://github.com/CCPPETMR/CCPPETMR_VM/issues/121.

Sadly, on Ubuntu 18.04, default python is still python2.7. I guess we can easily tell the SuperBuild to use python3. But what about jupyter? Will it just work when we use

python3 -m pip install jupyter

Possibly easiest would be to do

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
sudo update-alternatives  --set python /usr/bin/python3.6

before doing anything python-like at all.

@casperdcl @bathomas what do you think?

KrisThielemans commented 4 years ago

A complication might be that the SIRF-exercises notebooks had to include python2 kernel name, even though some of them have python3, e.g.

"metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },

in https://raw.githubusercontent.com/CCPPETMR/SIRF-Exercises/master/notebooks/Reg/sirf_registration.ipynb

casperdcl commented 4 years ago

update-alternatives for a system library is risky; it may break something else. jupyter in python3 will "just work" (with a warning about selecting a new kernel in case the name changes)

casperdcl commented 4 years ago

also I presume ubuntu 20.04LTS will default to py3.

Ede1994 commented 4 years ago

So I tested with a jupyter notebook based on python2 and the following code was issued by the terminal:

[IPKernelApp] ERROR | Failed to create history session in /home/sirfuser/.ipython/profile_default/history.sqlite. History will not be saved.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/history.py", line 549, in __init__
    self.new_session()
  File "</usr/local/lib/python2.7/dist-packages/decorator.pyc:decorator-gen-22>", line 2, in new_session
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/history.py", line 60, in needs_sqlite
    return f(self, *a, **kw)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/history.py", line 575, in new_session
    NULL, "") """, (datetime.datetime.now(),))
OperationalError: database is locked
KrisThielemans commented 4 years ago

This seems unrelated. Best to try again after a reboot of the VM.

KrisThielemans commented 4 years ago

@casperdcl you say

jupyter in python3 wll just work

After python3 -m pip install jupyter, I presume that will override an existing python2 install, and that the new one wlil have python3 as default kernel? (A volunteer for trying this?)

KrisThielemans commented 4 years ago

The other thing though is to make sure that CMake picks up python3 in the build. That might need a change in UPDATE.sh etc.

KrisThielemans commented 4 years ago

We're using CMake 3.13. We should probably by using FindPython now, which would then default to using python3 apparently.

See https://github.com/CCPPETMR/SIRF-SuperBuild/issues/313

casperdcl commented 4 years ago

After python3 -m pip install jupyter, I presume that will override an existing python2 install, and that the new one wlil have python3 as default kernel?

Assuming

1) there's also still a py2 jupyter installed 2) The launch command is just jupyter 3) the launch is not within a conda/venv

Then it would depend on the order in PATH whether jupyter py2 or 3 took precedence. Otherwise there would be no conflict.

For our purposes (vm/docker) we can definitely fully control this (incl. e.g. setting a default py2 kernel for py3 jupyter)

KrisThielemans commented 4 years ago

some other things to think about when upgrading:

paskino commented 4 years ago

I've removed the pin to nbstripout and spyder with python3, which you run with spyder3.

KrisThielemans commented 4 years ago

please create the PR.

KrisThielemans commented 3 years ago

closed with #170