linux环境部署python3+django

时间:2022-04-25 14:09:59

1. 确定Linux安装C/C++编译器,在线安装: yum install gcc gcc-c++ autoconf automake

2. 安装依赖环境: yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

3. 下载python3.7: wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

4. 解压python3.7: tar -zxvf Python-3.7.0.tgz

5. 创建安装目录: mkdir -p /usr/local/python3

6. 进入解压的目录, 编译安装, 需要耗费点时间, 这个过程如果失败, 看下日志缺少什么就安装什么: cd Python-3.7.0; ./configure --prefix=/usr/local/python3; make; make install

7. 建立python3软链接: ln -s /usr/local/python3/bin/python3 /usr/bin/python3; ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

8. 添加到环境变量: vi /etc/profile; source /etc/profile

PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

9. 查看是否安装成功: python3 -V; pip3 -V

linux环境部署python3+django

10. 安装django, 等待安装即可: pip3 install django

11. 随便创建一个workspace, 进入到创建的目录, 创建django项目: django-admin startproject [your project name]

12. 进入到创建的项目, 启动django项目, 看是否部署OK: python manage.py runserver 0.0.0.0:8001

也可以使用nohup后台启动: nohup python manage.py runserver 0.0.0.0:8001 &

13. 打开浏览器, 输入地址: http://[your IP]:8001/