.env not found with using python-dotenv==1.1.1 installed through uv pip install
还没有人认领这个 Issue。
评估
调研方向
Start by reproducing the three setups from the issue using dev-environment.yml, dev-environment-with-pip.yml, and show_dotenv_issue.py, then inspect how load_dotenv() locates .env under python-dotenv 1.1.1. Compare the 1.1.0 and 1.1.1 behavior with uv and pip; done means the cause is identified and the reported environment-variable loading behavior is fixed or clearly explained.
由索引模型根据 Issue 内容生成。
描述
dev-environment.yml
dev-environment-with-pip.yml
README.md
show_dotenv_issue.py
Python dotenv issue
System used for issue:
- WSL2 on Windows 11 Enterprise with Ubuntu 22.04
Requirements:
condaversion24.9.2(installed viaminiconda)uvversion0.8.9
Description of the issue:
When running a python script that uses the dotenv package to load environment variables,
depending on the python-dotenv version and using uv or not the .env-file is not found through load_dotenv().
Definition of the folder and files
Folder scructure should be as follows:
├── dev-environment-with-pip.yml
├── dev-environment.yml
├── .env
└── show_dotenv_issue.py
The files should contain the following content:
dev-environment.yml
name: python_dotenv_issue
channels:
- conda-forge
- defaults
dependencies:
- python=3.11.13
dev-environment-with-pip.yml
name: python_dotenv_issue_with_pip
channels:
- conda-forge
- defaults
dependencies:
- python=3.11.13
- pip=25.2
.env
MY_VAR1=my_value1
MY_VAR2=my_value2
show_dotenv_issue.py
import os
from dotenv import load_dotenv
load_dotenv()
if __name__ == "__main__":
print(os.getenv("MY_VAR1"))
print(os.getenv("MY_VAR2"))
Observations
There are three situations to point out:
1. Install python-dotenv==1.1.1 with uv pip install without pip==25.2 (does not work)
Run:
conda deactivate
conda env create -f dev-environment.yml
conda activate python_dotenv_issue
uv pip install python-dotenv==1.1.1
python -m show_dotenv_issue
You expect that the script prints
my_value1
my_value2
but it prints:
None
None
2. Install python-dotenv==1.1.1 with pip install (works)
Run:
conda deactivate
conda env create -f dev-environment-with-pip.yml
conda activate python_dotenv_issue_with_pip
pip install python-dotenv==1.1.1
python -m show_dotenv_issue
The script prints as expected:
my_value1
my_value2
3. Install python-dotenv==1.1.0 with uv pip install (works)
Remove the earlier conda env python_dotenv_issue:
conda deactivate
conda env remove -n python_dotenv_issue
Run:
conda env create -f dev-environment.yml
conda activate python_dotenv_issue
uv pip install python-dotenv==1.1.0
python -m show_dotenv_issue
The script prints as expected:
my_value1
my_value2
Conclusion
There seems to be an issue with python-dotenv==1.1.1 in combination with uv pip install when pip is not installed.
As there is no problem with python-dotenv==1.1.0, we suspect an issue in version 1.1.1. However, we have not been able
to point out what exactly could cause this.
show_dotenv_issue.py
dev-environment.yml
dev-environment-with-pip.yml
README.md
- 主要语言
- Python
- 星标
- 8.9k
- 派生
- 581
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
theskumar/python-dotenv 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
theskumar/python-dotenv#699 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 35/100
theskumar/python-dotenv#697 ·
-
难度 5/5 一周以上 新手友好度 28/100
theskumar/python-dotenv#693 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#683 · 4 条评论 ·
-
难度 3/5 1-2 天 新手友好度 55/100
theskumar/python-dotenv#644 · 2 条评论 ·
查看 theskumar/python-dotenv 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/Repo2RLEnv#163 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
难度 2/5 1-3 小时 新手友好度 70/100
NousResearch/hermes-agent#121143 ·