在服务器上 运行Django 项目,报错解决方案

1,No module named ‘_ctypes’

File "/usr/local/python3/lib/python3.7/ctypes/__init__.py", line 7, in <module>    from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes'

原因 Python3 有个内置包 ctypes 是一个 哇哦不函数库模块,提供兼容C语言的数据类型,通过调用Linux系统下的共享库,此模块需要使用CentOS7系统中外部函数库的开发练级库

解决方案

简单安装 外部函数库 libffi 就可以,操作步骤如下

1,使用 yum install 安装 libffi-level

    yum install libffi-devel -y

2,在 python 中 使用 make & make install重新编译并安装 python

make & make install

3, 最后测试即可;

参考文章:https://www.jianshu.com/p/69681655309b


2,no module named _ssl

缺少 ssl 包

centos 重新安装,再重新编译

yum install openssl-devel -y

修改 安装包\Modules\Setup中 以下内容

# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto

重新编译

make && make install

测试

[root@iZbp1iyr83m78fp8yjv65xZ Python-3.7.6]# python3
Python 3.7.6 (default, Apr  2 2022, 22:15:08) 
[GCC 10.2.1 20200825 (Alibaba 10.2.1-3 2.32)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> exit()

猜你喜欢

转载自blog.csdn.net/weixin_42512684/article/details/124266984
今日推荐