[SOLVED] Pyenv does not see environment variables
Pyenv does not see environment variables
I’m using a virtualenv with pyenv and although I have environment variables loaded, I can’t access them in Python:
(venv) ➜ which python
/home/gonczor/.pyenv/versions/3.9.6/envs/venv/bin/python
(venv) ➜ echo $DEBUG
(venv) ➜ source .env
(venv) ➜ echo $DEBUG
True
(venv) ➜ python
Python 3.9.6 (default, Aug 15 2021, 19:46:48)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ["DEBUG"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/gonczor/.pyenv/versions/3.9.6/lib/python3.9/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'DEBUG'
>>>
Solution
I don’t know why but it seems if you do not define the environment variable before sourcing into the environment this issue will be there.
Try
export DEBUG=True
and then try again it’ll solve your issue.
Answered By — Sadra Sabouri
Answer Checked By — David Goodson (FixIt Volunteer)
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0
메타데이터
- post_id
- 3df8899a048f
- slug
- solved-pyenv-does-not-see-environment-variables-3df8899a048f
- url
- https://medium.com/@fixitblog/solved-pyenv-does-not-see-environment-variables-3df8899a048f
- canonical_url
- https://medium.com/@fixitblog/solved-pyenv-does-not-see-environment-variables-3df8899a048f
- author_url
- https://medium.com/@fixitblog
- status
- ok
- fetched_at
- 2026-08-04 23:03:49