Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to import module #299

Open
DawChihLiou opened this issue Aug 16, 2023 · 0 comments
Open

Unable to import module #299

DawChihLiou opened this issue Aug 16, 2023 · 0 comments
Labels

Comments

@DawChihLiou
Copy link
Contributor

The Question:
Hi,

I'm trying out python-shell in a next.js project and I wasn't able to import my local python module in the script.

const messages = await PythonShell.runString(`from example_module import a, b, c`);

I'm using a pyproject.toml at the project root to define the local module:

[tool.poetry]
packages = [{include = "example_module", from = "python"}]

[tool.poetry.dependencies]
python = ">=3.11,<3.13"
bayesian = {path = "./python/example_module", develop = true }

This is the error I'm seeing.

- error TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of PythonShellError
    at new NodeError (node:internal/errors:399:5)
    at Function.byteLength (node:buffer:793:11)
    at apiRes.end 
    at handler 
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  digest: undefined
}
PythonShellError: ModuleNotFoundError: No module named 'example_module'
    at PythonShell.parseError
    at terminateIfNeeded
    at ChildProcess.<anonymous>
    at ChildProcess.emit
    at ChildProcess._handle.onexit
    ----- Python Traceback -----
    File "/var/folders/rn/fvrs2khs7hq_hb99d7sqj_0h0000gn/T/pythonShellFile5599925788.py", line 2, in <module>
      from example_module import a, b, c{
  traceback: 'Traceback (most recent call last):\n' +
    '  File "/var/folders/rn/fvrs2khs7hq_hb99d7sqj_0h0000gn/T/pythonShellFile5599925788.py", line 2, in <module>\n' +
    '    from example_module import a, b, c\n' +
    "ModuleNotFoundError: No module named 'example_module'\n",
  executable: 'python3',
  options: null,
  script: '/var/folders/rn/fvrs2khs7hq_hb99d7sqj_0h0000gn/T/pythonShellFile5599925788.py',
  args: null,
  exitCode: 1,
  logs: []
}

Any suggestion is appreciated. Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant