python3.7环境下sanic-ext未生效踩坑解析
作者:lvzi 时间:2022-06-30 12:56:35
坑:
在python3.7环境下,通过官方文档安装sanic即扩展插件,但是 sanic-ext
包不起作用,具体的表现为:无法打开路由/docs
。
这里的坑在于,服务启动时,sanic不会报错。因此很难定位出问题在sanic-ext。
原因:
寻找sanic-ext不起作用的原因:
首先在虚拟环境中执行import sanic_ext
结果报错,提示缺少importlib.metadata
查询当前环境下importlib.metadata
的版本,发现在python3.7下importlib.metadata=4.2
由于本人曾在python3.8环境可以正常使用sanic-ext
,所以进入python3.8环境下检查发现importlib.metadata=3.10.0
结论:
python3.7下的importlib.metadata
版本与sanic-ext不匹配,导致其无法起作用
回过头看:
虽然sanic-ext
不会报错,但其实sanic-ext
是否生效是有迹可循的,在sanic启动时,会有一串打印信息,可以通过打印信息中的packages
中是否包含sanic-ext
判断sanic-ext
是否正确生效。
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Sanic v22.9.0 │
│ Goin' Fast @ http://0.0.0.0:12345 │
├───────────────────────┬─────────────────────────────────────────────────────────────────────────────────┤
│ │ mode: debug, single worker │
│ ▄███ █████ ██ │ server: sanic, HTTP/1.1 │
│ ██ │ python: 3.8.8 │
│ ▀███████ ███▄ │ platform: Linux-4.15.0-189-generic-x86_64-with-glibc2.10 │
│ ██ │ auto-reload: enabled, /xx/xx/xx │
│ ████ ████████▀ │ packages: sanic-routing==22.8.0, sanic-ext==22.9.0 │
│ │ │
│ Build Fast. Run Fast. │ │
后记
python3.7的importlib.metadata
高于python3.8的,不符合直觉,可能是装其他东西更新了这个包,所以也许不是python3.7与sanic-ext
不适配,这点有待继续验证,更多关于python3.7环境sanic-ext未生效的资料请关注脚本之家其它相关文章!
来源:https://juejin.cn/post/7193603855504900152
标签:python,环境,sanic-ext,未生效
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用JavaScript访问XML数据
2023-06-29 22:19:08
python读取文件名称生成list的方法
2021-12-21 02:40:34
Python输出\\u编码将其转换成中文的实例
2023-03-30 22:58:02
![](https://img.aspxhome.com/file/2023/9/115799_0s.jpg)
开启Django博客的RSS功能的实现方法
2022-06-16 02:02:04
![](https://img.aspxhome.com/file/2023/4/95674_0s.jpg)
关于分页查询和性能问题
2008-03-11 12:25:00
Python常用模块用法分析
2022-02-05 05:29:43
我是如何从玩Photoshop变成老板的
2008-04-10 11:33:00
![](https://img.aspxhome.com/file/UploadPic/20084/10/2008410114044665s.jpg)
Python第三方库qrcode或MyQr生成博客地址二维码
2023-06-25 06:23:08
![](https://img.aspxhome.com/file/2023/9/109429_0s.png)
Python编程实现线性回归和批量梯度下降法代码实例
2021-10-13 07:33:27
![](https://img.aspxhome.com/file/2023/5/120915_0s.png)
python封装对象实现时间效果
2022-10-30 16:14:01
![](https://img.aspxhome.com/file/2023/2/112742_0s.jpg)
JavaScript 颜色梯度和渐变效果
2009-03-18 11:16:00
![](https://img.aspxhome.com/file/UploadPic/20093/18/ColorGrads-46s.gif)
python中用Scrapy实现定时爬虫的实例讲解
2023-07-26 05:47:01
python实现决策树
2021-11-07 19:14:05
Python整数与Numpy数据溢出问题解决
2023-02-02 00:39:36
![](https://img.aspxhome.com/file/2023/9/115869_0s.jpg)
python通过安装itchat包实现微信自动回复收到的春节祝福
2022-07-09 20:36:26
![](https://img.aspxhome.com/file/2023/4/94694_0s.png)
Python捕获异常堆栈信息的几种方法(小结)
2022-02-19 08:01:30
如何在django中实现分页功能
2021-10-21 03:29:49
![](https://img.aspxhome.com/file/2023/9/86319_0s.png)
Python中is与==的使用区别详解
2023-10-15 04:08:21
![](https://img.aspxhome.com/file/2023/4/101064_0s.png)
MYSQL教程:MYSQL字符集支持
2009-02-27 15:55:00
Python实现企业微信机器人每天定时发消息实例
2023-09-04 22:08:40
![](https://img.aspxhome.com/file/2023/9/64709_0s.jpg)