Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Flask with pycharm

enter image description here

I'm trying to follow https://developers.openshift.com/en/python-flask.html, to set up a flask app on openshift.

I've followed the directions and have got it working at the command line using git-bash on win7.

/myflaskapp (master)
$ python wsgi.py
127.0.0.1 - - [16/Jun/2015 13:46:10] "GET / HTTP/1.1" 200 12
127.0.0.1 - - [16/Jun/2015 13:46:10] "GET /favicon.ico HTTP/1.1" 404 233
127.0.0.1 - - [16/Jun/2015 13:46:10] "GET /favicon.ico HTTP/1.1" 404 233

However as you can see the 'Run' and 'debug' buttons are greyed out, in Pycharm Pro 4.5. How can I get them working?

like image 235
user1592380 Avatar asked Jun 16 '15 17:06

user1592380


2 Answers

Create a configuration. For the simple app you show, all you need to do is execute flaskapp.py. Right click on flaskapp.py and chose "Create 'flaskapp'". You can chose "Edit Configurations..." from the dropdown to the left of the run button to edit the configuration that's created.

like image 81
davidism Avatar answered Oct 23 '22 12:10

davidism


With PyCharm Community Edition 2019 on Windows :

  • Edit your configuration or Create a new configuration
  • In "Script path" set the path to flask.exe (1)
  • Set "Parameters" to run
  • Add to "Environment variables"
    • FLASK_APP=yourserverfile.py
    • FLASK_ENV=development

Now you can run your app with Shift+F10 (Release) or Shift+F9 (Debug)

Open a web broswer and go to http:127.0.0.1:5000 (if your port is 5000, default port is 5000)

Below Screenshot of configuration

pycharm flask configuration

Notes :

(1) Flask.exe should be in the Scripts directory of the Python path, something like "C:\Users\YOUR_USERNAME\Local\Programs\Python\Python36-32\Scripts\flask.exe"

like image 22
csblo Avatar answered Oct 23 '22 12:10

csblo