A web project template of Python3 using tornado and built with buildout.
- Python 3 (I'm using Python 3.7.2, and I suppose Python 3.5+ will do)
- MySQL (On MacOS, I'm using [email protected], while on Linux, I'm using mariadb)
sudo python -m pip install zc.buildout
(orpython -m pip install zc.buildout --user
);- Run
make all
(or reading Makefile);
- On MacOS, run
brew install [email protected]
, and add this to your bashrc or zshrc;
# mysql 5.7 at MacOS
export MYSQL_HOME="/usr/local/opt/[email protected]"
export PATH="$MYSQL_HOME/bin:$PATH"
export PKG_CONFIG_PATH="$MYSQL_HOME/lib/pkgconfig"
# For compilers to find [email protected]
export LDFLAGS="-L/usr/local/opt/[email protected]/lib -L/usr/local/opt/[email protected]/lib"
export CPPFLAGS="-I/usr/local/opt/[email protected]/include -I/usr/local/opt/[email protected]/include"
python -m pip install zc.buildout
;- Run
make all
;
pip freeze | grep -Eo '(.*==)' | sed 's/==//g' > requirements.txt
Run bin/amazing_api
using default port 8000 and env dev or bin/amazing_api --port=8xxx --env=dev|prod
.
Run curl http://localhost:8xxx
will get a message in json format:
{
"msg": "hello"
}
virtualenv
is a tool to create isolated Python environments. It creates an environment that has its own installation
directories, that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally
installed libraries either). Docs can be found here.
virtualenvwrapper
is a set of extensions to Ian Bicking’s virtualenv tool. The extensions include wrappers for
creating and deleting virtual environments and otherwise managing your development workflow, making it easier to work
on more than one project at a time without introducing conflicts in their dependencies.
Docs can be found here.
- Run
python -m pip install virtualenv virtualenvwrapper
; - Add
source /usr/local/bin/virtualenvwrapper.sh
to your bashrc or zshrc (orsource /usr/bin/virtualenvwrapper.sh
, you should locate on your own OS usingwhich virtualenvwrapper.sh
);
Command | Description |
---|---|
mkvirtualenv |
create a virtual env using specified python, default using env python |
lsvirtualenv |
list all virtual env created |
rmvirtualenv |
remove specified virtual env on disk |
workon |
list all virtualenv if no env is specified or activate specified env |