设置
我有个奇怪的问题。 我有一个网站,我希望运行一个python脚本,当有人按下按钮。在
所以,我遵循了这个教程:https://www.npmjs.com/package/python-shell
问题:
我的控制台打印这个:ReferenceError: require is not defined
在这一行:var PythonShell = require('python-shell');
这是my.js函数的第一行。我在npm install
步骤之后添加了这一行。在
我如何克服这个错误?在
可能有用的注释
我的脚本如下:
angular.module('MYApp')
.controller('MyTypeController', function ($scope, $http, $stateParams, $state) {
$scope.runPythonRoutine = function () {
console.log("Error 1");
var PythonShell = require('python-shell');
var myshell = new PythonShell.run('hello.py', function (err, results) {
console.log("Error 2");
// script finished
});
};
...
我的包.json包含:
^{pr2}$
require()在浏览器/客户端JavaScript中不存在。您需要require.js才能在浏览器中使用require()。您还必须将此添加到包.json公司名称:
并指定要求.js在底部html代码的
^{pr2}$<script>
标记中,如下所示:相关问题 更多 >
编程相关推荐