Unable to set python version in node runtime

Hello, I am trying to set my python version to a newer version since my current project requires a version higher than 3.8 but it’s currently stuck with 3.7.3

gyp info find Python using Python version 3.7.3 found at "/usr/bin/python3"

Hence why I am getting the following error:

Traceback (most recent call last):
  File "/usr/lib/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
    import gyp  # noqa: E402
  File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
    import gyp.input
  File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 8, in <module>
    import gyp.common
  File "/usr/lib/node_modules/node-gyp/gyp/pylib/gyp/common.py", line 435
    if CC := os.environ.get("CC_target") or os.environ.get("CC"):
           ^
SyntaxError: invalid syntax
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.<anonymous> (/usr/lib/node_modules/node-gyp/lib/configure.js:317:18)
gyp ERR! stack at ChildProcess.emit (node:events:519:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Linux 6.5.0-1021-aws
gyp ERR! command "/opt/render/project/nodes/node-21.7.2/bin/node" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /opt/render/project/src/node_modules/sharp
gyp ERR! node -v v21.7.2
gyp ERR! node-gyp -v v10.2.0
gyp ERR! not ok

is there a way to specify Python version in node runtimes? I read on a previous community topic that the PYTHON_VERSION environment variable does not work with node environments.

edit: I have also tried creating a new static website to see if render updated the python version on newer websites but it still used 3.7.3

Try using a Python service instead.

We control the native runtimes and include Node in a Python service but not the other way around. As such, the only Python for a Node service ends up being the underlying operating system’s Python, which is 3.7.3 as you’ve discovered.

When the service has Python set as its runtime, we make sure to include the version we default to, which is currently 3.11.9 and can also be specified by the PYTHON_VERSION environment variable then.

Hello Danny, thank you for your response. Can you assist me with deploying this website in a Python service? Or is there any way to update the python version?

When you create a new web service, we auto-detect the language. If you’re trying to deploy a Node application, the language will be set as Node. However, you’re welcome to modify that to another language in the service creation flow.

You would want to try something like:

  1. Create a new web service.
  2. Set the Language to Python.
  3. If you need a specific Node or Python version, set it using the appropriately environment variable (NODE_VERSION, PYTHON_VERSION).
1 Like

Hello, thank you the build now works as expected. However, this way I am facing the limitations of using a web service so if there was any way the Python version could be updated on static sites that would be good. Nevertheless, thank you for your help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.