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
# 安装,安装完成后输入python3查看安装成功的版本信息
[root@localhost Python-3.8.16]# make install
# 命令行输出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
。
2 Django项目部署
# 执行下面指令安装 python-devel和 mysql-devel
yum install mysql-devel
yum install python-devel
#安装uwsgi
pip install uwsgi
编写一个django.ini文件,文件内容如下文章来源:https://www.toymoban.com/news/detail-621689.html
[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中的接口文章来源地址https://www.toymoban.com/news/detail-621689.html
location / {
uwsgi_pass 127.0.0.1:9090;
uwsgi_param UWSGI_SCRIPT django_one.wsgi;
include uwsgi_params;
}
到了这里,关于linux安装python和部署Django项目的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!