Python2与Python3的区别:Queue与queue mysqldb和PyMySQL以及py2 to py3所遇问题

The Queue module has been renamed to queue in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3。python2 在明年将不再维护,所以现在建议慢慢换。python3下的队列模块已经改为了queue,此模块不需要安装,属于python自带的

1、from queue import Queue 如果不想在原来程序基础上修改,使用此方式import进行调整即可
2、PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一个库,Python2中则使用mysqldb。
pip3 install PyMySQL
import pymysql

3、
解决问题
TypeError: type numpy.ndarray doesn’t define round method
解决方法
类型错误:numpy.ndarray 类型数据不能定义__round__ method方法
将round方法改为np.round即可!
4、
TypeError: ‘odict_items’ object does not support indexing 或TypeError: ‘dict_items’
res = model.features._modules.items()[layer_index] py2
修改为 res = list(model.features._modules.items())[layer_index] py3

5、
解决问题:_tkinter.TclError: no display name and no $DISPLAY environment variable
在这里插入图片描述
解决方法:在脚本导入任何库之前,运行:
import matplotlib
# Force matplotlib to not use any Xwindows backend.
matplotlib.use(‘Agg’)

其余的 见一个总结的特别好的博客:
https://blog.youkuaiyun.com/u013385925/article/details/79615599

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值