背景:windows中使用pycharm完成python项目,需在linux部署。
1. 下载Anaconda3-2021.05-Linux-x86_64.sh 文件
2. 执行命令 sh Anaconda3-2021.05-Linux-x86_64.sh
3. 安装过程中,中间会有输入 "yes" 或 "no"的选项,一般全部输入“yes”.
4. 添加软链接 ln -s /***/***/Anaconda3/bin/python /usr/bin/python3
5. 执行 python3, 看到进入python3命令行,即表示Anaconda安装成功。
1. 联网环境:
直接执行 python38 -m pip install numpy 类似的命令;
2. 离线环境
2.1 互联网下载需要的依赖包 主要有 ****.whl 和 ****.tar.gz 两种格式
2.2 将依赖包上传至离线Linux系统
2.3 执行 python38 -m pip install ****.whl 即可安装
1. 将windows开发好的 python项目文件上传至linux
2. 进入主函数Py文件 (如test.py) 所在目录
3. 执行命令 nohup python3 test.py runserver &
4. 遇到报错信息:
项目中import自定义模块报错,找不到模块。
解决方案:将自定义模块所在目录全部加入系统路径

如 我的test.py文件在my_api文件夹中,在test.py文件中执行以下代码,就能将my_api上一级目录,及上一级目录对应的所有子目录加入sys.path
- def append_my_path():
- cur_path = os.path.abspath(os.path.dirname((__file__)))
- root_path = os.path.split(cur_path)[0]
- sys.path.append(root_path)
- sub_dir_lists = os.listdir(root_path)
- for dir in sub_dir_lists:
- sub_dir = root_path + "/" + dir
- if os.path.isdir(sub_dir):
- sys.path.append(sub_dir)