下载与安装
下载git并安装,可考网上的详过程,这里不赘述,去githubu注册账号,然后登录,建立一个库,如图
这里以first库为例。打开该库后,展开Code,复制HTTPS下面的连接。接下来进行clone。
Clone github库
在本地的目标文件夹(如:sentisensor)内点击右键选择 git bash here ,弹出的窗口里输入 git clone https://github.com/legend-design/first.git,回车,得到如下图得文件夹结构(第一次clone只有.git文件夹和README.md文件,且需要打开文件扩展名猜可见.git文件夹)
(该步骤可选)创建虚拟环境,如果事先没有安装virtualenv库,需要在DOS窗口中 pip install virtualenv执行安装,配置虚拟环境的好处是为每个python项目创建一个独立的运行环境,不相互干扰。
打开sentisensor文件夹,空白位置处,单击右键,启动git bash,运行 virtualenv env。 其中env为虚拟环境名称,可换成自己的名称,注意改动后续的gitignore文件中的名称。
激活虚拟环境 source env/scripts/activate
安装项目必须的库,比如 pip install flask pandas pipreqs plotly
从windows窗口打开刚才创建的文件夹 sentisensor ,新建两个文件 Procfile(无扩展名) app.py
Procfile 的内容为:
web: gunicorn --bind 0.0.0.0:$PORT app:app --preload
app.py的内容为:
from flask import Flask
app = Flask(name)
@app.route(’/’)
def index():
return ‘Web App with Python Flask!’
app.run(host=‘127.0.0.1’)
在git bash 运行 pipreqs ./ --encoding=utf8,这一步为了生成 requirements.txt 安装列表,告诉heroku,你的项目需要安装的库
手工往 requirements.txt 加入一行 gunicorn
签入到heroku(事先注册heroku账号,并绑定github的repository)
git add .
git commit -m ‘代码改动描述’
git push origin main
如下图
解决github clone 慢的问题
https://blog.csdn.net/weixin_42886104/article/details/106454331
https://blog.csdn.net/weixin_41190227/article/details/109542574
https://zhuanlan.zhihu.com/p/133697788
参考文件(有改动):https://www.cnblogs.com/OnlyMeMe/p/14910989.html