Python 3

Install on Centos


sudo yum install -y
sudo yum install -y python3
sudo yum install -y python3-devel
mkdir testpython
cd testpython
python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip

Convert production project from python 2 to python 3


python3 can’t pip install pywin32 on linux. pywin32 must be removed from requirements.txt file before fab ... deploy

Add the following code to <project>.wsgi file to support the python3 proxy handler

# see
from werkzeug.middleware.proxy_fix import ProxyFix
application.wsgi_app = ProxyFix(application.wsgi_app, x_proto=1, x_host=1)

Convert venv to python3

cd /var/www/<vhost>
sudo rm -Rf venv
sudo mkdir venv
sudo chown <vhostuser>:<vhostuser> venv
sudo su <vhostuser>
(<vhostuser>) python3 -m venv venv
(<vhostuser>) exit
sudo cp /home/lking/activate-this/ venv/bin
sudo chown -R <vhostuser>:apache venv/bin/
sudo su <vhostuser>
(<vhostuser>) source venv/bin/activate
(<vhostuser>/<vhost>/venv) pip install --upgrade pip
(development) fab -H <vhost> deploy

Create python3 service - see Set Script as Service

Install on Windows


  • navigate to

  • select/download latest 3.6 release

  • run installer

    • important You want to be sure to check the box that says Add Python 3.x to PATH as shown to ensure that the interpreter will be placed in your execution path.

  • click Install Now

Convert development project from python 2 to python 3

  • conversion -


    Check directory twice – be careful not to overwrite venv, python, etc!

    python "C:\Users\lking\AppData\Local\Programs\Python\Python36\Tools\scripts\" -w -n -f all -f idioms -f set_literal <package>
  • check for integer division /, replace with //

  • look for usages of cmp in sort, not supported any more

  • urlsafe_b64encode requires bytes, not str

  • check file opens around csv classes (e.g., DictReader, DictWriter) should use mode ‘r’ and ‘w’ and param newline=’’

    • in fact look for ‘wb’ and ‘rb’ as there may be other binary file operations which need to be fixed

    • within __main__ seems like cannot do from . import xxx (e.g., version); needs to be moved to main() as from <project> import xxx

  • argparse.ArgumentParser() doesn’t have version keyword

  • remove venv virtualenv for python 2

  • create venv virtualenv for python 3

  • install requirements (see

    pip install -r requirements.txt
    pip install pip-upgrader
    pip freeze > requirements.txt

Upgrade to newer version of python 3

Development Environment

  • upgrade package requirements (see

    pip install -U pip
    [pip install pip-upgrader]


    this updates requirements.txt

  • mv venv virtualenv to venv-<oldpyver> to save in case of problems with the below

  • create venv virtualenv for new python version, use latest pip

    python<ver> -m venv venv
      # vscode popup - accept new venv as workspace folder
    pip install -U pip
  • install requirements

    python -m pip cache purge
    pip install -r requirements.txt
  • if resolution errors occur remove problem package from requirements.txt and retry to let pip resolve the correct version

  • upgrade package requirements again, for new python (see

    pip install -r requirements.txt # check resolution errors
    pip freeze > requirements.txt
  • check that pip-upgrade installed compatible versions

    pip install -r requirements.txt
  • set interpreter for vscode [may have to delete and recreate venv if interpreter cannot be selected]

    • click on python version number in status bar (on bottom of vscode window)

    • make sure it is set to .\venv\Scripts\python.exe

    • restart vscode window

  • remove venv-<oldpyver>

  • test application, resolve any issues

  • commit changes

Target Environment

  • stop service

    # from sudouser account
    # stop service
    sudo systemctl stop vhost-<appl>-<tld>.service
  • upgrade venv

    # from <appuser> account (see app configuration)
    (<appuser>) cd /var/www/<tld>.<shortapp>
    (<appuser>) rm -rf venv/*
    (<appuser>) /usr/local/bin/python<ver> -m venv venv
    (<appuser>) source venv/bin/activate
    (<appuser>/venv) pip install -U pip
    (<appuser>/venv) pip cache purge
  • fab deploy release

  • install packages and create apache control files

    # from sudouser account
    # <portnum> is in /root/bin/mod_wsgi-express-readme.txt
    sudo cat /root/bin/mod_wsgi-express-readme.txt
    # NOTE: for scoretility use sudo /root/bin/init-mod_wsgi-express-uplevel rrwebapp [sandbox.] scoretility scoretility <portnum>
    sudo /root/bin/init-mod_wsgi-express <reponame> <tld>.<shortapp> <appuser> <appuser> <portnum>
    sudo cp /home/lking/activate-this/ /var/www/<tld>.<shortapp>
    sudo chown -R <appuser>:apache /var/www/<tld>.<shortapp>
    # test apache [optional]
    sudo /etc/mod_wsgi-express/<tld>.<shortapp> start
    sudo /etc/mod_wsgi-express/<tld>.<shortapp> stop
    # start service
    sudo systemctl start vhost-<appl>-<tld>.service
    # verify vhost operation using browser


    <tld> is sandbox, www
    <shortapp> is routes, scores, members, contracts, [others?]
    <reponame> is runningroutes, rrwebapp, members, contracts, [others?]
    <appuser> [check configuration]