我成功安装了一个模块但是为何用 IDLE 和 sublime text2 就提示出错?

2015-04-16 18:55:12 +08:00
 napretep
>>> import pyglet
>>> pyglet.window.Window(800,600)
Win32Window(width=800, height=600)

这个是用windows powershell运行的,没有问题


Traceback (most recent call last):
File "C:\down\pyglet.py", line 1, in <module>
import pyglet
File "C:\down\pyglet.py", line 2, in <module>
game_window = pyglet.window.Window(800,600)
AttributeError: 'module' object has no attribute 'window'

这个是st2运行的,说没有找到window属性。
IDLE上的提示也一样。

请问是哪里出了问题?
3909 次点击
所在节点    Python
7 条回复
xylophone21
2015-04-16 19:01:38 +08:00
看看你的环境是不是装了多个python,然后运行的不是同一个。
napretep
2015-04-16 19:13:58 +08:00
@xylophone21

你是说在系统属性-高级-环境变量里看吗?

用户变量为
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Users\napretep\.babun;c:\python27

系统变量为
C:\Python27\;C:\Python27\Scripts;C:\Program Files\Intel\TXE Components\TCS\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\TXE Components\DAL\;C:\Program Files\Intel\TXE Components\IPT\;C:\Program Files\Leawo\Youtube Download;

我不知道自己装了几个,因为过去曾反复装过python3和2,现在按照记忆来看的话,应该是一个。
xylophone21
2015-04-16 19:36:05 +08:00
cmd及powershell里分别运行python -v

另外参考http://docs.sublimetext.tw/others/
napretep
2015-04-16 20:12:17 +08:00
@xylophone21

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pyglet
>>> pyglet.window.Window(800,600)

Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
pyglet.window.Window(800,600)
File "C:\Python27\lib\site-packages\pyglet\window\win32\__init__.py", line 131, in __init__
super(Win32Window, self).__init__(*args, **kwargs)
File "C:\Python27\lib\site-packages\pyglet\window\__init__.py", line 505, in __init__
config = screen.get_best_config(template_config)
File "C:\Python27\lib\site-packages\pyglet\canvas\base.py", line 161, in get_best_config
configs = self.get_matching_configs(template)
File "C:\Python27\lib\site-packages\pyglet\canvas\win32.py", line 33, in get_matching_configs
configs = template.match(canvas)
File "C:\Python27\lib\site-packages\pyglet\gl\win32.py", line 25, in match
return self._get_arb_pixel_format_matching_configs(canvas)
File "C:\Python27\lib\site-packages\pyglet\gl\win32.py", line 98, in _get_arb_pixel_format_matching_configs
nformats, pformats, nformats)
File "C:\Python27\lib\site-packages\pyglet\gl\lib_wgl.py", line 95, in __call__
result = self.func(*args, **kwargs)
File "C:\Python27\lib\site-packages\pyglet\gl\lib.py", line 62, in MissingFunction
raise MissingFunctionException(name, requires, suggestions)
MissingFunctionException: wglChoosePixelFormatARB is not exported by the available OpenGL driver. ARB_pixel_format is required for this functionality.
>>>
xylophone21
2015-04-16 20:20:27 +08:00
在powershell里运行

Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pyglet
>>> pyglet.window1.Window(800,600)

注意这个1,让它报类似的错误,你就可以看到powershell里用的是哪个路径下的pyglet了
laike9m
2015-04-16 20:38:03 +08:00
试试这个呢,用 wheel 来装
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyglet
napretep
2015-04-16 20:46:31 +08:00
@xylophone21

应该是同一个python吧。
cmd 和powershell输入 python -v 得到的目录都是在c:\python27里的

好在我用刚下了的pycharm没什么问题。
那这个问题就先放着还是最好解决掉啊?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/184189

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX