python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

python-dotenv 0.9.2 does not load .env file from current directory

Open larsks opened this issue 3 years ago • 1 comments

I'm trying to use python-dotenv 0.9.2, and it appears that it does not load the .env file from the current directory, which is unexpected and surprising.

With a script located in ~/.local/share/virtualenvs/guac_py-TCd6GOsM/bin/guac, loading modules from /home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/python3.10/site-packages/guac/cmd/.env, I see it look for .env in the following locations when running with strace:

newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/python3.10/site-packages/guac/cmd/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/python3.10/site-packages/guac/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/python3.10/site-packages/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/python3.10/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/lib/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/guac_py-TCd6GOsM/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/virtualenvs/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/share/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.local/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/lars/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/home/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/.env", 0x7ffc7644fee0, 0) = -1 ENOENT (No such file or directory)

It appears to be looking for .env relative to the path to the calling module, rather than the current working directory.

larsks avatar Mar 04 '22 01:03 larsks

This behavior seems to be dependent on how the package is installed. If I flit install --symlink the project, we see the behavior described above. If I pip install -e . the project, it seems to work as expected.

larsks avatar Mar 04 '22 01:03 larsks

Is this issue present in 0.21.0? 0.9.2 is quite an old version.

bbc2 avatar Nov 12 '22 12:11 bbc2