我无法使用%python
使用%spark.pyspark
或%python
print("Hello")
z.z.runParagraph('REPLACE_ME')
解释器。
在一个最小的非工作示例中,可以从空笔记本开始并添加以下两段:
第一段:
%python
print("World")
第二段:
REPLACE_ME
然后用第二段中的段落id替换runParagraph()
,最后运行第一段。结果将是一个例外,表明方法Traceback (most recent call last):
File "/tmp/zeppelin_python-9073316303905892812.py", line 283, in <module>
raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
File "/tmp/zeppelin_python-9073316303905892812.py", line 276, in <module>
exec(code, _zcUserQueryNameSpace)
File "<stdin>", line 2, in <module>
File "/zeppelin/interpreter/python/py4j-0.9.2/src/py4j/java_gateway.py", line 836, in __call__
answer, self.gateway_client, self.target_id, self.name)
File "/zeppelin/interpreter/python/py4j-0.9.2/src/py4j/protocol.py", line 314, in get_return_value
format(target_id, ".", name, value))
Py4JError: An error occurred while calling t.runParagraph. Trace:
py4j.Py4JException: Method runParagraph([class java.lang.String]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:335)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:344)
at py4j.Gateway.invoke(Gateway.java:279)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:209)
at java.lang.Thread.run(Thread.java:748)
确实存在。我得到的完整例外是:
%python
z.z.runParagraph
然而,
<py4j.java_gateway.JavaMember object at 0x7f7319460d90>
报告@section('scripts')
<script src="https://cdn.webrtc-experiment.com/RecordRTC.js"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script>
function captureMicrophone(callback) {
navigator.mediaDevices.getUserMedia({audio: true}).then(callback).catch(function(error) {
alert('Unable to access your microphone.');
console.error(error);
});
}
var recorder;
//on click of a button representing microphone
$('#inputFields').on('click','*[class*=microphoneBtn]',function(){
var audio = $('$audio'); //this refers to an HTML audio element
var button = this;
if(recorder == null || recorder.state === 'stopped'){ //start recording
captureMicrophone(function(microphone) {
setSrcObject(microphone, audio);
audio.muted = true;
audio.play();
recorder = RecordRTC(microphone, {
type: 'audio',
recorderType: StereoAudioRecorder,
desiredSampRate: 16000
});
recorder.startRecording();
recorder.microphone = microphone;
}else{ //stop recording
recorder.stopRecording(function(){
var blob = this.getBlob(); //get actual blob file
audio.src = URL.createObjectURL(blob); //set src of audio element
audio.muted = false;
audio.play();
recorder.microphone.stop();
});
}
});
</script>
//on click of the save button, save the audio file to server
$('#inputFields').on('click','*[class*=saveBtn]',function(){
var blob = recorder.getBlob();
var formdata = new FormData();
formdata.append('audio-blob', blob);
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: 'POST',
url: //your url,
data: formdata,
processData: false,
contentType: false,
success: function (data) {
//success message
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//error message
}
});
});
@endsection
,所以我认为应该以这种方式访问该方法。我错过了一些初始化步骤吗?如何使用python解释器运行其他段落?
答案 0 :(得分:2)
您想要的方法是z.z.run(<paragraph-id>)
您可以检查上下文对象的类型/类以在源代码中查找它们的方法。
%spark.pyspark
print(type(z))
# <class '__main__.PyZeppelinContext'>
print(z.z.getClass())
# class org.apache.zeppelin.spark.SparkZeppelinContext
SparkZeppelinContext
扩展了BaseZeppelinContext
,您可以在其中找到与this chart中为后端API记录的方法匹配的方法。