Python Notes

Submitted by code_admin on Mon, 07/30/2018 - 13:26

Virtualenv - projects using different versions of modules

Install

Python 3.6

  1. sudo add-apt-repository ppa:deadsnakes/ppa
  2. sudo apt-get update
  3. sudo apt-get install python3.6
  4. sudo curl https://bootstrap.pypa.io/get-pip.py | sudo python3.6

Update line depending on available:

  1. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
  2. sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
  3. sudo update-alternatives --config python3
  1. sudo pip3 install virtualenv virtualenvwrapper

add the following to the end of ~/.bashrc

  1. # ADDED RJM for virtualenv
  2. export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
  3. export WORKON_HOME=~/virtualenvs
  4. source /usr/local/bin/virtualenvwrapper.sh

Setup new project

  1. mkvirtualenv dockJob

Work on project

  1. workon dockJob

Deactivate

  1. deactivate

Other notes

I have had to install nose and rednose in virtualenvs because they refer to python and were leaving the virtualenv
I had problem with depdancies that was caused by modules not specfying the version of pytz required. To resolve I had to remove than manually install the one I wanted.

  1. sudo pip install -r ./src/requirments.txt

Ref:
http://exponential.io/blog/2015/02/10/install-virtualenv-and-virtualenv…
http://docs.python-guide.org/en/latest/dev/virtualenvs/

pip check version

  1. pip show modulename

Simple web server

Used for SOA Component Viewer

  1. python -m http.server 8000

Python3 might be a different executable:

  1. python3 -m http.server 8000

Tags

RJM Article Type
Quick Reference