栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Django Linux环境安装

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Django Linux环境安装

文章目录
  • 一、概念
    • 1.1 WSGI
    • 1.2 uWSGI
  • 二、使用步骤
    • 1. 安装python
    • 2. pycharm 下远程Linux 同步
  • 三、bug


提示:以下是本篇文章正文内容,下面案例可供参考

一、概念 1.1 WSGI

Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口.使用python manage.py runserver 通常只在开发和测试环境中使用。开发结束后,需要在高效稳定的环境中运行,这时可以使用WSGI
uwsgi 替代runserver

1.2 uWSGI

uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。

WSGI,是一种通信协议。uwsgi同WSGI一样是一种通信协议。 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
uwsgi协议是一个uWSGI服务器自有的协议,它用于定义传输信息的类型(type of information), 每一个uwsgipacket前4byte为传输信息类型描述,它与WSGI相比是两样东西。替代runserver

为什么有了uWSGI为什么还需要nginx?因为nginx具备优秀的静态内容处理能力,然后将动态内容转发给uWSGI服务器,这样可以达到很好的客户端响应。

uWSGI主要学习已配置为主

二、使用步骤

使用docker安装请参考
https://blog.csdn.net/qq_35911309/article/details/116132738

1. 安装python openssl版本最低为1.0.2
查看openssh版本命令
ssh -V
 
查看openssl版本命令
openssl version

系统是centos7,里面的python版本是2.7。官网下载所需版本。

tar -xvf Python-3.8.5.tar.xz
cd Python-3.8.5/
./configure --prefix=/usr
make && make install  

将该软件安装在 /usr 下面,执行文件就会安装在 /usr/bin (而不是默认的 /usr/local/bin),资源文件就会安装在/usr/share(而不是默认的/usr/local/share)。同时一些软件的配置文件
你可以通过指定 --sys-config=参数进行设定。有一些软件还可以加上 --with、–enable、–without、–disable 等等参数对编译加以控制,可以通过允许 ./configure --help 察看详细的说明帮助
比如下面就是指定安装目录/usr/local/python3。 mkdir /usr/local/python3
如果没有用这个选项,安装过程结束后,该软件所需的软件被复制到不同的系统目录下,比较混乱。
删除旧的python的软连接,创建新的python2和python3的软连接,添加pip软链接

rm -f python2
ln -s python3.8 python
ln -s pip3.8 pip
python -V

[root@localhost ~]# python -V
Python 3.8.5

 mkdir /usr/local/python3  
./configure --enable-optimizations --prefix=/usr/local/python3
 make && make altinstall 
# 删除一些临时文件(删除源代码(CC++ code)生成的执行文件和所有的中间目标文件)
make clean
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

将python修改为系统最原始的那个版本。这是因为yum用的是原来2.7的版本。

(1).yum
vim /usr/bin/yum
(2).urlgrabber-ext-down
vim /usr/libexec/urlgrabber-ext-down
(3).firewalld
vim /usr/sbin/firewalld
(4).firewall-cm
vim /usr/bin/firewall-cm
把最顶部的#!/usr/bin/python改为:#!/usr/bin/python2.7
wq 保存,已经是的无须更改

安装virtualenv ,建议大家都安装一个virtualenv,方便不同版本项目管理

pip3 install virtualenv --user -i https://mirrors.aliyun.com/pypi/simple/

附:查找文件

[root@localhost bin]# whereis virtualenv
virtualenv:[root@localhost bin]# find / -name virtualenv
/root/.local/lib/python3.8/site-packages/virtualenv
/root/.local/bin/virtualenv

.英文点号表示这是个隐藏文件

2. pycharm 下远程Linux 同步

pip freeze > requirements.txt

cd testdj # 切换到我们创建的项目
$ python manage.py runserver 0.0.0.0:8000
#centos7查看防火墙所有信息
firewall-cmd --list-all
#centos7查看防火墙开放的端口信息
firewall-cmd --list-ports
systemctl restart firewalld.service //重启防火墙
firewall-cmd --zone=public --add-port=8080/tcp --permanent //开启8080端口
firewall-cmd --reload //重新载入配置
三、bug

