Python (Application)

From campisano.org
Jump to navigation Jump to search

python

Install

su -
#### as root
apt-get install python2.7 python-pip python3 python3-pip virtualenv
exit
  • and setup your user environment (you can put the follow in ~/.profile)
export PYTHON_USER_BASE_PATH=`python -m site --user-base`;
export PATH="${PATH}:${PYTHON_USER_BASE_PATH}/bin";
  • cleanup
python -m site --user-base  # WARN! get this path, usually will be ~/.local
rm -rf .local/* .cache/pip/ # WARN! see the content of .local before!

Install software with pip

  • example aws for python2:
python2 -m pip install --user aws-sam-cli==0.23.0
  • example aws for python3:
python3 -m pip install --user awscli==1.17.13

Use of virtualenv

  • example to create a python2 zip package
umask 0000
virtualenv -q -p python2 --no-site-packages env
source ./env/bin/activate
python -m pip install -r requirements.txt -t .
deactivate
cd env/lib/python2*/site-packages/
zip -q -r9 ../../../../helloworld.zip .
cd ../../../../
zip -q -g helloworld.zip app/app.py
rm -rf env
  • example to create a python3 zip package
umask 0000
virtualenv -q -p python3 --no-site-packages env
source ./env/bin/activate
python3 -m pip install -r requirements.txt -t .
deactivate
cd env/lib/python3*/site-packages/
zip -q -r9 ../../../../helloworld.zip .
cd ../../../../
zip -q -g helloworld.zip app/app.py
rm -rf env