角Python在第一个林上失败了

2024-03-29 07:51:09 发布

您现在位置:Python中文网/ 问答频道 /正文

设置

我有个奇怪的问题。 我有一个网站,我希望运行一个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}$

Tags: https脚本log网站varwwwfunction教程
1条回答
网友
1楼 · 发布于 2024-03-29 07:51:09

require()在浏览器/客户端JavaScript中不存在。您需要require.js才能在浏览器中使用require()。您还必须将此添加到包.json公司名称:

"require.js": "version"

并指定要求.js在底部html代码的<script>标记中,如下所示:

^{pr2}$

相关问题 更多 >