Skip to content

TypeError: PythonShell.run is not a function #148

Closed

Description

@sni-J

Today, my node modules have been reset for somewhat reason(idk) and I re-installed it. It worked properly until yesterday, but this error suddenly occurred.
+) I'm using ExpressJS

Error Message

TypeError: PythonShell.run is not a function
    at getKeyword (/home/joon/Desktop/server_study/db.js:313:17)

db.js

const PythonShell = require('python-shell');

var pyOptions = {
    mode: 'text',
    pythonPath: '/usr/bin/python3.5',
    pythonOptions: ['-u'],
    scriptPath: './python',
    args: ['title', 'researcher', 'path_of_txt']
};

...

function pythonTest(cb){
    PythonShell.run("x=1;print(x)", null, (err, results)=>{
        console.log(results);
    });
}

package.json

{
  "name": "server_study",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {
    "body-parser": "^1.18.3",
    "curl": "^0.1.4",
    "ejs": "^2.6.1",
    "express": "^4.16.2",
    "express-session": "^1.15.6",
    "i18n": "^0.8.3",
    "jquery": "^3.3.1",
    "jsdom": "^11.10.0",
    "multer": "^1.3.0",
    "mysql": "^2.16.0",
    "nodemailer": "^4.6.8",
    "pdf2json": "^1.1.7",
    "python-shell": "^1.0.3",
    "serve-index": "^1.9.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "private": true
}

Activity

  1. Almenon commented on Sep 6, 2018

    @Almenon
    Collaborator
  2. self-assigned this
    on Sep 6, 2018
  3. Almenon commented on Sep 6, 2018

    @Almenon
    Collaborator

    I Looked it up and apparently it's not that simple. Imports are a es6 feature so I thought they would work in node, given that even the outdated node 6.14.4 supports the vast majority of es6 features. But apparently only the latest edition of node supports imports.

    See https://stackoverflow.com/questions/45854169/how-can-i-use-an-es6-import-in-node

    So if you want to use imports you have four options:

    1. Use latest version of node with --experimental-modules flag. Node 8.5 might also work.
    2. use babel
    3. use esm
    4. use typescript (highly reccomend this)

    Or you can use require, like so:

    let {PythonShell} = require('python-shell')

    Repl.it Example

  4. sni-J commented on Sep 6, 2018

    @sni-J
    Author

    Thanks for your help!

  5. Almenon commented on Sep 15, 2018

    @Almenon
    Collaborator

    @sni-J I found out you can still use require - see updated comment above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions