WebFaction
Community site: login faq

49 topics involving Flask, but they're all old - not a single one references pipenv. I've tried following some of the venv cookbooks but there's too much different - it's like a monkey hitting keys on a typewriter.

Anyone have a tutorial using pipenv?

asked 12 Feb, 12:53

whil's gravatar image

whil
111
accept rate: 0%


Here's what to do to get the flask minimal app shown at the quickstart page of their documentation up and running using our mod_wsgi installer.

Start an ssh session and install pipenv using easy_install-3.6 pipenv if you haven't already.

Then create a new mod_wsgi app using our control panel installer. Please make a note of the python version you've selected because it will be needed later.

If you named the new app flask for example, go to ~/webapps/flask and run pipenv --python 2.7 or pipenv --python 3.6 depending on the python version you've chosen in the installer's page.

You can activate your new virtualenv using the pipenv shell command, install the flask framework with pipenv install flask and then note down the location of your virtualenv shown by pipenv --venv, as it will be needed later.

The lib and htdocs directories are not needed and you can do rm -rf htdocs/ lib/ to remove them, followed up by the creation of the directory that will host our code, mkdir src.

Create a file named src/hello.py and write the contents of the minimal application there using your favorite text editor.

Create one more file named src/wsgi.py with the following contents:

from hello import app as application

Finally, you will need to configure apache by updating the apache2/conf/httpd.conf file. You do not need the DirectoryIndex and DocumentRoot directives so remove them as well as the 4 lines within the <directory> section.

In the WSGIDaemonProcess line, change the python-path= part to only include the /home/your_username/webapps/flask/src directory and not the /home/your_username/webapps/flask/lib/pythonX.Y one and then add:

WSGIPythonHome "location of the virtualenv directory from pipenv --venv" WSGIScriptAlias / /home/your_username/webapps/flask/src/wsgi.py

It should look like this:

WSGIDaemonProcess flask processes=2 threads=12 python-path=/home/your_username/webapps/flask/src WSGIPythonHome /home/your_username/.local/share/virtualenvs/flask-bwxEPKz7 WSGIProcessGroup flask WSGIRestrictEmbedded On WSGILazyInitialization On WSGIScriptAlias / /home/your_username/webapps/flask/src/wsgi.py

When that's done, you can restart apache using the ./apache2/bin/restart command for the changes to take effect.

permanent link

answered 2 days ago

iliasr's gravatar image

iliasr ♦♦
1.8k14
accept rate: 36%

edited 2 days ago

Here's what to do to get the flask minimal app shown at the quickstart page of their documentation up and running using gunicorn.

Start an ssh session and install pipenv using easy_install-3.6 pipenv if you haven't already.

Then create a new Custom app (listening on port) type of application using our control panel installer. Note the port that the app was assigned, as it is needed later.

If you named the new app flask for example, go to ~/webapps/flask and run pipenv --python 2.7 or pipenv --python 3.6 depending on the python version you want to use for your project.

You can activate your new virtualenv using the pipenv shell command, install the flask framework and the server with pipenv install flask gunicorn and then note down the location of your virtualenv shown by pipenv --venv, as it will be needed later.

Create a directory that will host our code, mkdir src and cd into it.

Create a file named hello.py and write the contents of the minimal application there using your favorite text editor.

You can run gunicorn -w 2 -b 127.0.0.1:PORT hello:app, where PORT is the port number your custom application was assigned to get it up and running.

You will need to create a configuration file for gunicorn. A sample would look like:

chdir = "/home/your_username/webapps/flaskgu/src" bind = "127.0.0.1:PORT" daemon = True workers = 2

If that file is located in the ~/webapps/flask/ directory you can run gunicorn --config ~/webapps/flask/gunicorn.conf hello:app within an active virtual environment to get it working.

Gunicorn has a lot of options that you can add to that configuration file and they can be found here.

permanent link

answered 2 days ago

iliasr's gravatar image

iliasr ♦♦
1.8k14
accept rate: 36%

edited 2 days ago

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×44
×1

question asked: 12 Feb, 12:53

question was seen: 315 times

last updated: 2 days ago

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM