Terminal not loading environmental variables with PIPENV

Answered

I'm working on a Flask app, using pipenv. I have a .env file with FLASK_APP=ccadmin.py defined.

The problem is that when I run flask shell in the PyCharm Terminal, it's not loading the .env environmental variables. I have to type "set FLASK_APP = ccadmin.py" every single time.

However if I run "pipenv shell" from the Windows CLI, everything loads correctly.  

What's more... if I run "pipenv shell" from the PyCharm Terminal, it also loads the .env environmental variables correctly.  

Is the PyCharm terminal not invoking pipenv?

I'm running the latest PyCharm 2018.3

What additional information should I provide to help?

 

From PyCharm Terminal....

This does NOT work

Microsoft Windows [Version 10.0.16299.785]
(c) 2017 Microsoft Corporation. All rights reserved.

(CC Admin Site) C:\Users\davida\Dropbox\CC Admin Site>flask shell
* Tip: There are .env files present. Do "pip install python-dotenv" to use them.
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
App: app [production]
Instance: C:\Users\davida\Dropbox\CC Admin Site\instance
>>> app
<Flask 'app'>
>>> db
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'db' is not defined

This DOES work


Microsoft Windows [Version 10.0.16299.785]
(c) 2017 Microsoft Corporation. All rights reserved

(CC Admin Site) C:\Users\davida\Dropbox\CC Admin Site>pipenv shell
Loading .env environment variables…
Launching subshell in virtual environment…
Microsoft Windows [Version 10.0.16299.785]
(c) 2017 Microsoft Corporation. All rights reserved.

(CC_Admin_Site-0g0SztUB) (CC Admin Site) C:\Users\davida\Dropbox\CC Admin Site>flask shell
* Tip: There are .env files present. Do "pip install python-dotenv" to use them.
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
App: app [production]
Instance: C:\Users\davida\Dropbox\CC Admin Site\instance
>>> app
<Flask 'app'>
>>> db
<SQLAlchemy engine=postgresql://cc_web_admin:***@localhost/postgres>



I created the project to use Pipenv

1 comment

Hi David,

PyCharm's Terminal doesn't support working with .env files. You should probably try setting FLASK_APP environment variable in Terminal settings Settings | Tools | Terminal.

0

Please sign in to leave a comment.