问题一
Could not fetch URL https://pypi.python.org/simple/....
然后就是:问题二
Could not find a version that satisfies the requirement tensorflow
答:
加上–trusted-host ,换成了国内的pip源

pip install 安装包名字  -i http://pypi.doubanio.com/simple/ --trusted-host pypi.doubanio.com

问:
ERROR: Could not install packages due to an EnvironmentError: [Errno 28] No space left on device
答:

# 查看磁盘占有空间
df -h 
# 查看哪个文件
du -h -x --max-depth=1
# 显示隐藏目录或隐藏文件的占用空间
du -sh .[!.]*
# 排序
du -sh .[!.]* * | sort -hr 

问:
configure: error: no acceptable C compiler found in $PATH See config.log' for more details
答:
原因是缺少gcc编译环境
安装即可:yum install -y gcc

问:
-bash: make: command not found
答:
因为安装系统的时候使用的是最小化mini安装,
系统没有安装make、vim等常用命令,直接yum安装下即可。
yum -y install gcc automake autoconf libtool make

问:
zipimport.ZipimportError: can't decompress data; zlib not available
答:
centos系统中,zlib的开发链接库软件包是“zlib-devel”,
yum -y install zlib-devel

问:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
答:
查看你当前环境默认使用的 index-url 即 pip 源地址

pip install --help | grep -A 4 '--index-url '

-i, --index-url base URL of the Python Package Index
(default
https://pypi.org/simple). This should point to a
repository compliant with PEP 503 (the simple
repository API) or a local directory laid out in
the same format.

单次指定 index-url 为国内源

pip install {library_name} -i {index_url}

pip install -r requirements.txt -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

修改pip安装源加快python模块安装

mkdir ~/.pip
创建pip.conf文件填写:
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/

问:
Add correct host key in /root/.ssh/known_hosts to get rid of this message. Offending RSA key in /root/.ssh/known_hosts:2 RSA host key for [127.0.0.1]:2222 has changed and you have requested strict checking. Host key verification failed.
答:
openssh会把你每个你访问过计算机的公钥(public key)都记录在~/.ssh/known_hosts
vi ~/.ssh/known_hosts
删除对应ip的相关rsa信息

问:
出现Could not import runpy module“
SystemError: returned NULL without setting an error generate-posix-vars failed make[1]: *** [pybuilddir.txt] Error 1 make[1]: Leaving directory /usr/local/src/Python-3.8.0 make: *** [profile-opt] Error 2
答:
导致原因:
在低版本的gcc中带有–enable-optimizations参数
解决方法(不推荐使用方法1):
1、升级gcc至高版本,gcc 8.1.0已修复此问题
2、./configure参数中去掉–enable-optimizations

问:
Pycharm报错连接linux服务器报错:Could not verifyssh-rsahost key with fingerprint
答:
是本地,不是服务器上的。我的在C:/User/Administor/.ssh/known_hosts 。

问:
Invalid HTTP_HOST header: '10.36.152.2:8000'. You may need to add '10.36.152.2' to ALLOWED_HOSTS
答:
将ALLOWED_HOSTS = []改为ALLOWED_HOSTS = [’*’]

问:
Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")
答:
修改python配置文件,并重新编译安装:
(1)vi Python-3.8.5/Modules/Setup

设置SSL路径,但是这个SSL的安装路径在哪里

whereis openssl


问:
./Modules/_ssl.c:64:25: 致命错误:openssl/rsa.h:没有那个文件或目录
答:

yum install openssl-devel

问:
ModuleNotFoundError: No module named '_ctypes' --Python3
答:

yum install libffi-devel -y
make
make altinstall

问:
pip install uwsgi 之后,运行uwsgi 报错:[uwsgi: command not found]
答:
建立软链接
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

问:
Error response from daemon: conflict: unable to delete a2f2e369e78e (cannot be forced) - image has dependent child images
答:


问:
docker run -it -p 2222:22 -p 8000:8000 c6b614076583
iptables问题---docker: Error response from daemon: driver failed programming external conne...
答:
systemctl restart docker(重新启动docker


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/338351.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号