0

Using Python 3.6, PyCharm 2019.3.1 CE, 64-bits Ubuntu 18.04

I have an environment variable that is accessed fine when running my python script from the command line, but does not show up when running with PyCharm.

This is the script:

import os
print(os.environ.get("GENICAM_GENTL64_PATH"))

From the terminal, this is my output:

:/usr/lib/ids/cti

While with PyCharm, this is my output:

None

What is happening here? Why does the environment variable not show up when running with PyCharm?

R. dV
  • 416
  • 1
  • 3
  • 15

1 Answers1

1

When you run python from your terminal, the python script inherits the environment variables from the shell, which in turn gets GENICAM_GENTL64_PATH through a startup script in /etc/profile.d. (see docs).

In contrast, when you start the script from PyCharm, there is no shell - PyCharm starts the python process itself - so you won't have the environment variables that populated by /etc/profile.d.

You can solve it by launching PyCharm from your terminal, as described here.

Shahar Glazner
  • 377
  • 4
  • 10