Flask installation and setup (python, virtualenv, flask) - notes

Written by Administrator on Tuesday March 10, 2020

Need to install: python, virtualenv, pip, flask

Python

Python installation directories for python (all versions), python2.7, python3.6 and python3.8:

$ whereis python
$ whereis python2.7
$ whereis python3.6
$ whereis python3.8

Then you will see all directories, where python can be found:

Or there is different way to find python installation locations:

$ type -a python
$ type -a python2.7
$ type -a python3.6
$ type -a python3.8

Then you will see installation folders in different way:

Then let's install pythonpy:

$ sudo apt install pythonpy

then let's check the version of pythonpy:

$ py -m pip --version

Then you will receive something like this:

Virtualenv

Virtualenv for python 2.7

Check, if virtualenv is installed:

$ virtualenv --version

Then let's check virtualenv installation folders:

$ type -a virtualenv

Venv for python 3+

Venv is a module for managing virtual environments for Python3.

Let's create folder for project environments:

$ mkdir python_projects

and let's create our first environment:

$ cd python_projects
$ sudo python3 -m venv TestProject_01
$ cd TestProject_01
$ ls -la

Now we need to activate the TestProject_01 environment:

$ source /bin/activate

activation of environment in python

Flask installation

So, our environment is now activated, we can install Flask using pip. Pay attention, that if you try to install Flask under root, it will mess up the system and could potentially bring some problems with rights.

$ pip install Flask

Now we can check, which Flask version is installed:

$ python
Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__

If you forget, how to exit python environment, just click Ctrl+D.

Category: linux Tags: bash linux python virtualenv venv