有時你的app應用渐逃,會用到多個平臺耍目,比如:Python + Node.js
ref: https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app
Flask網(wǎng)站輕松部署到免費主機Heroku(2) - 清除數(shù)據(jù)
vue2+Flask網(wǎng)站觉鼻,輕松部署到免費主機Heroku(1)
HowTo:
heroku buildpacks --app <App Name>
=== <App Name> Buildpack URL
heroku/python
heroku buildpacks:set heroku/python
heroku buildpacks:add --index 1 heroku/nodejs
# 1 is the first buildpack
選擇特定的Python版本:
create runtime.txt
file in root dir
cat runtime.txt
python-2.7.13
# or python-3.6.2
Anaconda Jupyter (IPython)
調(diào)試:
%pdb on
from IPython.core.debugger import Tracer
def f1(a, b):
Tracer()()
a+=b
Tracer()()
return a/b
f1(3, 2)
快捷鍵:
- l 顯示上下文
- a(rgs) 打印所有變量
- b 顯示斷點
- n 下一行(step over)
- s step into
- u 返回上一級
- q 退出
Anaconda
Conda 支持IPython朋鞍,集成了主要的科學計算python packages惯雳,300多MB朝巫,適合懶人下載
并且方便做環(huán)境管理、package管理
常用命令
創(chuàng)建虛擬環(huán)境:
conda create --name <環(huán)境名字> <安裝哪些packages>
比如石景,創(chuàng)建一個python3的環(huán)境劈猿,裝好 anaconda標準的packages:
conda create -n py35 python=3 anaconda
切換環(huán)境
conda env list
activate <環(huán)境名字>
deactivate
conda env export > environment.yml# 導出到文件
conda env create -f environment.yml
刪除環(huán)境
conda remove --name flowers --all
在不同的python間切換
conda search python
$ conda create -n py27 python=2.7 anaconda
# 升級Python
$ conda update python
$ conda install python=3.6
管理包 Packages:
conda list -n snowflakes
conda search beautiful-soup
conda install --name bunnies beautiful-soup
#升級本身
conda update anaconda
Python3 新建應用
虛擬環(huán)境:
創(chuàng)建:python -m venv .\venv
激活:.\venv\Scripts\activate.bat
命令行會提示當前虛擬環(huán)境的名稱復制Heroku git
git clone https://git.heroku.com/<app_Name>.git
## 有時會提示git.heroku.com登錄,這時潮孽,用戶名:空揪荣,密碼:Token
## get Token: heroku auth:token
## 本地修改、調(diào)試
pip freeze #顯示所有依賴
pip freeze > requirements.txt #生成requirements.txt文件
pip install -r requirements.txt #根據(jù)requirements.txt生成相同的環(huán)境
保證有以下模塊:
gunicorn==19.7.1
psycopg2==2.7.3.1
git add .git commit -m "xxx"
git push origin master
Heroku數(shù)據(jù)庫初始化
heroku run bash --app xxx
python manage.py deploy
python manage.py initroleHeroku 環(huán)境變量:
FLASK_CONFIG = heroku本地運行Server
python manage.py runserver遠程訪問:xxx.herokuapp.com
heroku logs --app xxx
Python2 -> Python3
venv安裝:
pip install Flask Flask_sqlalchemy Flask_security Flask_admin Flask_compress Flask_script Flask_Migrateprint --> print()
try: except Except, e: --> except Except as e:
raw_input() --> input()
<> --> not is
from MyModule import func1 --> from .MyModule import func1
-- Flask_Security:
# security = Security(datastore=user_datastore)
# security.init_app(app) -->
security = Security()
security.init_app(app, user_datastore)