load_dotenv doesn't find .env when run from LabVIEW

Offen
#299 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 12 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
devops

Rechercherichtung

Start with find_dotenv, especially its _is_interactive function, and compare its behavior when the Python script is run normally versus inside LabVIEW. Done means the .env file beside the script is found without passing an explicit path, while the existing load_dotenv and find_dotenv behavior remains intact.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

I have a Python script that I'm running from LabVIEW using a Python node (LabVIEW's mechanism for running Python scripts inside a LabVIEW program).

I have .env file in the same directory with the Python script. However, when running the script from LabVIEW, load_dotenv() doesn't find .env, and neither does find_dotenv().

The culprit seems to be _is_interactive function inside find_dotenv:

    def _is_interactive():
        """ Decide whether this is running in a REPL or IPython notebook """
        main = __import__('__main__', None, None, fromlist=['__file__'])
        return not hasattr(main, '__file__')

When Python script is run inside LabVIEW, __name__ is set to the name of the Python module that is run, instead of __main__. Therefore, although __file__ is available and set properly when the script is run, and the script is actually not being run interactively, the above function returns true.

Consequently, .env is not searched for in the directory in which the script is located, but instead in the working directory, which in case of LabVIEW is C:\Windows\System32, and therefore cannot be found.

(I can work around the problem by passing the correct path manually to load_dotenv, but it would be great to have dotenv find the path automatically.)

Vorherrschende Sprache
Python
Sterne
8.9k
Forks
618
Ø Merge
12 T. 6 Min.
Gemergte PRs (30 T.)
3

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus theskumar/python-dotenv

Alle Issues in theskumar/python-dotenv

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.