官网地址: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
# 安装,安装完成后输入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]# yum
File "/usr/bin/yum", line 30
except KeyboardInterrupt, e:
^
SyntaxError: invalid syntax
编辑文件vim /usr/bin/yum
,将首行修改为#!/usr/bin/python2
。
# 执行下面指令安装 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 8月 1 10:24 django.ini
drwxr-xr-x. 10 root root 184 7月 31 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;
}