@@ -93,11 +93,17 @@ def new_ipy(s=''):
93
93
new_ipy()
94
94
95
95
"""
96
- from IPython .kernel import KernelManager
96
+
97
+ try :
98
+ from jupyter_client .manager import KernelManager
99
+ except ImportError : # For compatibility with IPython 3 or lower
100
+ from IPython .kernel import KernelManager
101
+
97
102
km = KernelManager ()
98
103
km .start_kernel ()
99
104
return km_from_string (km .connection_file )
100
105
106
+
101
107
def km_from_string (s = '' ):
102
108
"""create kernel manager from IPKernelApp string
103
109
such as '--shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for IPython 0.11
@@ -107,21 +113,31 @@ def km_from_string(s=''):
107
113
import IPython
108
114
except ImportError :
109
115
raise ImportError ("Could not find IPython. " + _install_instructions )
110
- from IPython . config . loader import KeyValueConfigLoader
116
+
111
117
try :
112
- from IPython .kernel import (
113
- KernelManager ,
114
- find_connection_file ,
115
- )
116
- except ImportError :
117
- # IPython < 1.0
118
- from IPython .zmq .blockingkernelmanager import BlockingKernelManager as KernelManager
119
- from IPython .zmq .kernelapp import kernel_aliases
118
+ from traitlets .config .loader import KeyValueConfigLoader
119
+ except ImportError : # IPython <= 3.0
120
+ from IPython .config .loader import KeyValueConfigLoader
121
+
122
+ try :
123
+ from jupyter_client .manager import KernelManager
124
+ from jupyter_client .connect import find_connection_file
125
+
126
+ except ImportError : # IPython <= 3.0
120
127
try :
121
- from IPython .lib .kernel import find_connection_file
128
+ from IPython .kernel import (
129
+ KernelManager ,
130
+ find_connection_file ,
131
+ )
122
132
except ImportError :
123
- # < 0.12, no find_connection_file
124
- pass
133
+ # IPython < 1.0
134
+ from IPython .zmq .blockingkernelmanager import BlockingKernelManager as KernelManager
135
+ from IPython .zmq .kernelapp import kernel_aliases
136
+ try :
137
+ from IPython .lib .kernel import find_connection_file
138
+ except ImportError :
139
+ # < 0.12, no find_connection_file
140
+ pass
125
141
126
142
global km , kc , send
127
143
@@ -142,7 +158,11 @@ def km_from_string(s=''):
142
158
p = p .lstrip ().rstrip () # profile part of the string
143
159
fullpath = find_connection_file (k ,p )
144
160
else :
145
- fullpath = find_connection_file (s .lstrip ().rstrip ())
161
+ s = s .lstrip ().rstrip ();
162
+ if (len (s ) == 0 ):
163
+ fullpath = find_connection_file ()
164
+ else :
165
+ fullpath = find_connection_file (s .lstrip ().rstrip ())
146
166
except IOError as e :
147
167
echo (":IPython " + s + " failed" , "Info" )
148
168
echo ("^-- failed '" + s + "' not found" , "Error" )
0 commit comments