常用命令

40 阅读2分钟

git操作

- git clone -b {branch_name} {url} # 从github克隆指定分支的项目
- git remote -v # 查看项目关联的远程仓库
- git add . # 将代码存入暂存区
- git commit -m {message} # 提交代码
- git push # 推送代码到远程仓库
- git pull # 拉取远程代码到本地
- git branch {newbranch} # 新建分支
- git checkout {branch} # 切换分支
- git push --set-upstream origin {new_branch} # 将本地dev分支推送到远程
- git merge {branch} # 合并指定分支到当前分支

conda相关

- conda env list # 列出所有环境
- conda create -n 环境名 python=3.11 # 创建conda环境
- conda activate 环境名 # 激活环境
- conda deactivate # 退出当前环境
- conda remove -n 环境名 --all # 删除环境

HDFS相关

# 新建文件夹
- hadoop fs -mkdir '/user/hadoop/zhongxinhao/'
# 查询文件夹
- hdfs dfs -ls '/user/hadoop/zhongxinhao/'
# 上传数据
- hdfs dfs -put 'file1.json' '/user/hadoop/zhongxinhao/file1.json'
# 下载数据
- hdfs dfs -get '/user/hadoop/zhongxinhao/file1.json'
# 删除数据
- hdfs dfs -rm '/user/hadoop/zhongxinhao/file1.json'
# 查看文件内容
- hdfs dfs -cat '/user/hadoop/zhongxinhao/file1.txt'
- hdfs dfs -tail '/user/hadoop/zhongxinhao/file1.txt'
# 移动或重命名文件
- hdfs dfs -mv '/user/hadoop/zhongxinhao/file1.txt /user/hadoop/zhongxinhao/file2.txt'
# 拷贝文件
- hdfs dfs -cp '/user/hadoop/zhongxinhao/file1.txt /user/hadoop/zhongxinhao/file2.txt'

Python包管理uv

# 安装uv
pip install uv

# 创建虚拟环境并指定Python版本
uv venv --python 3.9.7
source .venv/bin/activate

# 安装单个包 
uv add requests

# 查看已安装包
uv pip list

FastAPI

简介

  • FastAPI 是一个用于构建 API 的现代、快速(高性能)的 web 框架,使用 Python 3.8+ 并基于标准的 Python 类型提示。
  • Uvicorn是一个基于ASGI(Asynchronous Server Gateway Interface)的异步Web服务器,用于运行异步Python web应用程序。它是由编写FastAPI框架的开发者设计的,旨在提供高性能和低延迟的Web服务

安装教程

pip install fastapi
pip install uvicorn

快速入门

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def index():
    return {"message": "Hello World"}

@app.get("/info")
async def info():
    return {
        "app_name": "FastAPI框架学习",
        "app_version": "v0.0.1"
    }

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)
  • def:使用 def 关键字定义的函数是同步函数。这意味着当你调用这样的函数时,程序会等待该函数执行完成,并返回结果后,才会继续执行后续的代码。
  • async def:使用 async def 定义的函数是异步函数,也称为"协程"。这意味着你可以在该函数中执行异步操作,并且不会阻塞程序的其他部分。
  • FastApi框架在启动时,除了注册路由之外,还会自动生成API在线文档,并且生成两种在线文档: Swagger UI 和 ReDoc,访问地址分别为: SwaggerUi风格文档:http://127.0.0.1:8000/docs、ReDoc风格文档:http://127.0.0.1:8000/redoc