question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to load PIPENV_* environs from .env file

See original GitHub issue

I understand the existence of #902, but the it seems the OP was looking for something different.

Sometimes I want Pipenv to handle one particular project differently than others. The most common problem is I don’t usually set PIPENV_VENV_IN_PROJECT, but for some projects I want to do. This is however not possible, because they are loaded for shell and run, not install etc., and even if they are, .env is loaded during runtime, therefore doesn’t affect values in environments.py.

direnv and similar tools like autoenv are not an option for me because they are all shell-depedent, and I operate in the command prompt on Windows.

My current workaround is to use a custom Dotenv loader, and a Batch script like this:

REM pipenv.bat
REM Shim to wrap Pipenv invocation in a loaded environment.
REM Put this in the project root so it’s picked up when you call "pipenv".

if exist ".env" (
    dotenv-run pipenv %*
) else (
    pipenv %*
)

which sort of works, but is suboptimal. I wish Pipenv could handle this more cleanly since it already loads .env files anyway.

Steps to replicate
  1. Create a project
  2. Run pipenv install with PIPENV_VENV_IN_PROJECT set
  3. Unset PIPENV_VENV_IN_PROJECT, create .env with PIPENV_VENV_IN_PROJECT=1
Expected result
> pipenv install
Loading .env environment variables…
Installing dependencies from Pipfile.lock

Pipenv should go on reusing .venv and perform operations.

Actual result
> pipenv install
Creating a virtualenv for this project…

Pipenv goes on to create a virtualenv in the default location, not respecting values in .env.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
kennethreitzcommented, Dec 18, 2017

we do not want to support this.

6reactions
ghostcommented, Apr 9, 2018

@kennethreitz I’d be interested to know what the reasoning for this is. It seems like it would be a useful feature to have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I set environment variables in pipenv? - Stack Overflow
If you want to load automatically some environment variables each time you start the project, you can set a .env file at the...
Read more >
Advanced Usage of Pipenv - Read the Docs
Pipenv will expand environment variables (if defined) in your Pipfile. Quite useful if you need to authenticate to a private PyPI:.
Read more >
Using .env Files for Environment Variables in Python ...
While going to pipenv shell for the project, the .env file is automatically loaded. What loads the settings.py file (which has code to...
Read more >
pipenv Documentation - Read the Docs
Automatically adds/removes packages to a Pipfile when they are installed or uninstalled. • Automatically loads .env files to support customization and overrides ...
Read more >
Allow environment variables to load from .env file : PY-5543
So no need to Edit Configuration templates whenever opening a new project to point to the .env, just 'if it's a pipenv project,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found