Skip to main content

environment package in python

Using the right environment package in Python

Published 2 min readMarkdown
environment package in python

I think there are way too many environment handling packages out there (at PyPi) to get confused.

  1. One is environ which was last released in 2007 - https://pypi.org/project/environ/ - which is Python 2 based. We don't want this anymore.

  2. What we normally use in a pure python script is python-environ - https://pypi.org/project/python-environ/ - last released in 2020 - but the page is all about the next environ pypi package I've mentioned about - django-environ

  3. Then we have django-environ which is what is the latest - https://pypi.org/project/django-environ/ - last released in 2023 - this works perfectly on non-Django environments as well. Since its just a wrapper and also referred to by python-environ package page, we are better off using this package only.

python -m pip install environ
Collecting environ
  Downloading environ-1.0.tar.gz (2.6 kB)
  Preparing metadata (setup.py) ... done
Installing collected packages: environ
  DEPRECATION: environ is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for environ ... done
Successfully installed environ-1.0

(env) PS D:\> python .\test.py
Traceback (most recent call last):
  File "D:\test.py", line 5, in <module>
    import environ
  File "D:\env\lib\site-packages\environ.py", line 114
    raise ValueError, "No frame marked with %s." % fname
                    ^
SyntaxError: invalid syntax
(env) PS D:\> python -m pip uninstall environ
Found existing installation: environ 1.0
Uninstalling environ-1.0:
  Would remove:
    d:\env\lib\site-packages\environ-1.0-py3.10.egg-info
    d:\env\lib\site-packages\environ.py
Proceed (Y/n)? Y
  Successfully uninstalled environ-1.0
(env) PS D:\> python .\test.py
Traceback (most recent call last):
  File "D:\test.py", line 5, in <module>
    import environ
ModuleNotFoundError: No module named 'environ'
(env) PS D:\> python -m pip install python-environ
Collecting python-environ
  Using cached python_environ-0.4.54-py2.py3-none-any.whl
Installing collected packages: python-environ
Successfully installed python-environ-0.4.54

(env) PS D:\> python -m pip uninstall python-environ
Found existing installation: python-environ 0.4.54
Uninstalling python-environ-0.4.54:
  Would remove:
    d:\env\lib\site-packages\environ\*
    d:\env\lib\site-packages\python_environ-0.4.54.dist-info\*
Proceed (Y/n)? Y
  Successfully uninstalled python-environ-0.4.54
(env) PS D:\> python -m pip install django-environ
Collecting django-environ
  Using cached django_environ-0.11.2-py2.py3-none-any.whl (19 kB)
Installing collected packages: django-environ
Successfully installed django-environ-0.11.2

About the author

  • I am a web developer from Navi Mumbai. Mainly dealt with LAMP stack, now into Django and getting into Laravel and Cloud. Founder of nerul.in and gaali.in

No comments yet. Be the first to comment.