Environment variables in PyCharm Jupyter

Viewed 430

In the standard Python Console or Terminal in PyCharm it is pretty straightforward to set environment variables.

How can you set environment variables for PyCharm's managed Jupyter?

2 Answers

There is no easy built-in way at the moment, I am afraid. See the corresponding ticket in the JetBrains issue tracker https://youtrack.jetbrains.com/issue/DS-2770 (and vote for it).

The one workaround that comes to mind is to export the desired environment variables in a shell session -> start PyCharm from it -> start the managed server. IDE will inherit the envs from the shell, and the server will inherit them from the IDE.

You can use a configured Jupyter Server.

  • Open a terminal in PyCharm

  • Export your environment variables in the terminal

    export MY_VARIABLE="its-value"

  • Start a Jupyter Server

    jupyter notebook --no-browser

  • Configure PyCharm to use the server you just started

Note the server URL from the terminal output and then add a server configuration in Languages & Frameworks => Jupyter => Jupyter Servers

Related