1、ModuleNotFoundError: No module named '_ssl' 编译安装python前,打开Setup.dist中以下几行注释 编辑usr/local/Python-3.9.5/Modules/Setup.dist SSL=/usr/local/ssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/opens
1、ModuleNotFoundError: No module named '_ssl'
编译安装python前,打开Setup.dist中以下几行注释
编辑usr/local/Python-3.9.5/Modules/Setup.dist
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
然后再编译安装python
./configure --with-ssl --prefix=/usr/local/python3.9.5make&&make instll
2、运行xadmin报错
File "/root/.virtualenvs/luffy/lib/python3.9/site-packages/xadmin/plugins/importexport.py", line 48, in <module>from import_export.admin import DEFAULT_FORMATS, SKIP_ADMIN_LOG, TMP_STORAGE_CLASS
ImportError: cannot import name 'DEFAULT_FORMATS' from 'import_export.admin' (/root/.virtualenvs/luffy/lib/python3.9/site-packages/import_export/admin.py)
解决方案:
注释报错行:
/root/.virtualenvs/luffy/lib/python3.9/site-packages/xadmin/plugins/importexport.py
from import_export.admin import DEFAULT_FORMATS, SKIP_ADMIN_LOG, TMP_STORAGE_CLASS重新导入,添加以下两行:
from import_export.formats.base_formats import DEFAULT_FORMATSfrom import_export.admin import ImportMixin, ImportExportMixinBase
3、ModuleNotFoundError: No module named 'virtualenvwrapper'
安装虚拟环境
pip3 install virtualenvpip3 install virtualenvwrapper
配置变量环境
vim ~/.bashrc
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3export VIRTUALENVWRAPPER_VIRTUALENV=/usr/bin/virtualenv
source /usr/local/python3/bin/virtualenvwrapper.sh
source ~/.bashrc
4、安装uswgi报错
报错1:
WARNING: Discarding http://mirrors.cloud.aliyuncs.com/pypi/packages/f7/64/9d5b5cc503dae67fa55c73f0eedfea06e44f612ee964a0b2a3a9cd0189ae/uwsgi-1.4.10.tar.gz#sha256=d4c30a6496d7d7be59f0264393649b9bd5ec58f72c4c3b79b8160b25c193c512 (from http://mirrors.cloud.aliyuncs.com/pypi/simple/uwsgi/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/9e/9a/3638f702fa8e61c85b1176db1a68a76e5eceef8fedd9c26a8b55a51a6581/uwsgi-1.4.9.tar.gz (590 kB)
|████████████████████████████████| 590 kB 155 kB/s
ERROR: Command errored out with exit status 1:
command: /usr/local/python3/bin/python3.9 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-oyzteori/uwsgi_6dbf2cdc9a9546f4b5008f8867f6294e/setup.py'"'"'; __file__='"'"'/tmp/pip-install-oyzteori/uwsgi_6dbf2cdc9a9546f4b5008f8867f6294e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-_xm07qeo
cwd: /tmp/pip-install-oyzteori/uwsgi_6dbf2cdc9a9546f4b5008f8867f6294e/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/python3/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
from setuptools.dist import Distribution
File "/usr/local/python3/lib/python3.9/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/python3/lib/python3.9/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/python3/lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
WARNING: Discarding http://mirrors.cloud.aliyuncs.com/pypi/packages/9e/9a/3638f702fa8e61c85b1176db1a68a76e5eceef8fedd9c26a8b55a51a6581/uwsgi-1.4.9.tar.gz#sha256=f4d345e3f08bf7859cf92340f79e10d7093e297e54c8448d9c1c821848e7fe2d (from http://mirrors.cloud.aliyuncs.com/pypi/simple/uwsgi/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement uwsgi (from versions: 1.4.9, 1.4.10, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 1.9.7, 1.9.8, 1.9.9, 1.9.10, 1.9.11, 1.9.12, 1.9.13, 1.9.14, 1.9.15, 1.9.16, 1.9.17, 1.9.17.1, 1.9.18, 1.9.18.1, 1.9.18.2, 1.9.19, 1.9.20, 1.9.21, 1.9.21.1, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.5.1, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10, 2.0.11, 2.0.11.1, 2.0.11.2, 2.0.12, 2.0.13, 2.0.13.1, 2.0.14, 2.0.15, 2.0.16, 2.0.17, 2.0.17.1, 2.0.18, 2.0.19, 2.0.19.1, 2.0.20)
ERROR: No matching distribution found for uwsgi
WARNING: You are using pip version 21.1.1; however, version 22.0.4 is available.
You should consider upgrading via the '/usr/local/python3/bin/python3.9 -m pip install --upgrade pip' command.
报错2:
[root@python01 ~]# pip3 install uwsgiLooking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting uwsgi
Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/24/fd/93851e4a076719199868d4c918cc93a52742e68370188c1c570a6e42a54f/uwsgi-2.0.20.tar.gz (804 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 804.9/804.9 KB 10.6 MB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
解决方案:
安装依赖
yum -y groupinstall "Development tools"yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel tk-devel pcre-devel
升级pip和setuptools
/usr/local/python3/bin/python3.9 -m pip install --upgrade pippip3 install --upgrade setuptools
再安装
pip3 install uwsgi5、module 'jwt' has no attribute 'encode'
jwt和PyJWT冲突导致,同时存在jwt和PyJWT模块,import PyJWT导入的还是jwt,解决方法,卸载jwt和PyJWT,然后重新安装PyJWT
pip uninstall jwtpip uninstall PyJWT
pip install PyJWT
6、外键序列化报错
Got AttributeError when attempting to get a value for field `orders` on serializer `CourseSectionSerializer`.The serializer field might be named incorrectly and not match any attribute or key on the `RelatedManager` instance.
Original exception text was: 'RelatedManager' object has no attribute 'orders'.
当外键是一对多关系,在序列化外键的时候需要加入many = True参数
coursesections = CourseSectionSerializer(many= True)6、vue的img向后端nginx请求图片失败(未解决)
vue中在本地像远端的nginx请求图片,返回的格式是text/html,前端无法正常展示(nginx转发img的请求,会改变图片的格式?)
使用curl方式,可以正常返回;并且本地img向本地的django直接请求,也可以正常返回;
本地使用aixos向远端nginx请求,也可以正常返回