I have been able to successfully run Python backtests locally on my machine, but I am struggling to run Jupyter notebooks properly. I am trying to execute the BasicQuantBookTemplate.ipynb locally on my machine.

When I try to execute this piece of code (which is the first cell in BasicQuantBookTemplatet.ipynb):

!pip install pythonnet
# Imports
from clr import AddReference
from System import *
from QuantConnect import *
from QuantConnect.Data.Custom import *
from QuantConnect.Data.Market import TradeBar, QuoteBar
from QuantConnect.Research import *
from QuantConnect.Indicators import *
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import pandas as pd

# Create an instance
qb = QuantBook()

# Select asset data
spy = qb.AddEquity("SPY")

I get the following backtrace:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pythonnet in /opt/conda/envs/py36/lib/python3.6/site-packages (2.4.0)
ImportError Traceback (most recent call last)
<ipython-input-1-d06382665402> in <module>
1 get_ipython().system('pip install pythonnet')
2 # Imports
----> 3 from clr import AddReference
4 AddReference("System")
5 AddReference("QuantConnect.Common")

ImportError: System.NullReferenceException: Object reference not set to an instance of an object
at Python.Runtime.Runtime.XDecref (System.IntPtr op) [0x00041] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.Runtime.Initialize () [0x001f0] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.PythonEngine.Initialize (System.Collections.Generic.IEnumerable`1[T] args, System.Boolean setSysArgv) [0x0001e] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.PythonEngine.Initialize (System.Boolean setSysArgv) [0x00005] in <c56ab175820d412caf052e079c2ab9ef>:0
at Python.Runtime.PythonEngine.InitExt () [0x00000] in <c56ab175820d412caf052e079c2ab9ef>:0

So it can find PythonNet installation properly, and yet, there is an import error in "from clr import AddReference" line. Any fixes for this?