1

I'm having trouble running my flask based web app that uses an api key from IEX. Normally in my Linux based cloud IDE I run:

export API_KEY=[keyhere]

in the command line and the program works fine. But I cannot get my program to run locally in my Windows machine. When I run the exact same command in the terminal it says:

'export' is not recognized as an internal or external command, operable program or batch file.

I've found a quirk about the Windows terminal compared to linux from a different necessary command. In Linux I may write:

FLASK_APP=application.py

but in Windows I am supposed to write the same as:

$env:FLASK_APP='application.py'.

Writing $env: for the API_KEY command results in this error though:

The filename, directory name, or volume label syntax is incorrect.

I'm using VSCode if that helps. I tried setting the API_KEY in both the VSCode's integrated terminal and Window's operating system terminal. Does anyone know how to set an API_KEY in Windows?

Steven Kim
  • 101
  • 2
  • 9
  • That's just an environment variable. You're asking how to set an environment variable. Just use `SET`. `export` is the LINUX keyword. `SET FLASK_APP=application.py`. There's no `$env` in Windows – Panagiotis Kanavos Nov 28 '19 at 11:33
  • Unless you mean how *Powershell* set's environment variables? – Panagiotis Kanavos Nov 28 '19 at 11:35
  • The original question - how to set an environment variable on your machine - isn't programming-related. Hit the `Win` key and type `system variables`. The first result should be `Edit the System Environment Variables` which opens a dialog box allowing you to set system-wide or user-specific environment variables. – Panagiotis Kanavos Nov 28 '19 at 11:37
  • If you ask how to set evn variables in a VS Code terminal specifically, there are duplicate questions [like this one](https://stackoverflow.com/questions/48595446/is-there-any-way-to-set-environment-variables-in-visual-studio-code) - the answers show how to set executables, arguments and env variables for various task commands – Panagiotis Kanavos Nov 28 '19 at 11:38
  • Setting environment variables before opening a terminal, or executing a script that sets them, is done in VS Code settings, through the `terminal.integrated.shellArgs.windows` and `terminal.integrated.env.windows` settings. Check [here](https://stackoverflow.com/questions/45635168/vscode-how-to-run-a-command-after-each-terminal-open), [here](https://stackoverflow.com/questions/46232602/terminal-integrated-env-windows-for-integrated-terminal) and the [integrated terminal docs](https://code.visualstudio.com/docs/editor/integrated-terminal) – Panagiotis Kanavos Nov 28 '19 at 11:48

2 Answers2

2

In Windows the command is set as compared to export in Linux/Unix based systems.

Faizan Naseer
  • 589
  • 3
  • 12
  • And even that isn't needed if you add a user or system environment variable through System settings – Panagiotis Kanavos Nov 28 '19 at 11:40
  • Thank you, that worked for the Windows terminal and I able to at least get my web program running. But it does not work for the VSCode integrated terminal which is a large inconvenience. It gives me an error when I run flask run after I set the api_key as `RuntimeError: API_KEY not set` Anyone know how to run the web app from VSCode's integrated terminal? – Steven Kim Nov 28 '19 at 19:44
0

If you're using "Run without Debugging" you can modify your launch.json to include an "env" key with mapping of environment variables:

"env": {"API_KEY": "[keyhere]"}
Brett Cannon
  • 14,438
  • 3
  • 45
  • 40