In Pset8, I continue to get the "API_KEY" not set runtime error, even though i crosschecked with:

echo $API_KEY

and the response was:


which matched the key that i exported. Read the answer below to understand how to fix this ANNOYING bug.


3 Answers 3


This can be easily solved by noting which terminal the export command was executed in the same terminal window that flask is running in (will be prompted to run in after the export command). Otherwise, flask cannot recognize the API_KEY as an environment variable, hardly being an environment variable.

  • 1
    Thanks Karthik :) Aug 31, 2017 at 16:29
  • np ;) i suffered too long for this on pset 8 Oct 26, 2017 at 4:47
  • 1
    thanks Karthik. You suffered so we didn't have to. Oct 26, 2017 at 9:15
  • how should i export the api_key if I am doing the same pset on vscode?
    – Praful
    Jun 21, 2019 at 17:03

If anyone is still having a problem to set API_KEY as an environmental variable, remember to do it following this syntax (in VSCODE terminal or powershell for WINDOWS):


Then flask run

Also, remember to do this in the same directory in which the app is located, and to also previously set 'application' (as long as it still is the name of your main .py file) as the environment in which the Flask app runs, as per the following syntax: $env:FLASK_APP = "application"


For those that didn't understand the answer of @Karthik Krishnan you can follow this:

export API_KEY=...

Where ... is the api key you got from IEX Cloud

after this in the same terminal window do:

flask run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .