c3cris c3cris - 2 months ago 6
Git Question

Best practice to deploy python app to use a specific version of Python with venv

I am done with a project and it has been been pushed to git but the client wants VENV. I already got

venv
to work and created a
requirements.txt
file.

My question is what is the best practice for a deployment workflow. So far this is what I created as a deploy workflow:

git clone ssh://myawesomerepo
cd myawesomerepo
pip install virtualenv
venv -python=python3.5 env
source env/bin/activate
pip install -r requirements.txt
python run.py


Is this the correct workflow?

Assuming that we don't know what version of python the client has. My project is written for python 3.5, and if the client has 2.7 will this work?*

Answer

I use the following bash script to install my python applications: I check for either versions of pip ( 2.x or 3.x ) if they are in PATH:

#!/bin/bash
if [ command -v pip3 >/dev/null 2>&1  ]; 
then
    echo "installing virtual env with pip3"
    pip3 install virtualenv
else
    echo "installing virtual env with pip"
    pip install virtualenv
fi

echo "Installing python 3.5 bin"
virtualenv --python=python3.5 env

echo "Activate virtual env"
source env/bin/activate

echo "Installing requirements"
pip install -r requirements.txt