Pipenv: Always load .env file

Created on 13 Oct 2017  Â·  7Comments  Â·  Source: pypa/pipenv

I think it might be worth considering to always load the .env file. As far I can see it is only loaded when running pipenv shell.

An example use case for this would be to share the configuration of PIPENV_VENV_IN_PROJECT so that the venv is created in the local directory. See also steps to replicate.

Describe your environment
  1. OS Type: Windows 10
  2. Python version: $ python -V: Python 2.7.11
  3. Pipenv version: $ pipenv --version: pipenv, version 8.2.7
Steps to replicate

Run in powershell:

PS C:\tmp\pipenv> echo "PIPENV_VENV_IN_PROJECT 1" > .env
PS C:\tmp\pipenv> cat .env
PIPENV_VENV_IN_PROJECT 1
PS C:\tmp\pipenv> pipenv --two
Expected result

.env file is loaded, resulting in:

Virtualenv location: C:\tmp\pipenv\.venv
Actual result

.env file is not loaded, resulting in:

Virtualenv location: C:\Users\Karim\.virtualenvs\playground-pipenv-RDyG8wOS
Type

Most helpful comment

I think that making pipenv handle .env during pipenv install is a better solution than direnv because:

  • pipenv already loads .env, so all necessary plumbing is already there
  • direnv has to be installed and configured separately, wherever you want to use pipenv - all developers' machines, Jenkins, TravisCI etc.

My personal motivation for having this functionality: I have a project that uses private PyPI that doesn't have a shared URL - each developer has their own URL because of security concerns, so I can't put that URL in Pipfile. As far as I can see, the next logical place would be to put it in .env, but it's not that useful when it's not used by pipenv install.

All 7 comments

To my understanding a .env file is specified to take KEY=VALUE specifiers that are newline separated. Is there something unique to Windows that is allowing you to exclude the = in your specification? Does your result change when you add the =?

or this may possible be a duplicate of #879.

Does your result change when you add the =?

When adding the = in between I get the following error when running pipenv shell where the .env file is actually loaded: TypeError: must be string without null bytes, not str

or this may possible be a duplicate of #879.

I guess not as there is no sign of the .env file being loaded at all when running pipenv --two.

Commands like pipenv shell show a message that the .env file is loaded:

Loading .env environment variables…

@kriim So is this more of a problem or an enhancement in your opinion? There are other tools out there like direnv that can execute .env files upon entering a directory.

I think that making pipenv handle .env during pipenv install is a better solution than direnv because:

  • pipenv already loads .env, so all necessary plumbing is already there
  • direnv has to be installed and configured separately, wherever you want to use pipenv - all developers' machines, Jenkins, TravisCI etc.

My personal motivation for having this functionality: I have a project that uses private PyPI that doesn't have a shared URL - each developer has their own URL because of security concerns, so I can't put that URL in Pipfile. As far as I can see, the next logical place would be to put it in .env, but it's not that useful when it's not used by pipenv install.

@erinxocon It feels counterproductive to use a second tool to handle env vars when pipenv already has all the info it needs, and is already doing it partially. I feel the .env file (out of version control) would be a good place to store for instance the tokens for private repositories.

I have the the same problem as others, need to install a package from a private repository. Having pipenv install using .env would be very very useful.

Was this page helpful?
0 / 5 - 0 ratings