当前位置: 首页 > news >正文

linux安装python和部署Django项目

文章目录

      • 1 python安装
      • 2 Django项目部署

1 python安装

官网地址:https://www.python.org/

本次下载的python安装包地址:https://www.python.org/ftp/python/3.8.16/Python-3.8.16.tgz

解压下载的python压缩包

[root@localhost software]# tar -zxvf Python-3.8.16.tgz
# 进到解压后的目录执行configure
[root@localhost Python-3.8.16]# ./configure 
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.8... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "linux"
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/home/dream21th/software/Python-3.8.16':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
#安装GCC
[root@localhost Python-3.8.16]# yum install gcc -y
# 安装下面python暗转需要的依赖包
yum install zlib zlib-devel openssl openssl-devel
yum install glib2-devel openssl-devel pcre-devel bzip2-devel gzip-devel
yum install libffi-devel -y
yum install zlib zlib-devel
yum install libjpeg libjpeg-devel
yum install freetype freetype-devel
# 编译
[root@localhost Python-3.8.16]# make

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-mf6vqyuR-1690860274922)(D:\developsoftware\mayun\note\study-note\python\images\image-20230731161649517.png)]

# 安装,安装完成后输入python3查看安装成功的版本信息
[root@localhost Python-3.8.16]# make install

![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-r5fnZoOB-1690860274924)(D:\developsoftware\mayun\note\study-note\python\images\image-20230731162009979.png)](https://img-blog.csdnimg.cn/2a40c4f2f19943a399c493dc179ba3a2.png)

# 命令行输出python看到的还是系统自带默认的python2.7.5版本
[root@localhost Python-3.8.16]# python
Python 2.7.5 (default, Oct 14 2020, 14:45:30) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
# 查看python3, pip3的安装路径
[root@localhost Python-3.8.16]# find / -name python3
/usr/local/bin/python3
[root@localhost Python-3.8.16]# find / -name pip3
/usr/local/bin/pip3
[root@localhost Python-3.8.16]# find / -name python
/etc/python
/usr/bin/python
/usr/share/gcc-4.8.2/python
/usr/share/bash-completion/completions/python
/home/dream21th/software/zookeeper-3.4.14/zookeeper-contrib/zookeeper-contrib-rest/src/python
/home/dream21th/software/zookeeper-3.4.14/zookeeper-contrib/zookeeper-contrib-zkpython/src/python
/home/dream21th/software/Python-3.8.16/python
[root@localhost Python-3.8.16]# find / -name pip
/usr/local/lib/python3.8/site-packages/pip
/home/dream21th/software/Python-3.8.16/Tools/msi/pip
#创建软连接将/usr/bin/python 指向/usr/local/bin/python3,这个时候在命令行输入python就是使用python3
[root@localhost bin]# mv python python.bak
[root@localhost bin]# ln -s /usr/local/bin/python3 /usr/bin/python
[root@localhost bin]# python
Python 3.8.16 (default, Jul 31 2023, 16:12:21) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
#创建软连接将/usr/bin/pip 指向/usr/local/bin/pip3,这个时候在命令行输入pip就是使用pip3
[root@localhost bin]# ln -s /usr/local/bin/pip3 /usr/bin/pip
#经过上面的创建之后,yum指令会出错,将第一行修改为#!/usr/bin/python2
[root@localhost bin]# yumFile "/usr/bin/yum", line 30except KeyboardInterrupt, e:^
SyntaxError: invalid syntax

编辑文件vim /usr/bin/yum,将首行修改为#!/usr/bin/python2

2 Django项目部署

# 执行下面指令安装  python-devel和 mysql-devel
yum install mysql-devel
yum install python-devel
#安装uwsgi
pip install uwsgi

编写一个django.ini文件,文件内容如下

[uwsgi]
socket =0.0.0.0:9090
master =1
processes =1
pidfile = /var/run/django_one.pid
#日志路径
daemonize = /var/log/uwsgi/django_one.log
#模块
module = django_one.wsgi:application
#项目目录
chdir =/home/dream21th/code/django_one
listen = 100
buffer-size =32768
max-requests = 200
[root@localhost code]# ll
总用量 4
-rw-rw-r--.  1 dream21th dream21th 255 81 10:24 django.ini
drwxr-xr-x. 10 root      root      184 731 17:09 django_one
#启动项目
[root@localhost code]# uwsgi --ini django.ini

在nginx中配置下面信息,就可以访问Django中的接口

       location / {uwsgi_pass 127.0.0.1:9090;uwsgi_param UWSGI_SCRIPT django_one.wsgi;include uwsgi_params;}
http://www.lryc.cn/news/105508.html

相关文章:

  • 00-Hadoop入门
  • SE-Net注意力机制详解
  • 商城免费搭建之java商城 开源java电子商务Spring Cloud+Spring Boot+mybatis+MQ+VR全景+b2b2c bbc
  • 推理加速 --- torch.compile
  • JS-----数据结构与算法(2)
  • 手把手安装TomCat;并部署JPress
  • tensorflow1.13分布式训练 参考资料 -教程原理
  • DP学习第五篇之礼物的最大价值
  • cURL error 1: Protocol “https“ not supported or disabled in libcurl
  • XCode升级后QT无法编译的问题
  • springboot编写mp4视频播放接口
  • 华为OD机试真题 JavaScript 实现【机器人活动区域】【2023Q1 200分】,附详细解题思路
  • C++中的静态分配和动态分配
  • 【Android常见问题(五)】- Flutter项目性能优化
  • JSON转换:实体类和JSONObject互转,List和JSONArray互转(fastjson版)
  • Java单例模式几种代码详解
  • PHP代码审计--理论
  • 在云服务器上,clone github时报Connection timed outexit code: 128
  • 小型双轮差速底盘寻迹功能的实现
  • 第七篇:k8s集群使用helm3安装Prometheus Operator
  • Chrome 75不支持保存成mhtml的解决方法
  • 工程监测振弦采集仪应用于岩土工程监测案例
  • 配置HDFS单机版,打造数据存储的强大解决方案
  • U盘删除的文件怎么找回?4个简单方法分享!
  • 【雕爷学编程】MicroPython动手做(27)——物联网之掌控板小程序2
  • 形参动态内存开辟和柔性数组
  • 【LLM系列之指令微调】长话短说大模型指令微调的“Prompt”
  • MacOS使用brew如何下载Nginx
  • linux ftp
  • 你知道HTTP与HTTPS有什么区别吗?