{"id":8480,"library":"pyexecjs","title":"PyExecJS","description":"PyExecJS is a Python library (version 1.5.1) designed to run JavaScript code from Python by automatically picking the best available JavaScript runtime. It was developed as a port of Ruby's ExecJS, aiming to simplify JavaScript execution, particularly in environments like Windows XP where Node.js was not readily available. However, the library is officially End-of-Life (EOL) since 2018 and is no longer maintained, with its original purpose largely superseded by modern JavaScript runtime availability.","status":"abandoned","version":"1.5.1","language":"en","source_language":"en","source_url":"https://github.com/doloopwhile/PyExecJS","tags":["javascript","runtime","execution","nodejs","v8","eol"],"install":[{"cmd":"pip install PyExecJS","lang":"bash","label":"Install PyExecJS"}],"dependencies":[{"reason":"Provides Python 2 and 3 compatibility utilities.","package":"six","optional":false},{"reason":"Common JavaScript runtime used by PyExecJS.","package":"Node.js","optional":true},{"reason":"Python wrapper for Google V8 engine, can be used by PyExecJS.","package":"PyV8","optional":true},{"reason":"JavaScript engine, can be used by PyExecJS.","package":"Mozilla SpiderMonkey","optional":true},{"reason":"A headless WebKit, can be used by PyExecJS.","package":"PhantomJS","optional":true}],"imports":[{"symbol":"execjs","correct":"import execjs"}],"quickstart":{"code":"import execjs\nimport os\n\n# Basic evaluation\nresult_eval = execjs.eval(\"'red yellow blue'.split(' ')\")\nprint(f\"Eval result: {result_eval}\")\n\n# Compiling and calling a function\nctx = execjs.compile(\"\"\"\n  function add(x, y) {\n    return x + y;\n  }\n\"\"\")\nresult_call = ctx.call(\"add\", 1, 2)\nprint(f\"Call result: {result_call}\")\n\n# Selecting a specific runtime (requires runtime to be installed, e.g., Node.js)\n# You might need to set the environment variable or ensure Node.js is in PATH\n# os.environ[\"EXECJS_RUNTIME\"] = \"Node\"\n# node_runtime = execjs.get()\n# if node_runtime:\n#   print(f\"Selected runtime: {node_runtime.name}\")\n#   print(f\"Node.js eval result: {node_runtime.eval('1 + 2')}\")\n# else:\n#   print(\"Node.js runtime not found or configured.\")","lang":"python","description":"This quickstart demonstrates the core functionalities of PyExecJS: `execjs.eval()` for simple JavaScript snippets and `execjs.compile()` followed by `ctx.call()` for more complex code with functions. It also shows how to (optionally) attempt to select a specific runtime, though proper runtime installation and environment configuration are external requirements."},"warnings":[{"fix":"Migrate to direct `subprocess` calls for Node.js, `python-uglifyjs`, `js2py`, or a specialized library for your specific use case.","message":"PyExecJS is End-of-Life (EOL) and no longer actively maintained since 2018. Bugs will not be fixed, and its original motivation (bridging JavaScript runtimes on Windows XP) is obsolete. Users are advised to use alternative libraries or directly interact with JavaScript runtimes via `subprocess`.","severity":"breaking","affected_versions":"1.5.1 and earlier"},{"fix":"Ensure Node.js, PyV8, or another supported JavaScript runtime is installed and available in your system's PATH, or explicitly configured for PyExecJS.","message":"The JScript runtime (Microsoft Windows Script Host) is not supported due to security concerns. Attempting to use it will result in an `EnvironmentError`.","severity":"deprecated","affected_versions":"All versions"},{"fix":"For performance-critical applications, consider using a direct integration with a JavaScript engine (e.g., PyV8 if actively maintained, or a more performant JavaScript-Python bridge) or minimize the number of calls by processing larger batches of data within the JavaScript context.","message":"PyExecJS communicates with JavaScript runtimes primarily via text, which can lead to performance overhead, especially for frequent or complex operations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If specific runtime features are required, it's recommended to bypass PyExecJS and invoke the JavaScript runtime directly using Python's `subprocess` module, allowing full control over the execution environment and arguments.","message":"PyExecJS does not fully support runtime-specific features (e.g., Node.js environment variables or module loading mechanisms). It's designed as a generic adapter, which limits its utility for advanced Node.js interactions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install a supported JavaScript runtime like Node.js and ensure it's accessible in your system's PATH. PyExecJS will automatically try to detect and use it. You can verify detected runtimes programmatically.","cause":"PyExecJS attempted to use the JScript runtime on Windows, which has been explicitly disabled due to security vulnerabilities or is no longer considered viable.","error":"EnvironmentError: Your Javascript runtime 'JScript' not supported due to security concerns."},{"fix":"Install a JavaScript runtime like Node.js (`npm install -g node` or download from nodejs.org) and ensure it's added to your system's PATH. On macOS, JavaScriptCore is usually available. On systems where PyV8 is an option, ensure it's correctly installed and configured. Restart your environment after installation.","cause":"PyExecJS could not find any compatible JavaScript runtime (e.g., Node.js, PyV8, JavaScriptCore, SpiderMonkey) installed on the system, or they are not correctly configured/in the system's PATH.","error":"execjs.RuntimeUnavailableError: No runtime available"},{"fix":"Ensure the JavaScript code passed is a valid, self-contained JavaScript string. If you need to include dynamic Python values, use f-strings or `.format()` to inject them into the JavaScript string before passing it to PyExecJS. For instance, `execjs.eval(f'\"Hello, {python_var}!\".length')`.","cause":"This error often occurs when JavaScript code is passed incorrectly to `execjs.eval()` or `execjs.compile()`, or when there's an actual syntax error in the JavaScript string. A common mistake is trying to embed Python variables directly into the JavaScript string without proper concatenation or formatting.","error":"ProgramError: SyntaxError: Unexpected token var"}]}