Python3:ImportError: No module named 'compiler.ast'
from compiler.ast import flatten
上面这条语句好像在python3 以后就废除了,如果使用的话就会报错。
Traceback (most recent call last):
File "eval_ssd_network.py", line 31, in <module>
from compiler.ast import flatten
ImportError: No module named 'compiler'
或者
Traceback (most recent call last):
File "eval_ssd_network.py", line 31, in <module>
from compiler.ast import flatten
ImportError: No module named 'compiler.ast'
因此,查资料显示,需要自己写一个函数:
import collections
def flatten(x):
result = []
for el in x:
if isinstance(x, collections.Iterable) and not isinstance(el, str):
result.extend(flatten(el))
else:
result.append(el)
return result
print(flatten(["junk",["nested stuff"],[],[[]]]))
参考文献
[1].Python 3 replacement for deprecated compiler.ast flatten function.https://stackoverflow.com/questions/16176742/python-3-replacement-for-deprecated-compiler-ast-flatten-function
[2].Python 3 replacement for deprecated compiler.ast flatten function. https://reformatcode.com/code/python/python-3-replacement-for-deprecated-compilerast-flatten-function
---------------------
作者:农民小飞侠
来源:CSDN
原文:https://blog.csdn.net/w5688414/article/details/78489277
版权声明:本文为博主原创文章,转载请附上博文链接!
Python3:ImportError: No module named 'compiler.ast'的更多相关文章
- ImportError: No module named 'commands'
/*********************************************************************** * ImportError: No module na ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决
python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'的解决方法: 1.原因是官网的是python2语法写的,看官手动把官 ...
- 关于python3.X 报"import urllib.request ImportError: No module named request"错误,解决办法
#encoding:UTF-8 import urllib.request url = "http://www.baidu.com" data = urllib.request.u ...
- python3 与 Django 连接数据库报错:ImportError: No module named 'MySQLdb'
在 python2 中,使用 pip install mysql-python 进行安装连接MySQL的库,使用时 import MySQLdb 进行使用 在 python3 中,改变了连接库,改为了 ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'如何解决【转载】
原文转自:http://bbs.chinaunix.net/thread-4154743-1-1.html python3中用HTMLTestRunner.py报ImportError: No mod ...
- python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'的解决方法:
全文转载至:http://www.cnblogs.com/testyao/p/5658200.html python3中用HTMLTestRunner.py报ImportError: No modul ...
- win7下python3.4 ImportError: No module named 'MySQLdb'错误解决方法
首先,安装PyMySQL C:\Users\fnngj>python -m pip install PyMySQL 执行以下命令会报错: ImportError: No module named ...
- ubuntu下使用python3的有些库时,解决"raise ImportError(str(msg) + ', please install the python3-tk package') ImportError: No module named '_tkinter', please install the python3-tk package"的错误
问题: 在Ubuntu下使用matplotlib这个库时,运行时出现如下错误: raise ImportError(str(msg) + ', please install the python3-t ...
- ImportError: No module named MySQLdb
ImportError: No module named MySQLdb 该错误是源于我们没有安装Python连接MySQL所需的MySQLdb库而引起. python3.5下的解决方法ubuntu系 ...
随机推荐
- 【产品经理】产品经理不懂API接口是什么,怎么和程序员做朋友?
接口不是技术经理来写吗?没接过它,一脸不清楚地节奏 开放即共享,是互联网的一个重要属性和精神.它是一种服务模式,一个特殊的产品,目前较大规模的互联网企业都有自己的开放平台. 如果把自己局限为一个功能产 ...
- 词袋和 TF-IDF 模型
做文本分类等问题的时,需要从大量语料中提取特征,并将这些文本特征变换为数值特征.常用的有词袋模型和TF-IDF 模型 1.词袋模型 词袋模型是最原始的一类特征集,忽略掉了文本的语法和语序,用一组无序的 ...
- arcgis 点线面操作
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Android基础&进阶
基础总结篇之一:Activity生命周期 基础总结篇之二:Activity的四种launchMode 基础总结篇之三:Activity的task相关 基础总结篇之四:Service完全解析 基础总结篇 ...
- WCF ChannelFactory
public static class WcfExtensions{ public static void Using<T>(this T client, Action<T&g ...
- ajax嵌套陷阱
ajax嵌套陷阱 $('.ajaxupd').click(function () { $('.shadow1').show(); $('.update').show(); var tds=$(this ...
- python 使用自定义的类方法
- 安装vagrant&virtualBox
https://blog.csdn.net/dream_188810/article/details/78218073 VirtualBox是一款开源免费的虚拟机软件(之前一直使用vm,vm功能较多, ...
- hdu4313 贪心+并查集
题意简单思路也还可以.开始从小到大排序非常烦.后来从大到小就很简单了: 从大到小解决了删除的边最小. #include<stdio.h> #include<string.h> ...