-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Note
Not tested! Please leave a comment if you have checked any of these methods.
- Setting
PYTHONPATHinpackage.jsonusing dotenv-cli:
npm i dotenv-clipackage.json:
{
"scripts": {
"dev": "dotenv -v PYTHONPATH=. -- node src/index.js"
}
}src/index.js:
const { pymport, proxify } = await import('pymport');
const my_python_module = proxify(pymport('my_python_module'));- Using dynamic import:
Warning
Dynamic imports can make the code more difficult to read and manage because they add asynchronous behavior.
import path from 'node:path';
process.env['PYTHONPATH'] = path.resolve(".");
(async () => {
const { pymport, proxify } = await import('pymport');
const my_python_module = proxify(pymport('my_python_module'));
})();- Using
requirein Node 23.0 (there no need for a--experimental-require-moduleflag):
Caution
pymport is officially tested only on Node 16.x, 18.x, and 20.x.
package.json:
{
"scripts": {
"start": "node src/index.js",
}
}src/index.js:
import path from 'node:path';
process.env['PYTHONPATH'] = path.resolve(".");
const { pymport, proxify } = require('pymport');
const my_python_module = proxify(pymport('my_python_module'));Metadata
Metadata
Assignees
Labels
No labels