AttributeError: 'module' object has no attribute 'App'

环境介绍

基本《Python 基础教程(第2版 修订版)》 作者:[挪] Magnus Lie Hetland 司维 曾军崴 谭颖华 译

操作系统:CentOS release 6.9 (Final)

python版本:Python 2.6.6

程序编辑器:VIM - VI IMproved 7.4

wxPython版本:wxPython-2.8.12.0-1.el6.x86_64

程序源码:

#!/usr/bin/env python

import wx

app = wx.App()

win = wx.Frame(None)

win.Show()

app.MainLoop()

报错:

[[email protected] python]# python wx.py

Traceback (most recent call last):

File "wx.py", line 2, in <module>

import wx

File "/root/python/wx.py", line 3, in <module>

app = wx.App()

AttributeError: ‘module‘ object has no attribute ‘App‘

从网上找到答案:

问题解决方法:

1. 命名py脚本时,不要与python预留字,模块名等相同

2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件;在已经生成.pyc文件的情况下,若代码不更新,运行时依旧会走pyc,所以要删除.pyc文件),重新运行代码;或者找一个可以运行代码的环境,拷贝替换当前机器的.pyc文件即可

解决:

把wx.py 改成 editor.py  执行成功弹出一个文本框,如附件截图:

[[email protected] python]# python editor.py

AttributeError: 'module' object has no attribute 'App'

时间: 2024-08-26 17:04:22

AttributeError: 'module' object has no attribute 'App'的相关文章

AttributeError: &#39;module&#39; object has no attribute &#39;dumps&#39;

报错: [[email protected] ~]# ./json.py DATA: [{'a': 'A', 'c': 3.0, 'b': (2, 4)}] Traceback (most recent call last): File "./json.py", line 4, in <module> import json File "/root/json.py", line 8, in <module> data_string = jso

Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attribute 'xxx'".这其实是.pyc文件存在问题. 问题定位: 查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件 问题解决方法: 1. 命名py脚本时,不要与python预留字,模块名等相同 2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件

[Python]attributeError:&#39;module&#39; object has no attribute &#39;dump&#39;

[问题] [代码] 文件名:pickle.py # coding=utf-8 #持久存储 import pickle #b 以二进制的模式打开文件 with open('mydata.pickle','wb') as mysavedata: #用dump保存数据 pickle.dump([1,2,'three'],mysavedata) #b 以二进制的模式打开文件 with open('mydata.pickle','rb') as myreaddata: #使用load恢复数据 list =

Faq_flask : AttributeError: ‘module’ object has no attribute ‘autoescape’

原文地址: http://www.suzf.net/thread-0613-153.html 转载须注明原始出处 前些天从 "spider_net" 上找了一篇文章 , 大致就是利用 highcharts + flask + mysql 构建的一个简单的监控系统 ,经过几番挣扎终于还是给捣持出来了 , 现在总结一下 , 分享给大家 .   o_O 部分报错信息: * Detected change in 'flask_web.py', reloading* Restarting wit

service_identity 模块 AttributeError: &#39;module&#39; object has no attribute &#39;Any&#39;

安装scrapy之后,开始第一步创建scrapy的工程,之后提示一个userwarning:提示我service_identity没有安装,我通过pip install service_identity安装之后,重新创建一个scrapy的爬虫工程有提示以下的错误. Traceback (most recent call last): File "/usr/local/bin/scrapy", line 4, in execute() File "/usr/local/lib/

os.uname() AttributeError: &#39;module&#39; object has no attribute &#39;uname&#39;

os.uname() Returns information identifying the current operating system. The return value is an object with five attributes: sysname - operating system name nodename - name of machine on network (implementation-defined) release - operating system rel

AttributeError: &#39;module&#39; object has no attribute &#39;Thread&#39;

$ python thread.py starting at: 2015-08-05 00:24:24Traceback (most recent call last):  File "thread.py", line 28, in <module>    main()  File "thread.py", line 16, in main    th = threading.Thread(target= test,args= (i,2))Attribu

AttributeError: &#39;module&#39; object has no attribute &#39;handlers&#39;--Python子模块导入问题

想使用python的logging模块记录日志,并使用RotatingFileHandler来处理日志以便于在日志文件超过指定的大小后会重新生成新的日志文件. 基本代码如下: import logging logger = logging.getLogger('mylogger') logger.setLevel(logging.INFO) fh=logging.handlers.RotatingFileHandler('/tmp/test.log', mode = 'a', maxBytes=

python 错误AttributeError: &#39;module&#39; object has no attribute &#39;AF_INET&#39;

写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即可. 据我的理解,应该是我们自己命名重写了Python的socket函数. 附上我的小代码 import socket mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) mysock.connect(('data.pr4e.org'