I'm TA in a Programming course. This week's challenge was to build a basic chess game. Teacher made a game.py library, that would help them. The problem is, when calling the LostGame class, which is defined as follows (and uses Arcade library):
class LostGame(arcade.Window):
def __init__(self):
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.sprites_list = None
self.background = None
arcade.set_background_color(arcade.color.RED)
self.moves = []
self.doing = 0
self.started = 0
self.current_text = "Comienza el juego"
We will have the following error:
Traceback (most recent call last):
File "test.py", line 4, in <module>
juego = game.LostGame()
File "/Users/daniel/Documents/Doctorado/Ayudantías/IIC2115/L02/game.py", line 39, in __init__
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/arcade/application.py", line 53, in __init__
resizable=resizable, config=config)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyglet/window/__init__.py", line 643, in __init__
self._create()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/arcade/monkey_patch_pyglet.py", line 81, in _create
self.context.attach(self.canvas)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyglet/gl/cocoa.py", line 289, in attach
self._nscontext.setView_(canvas.nsview)
AttributeError: 'NoneType' object has no attribute 'setView_'
We noticed that this error would happen in all computers that have Anaconda installed. We thing it may be because it Anaconda's python doesn't recognise Arcade library. We have already ran the code on an independent version of Python 3.7, without success.
Thanks in advance for your help!
Related
I am using the pyattck module to retrieve information from mitre att&ck.
Versions:
- pyattck==7.0.0
- pyattck-data==2.5.2
Then, I just created a simple main.py file to test the module.
from pyattck import Attck
def main():
attck = Attck()
for technique in attck.enterprise.techniques:
print(technique.name)
if __name__ == '__main__':
main()
When running the main.py script I get the following exception:
Traceback (most recent call last):
File "/<path>/main.py", line 15, in <module>
main()
File "/<path>/main.py", line 8, in main
for technique in attck.enterprise.techniques:
File "/<path_venv>/lib/python3.10/site-packages/pyattck/attck.py", line 253, in enterprise
from .enterprise import EnterpriseAttck
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 7, in <module>
class EnterpriseAttck(Base):
File "/<path_venv>/lib/python3.10/site-packages/pyattck/enterprise.py", line 42, in EnterpriseAttck
__attck = MitreAttck(**Base.config.get_data("enterprise_attck_json"))
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 55, in __init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 53, in __init__
self.__attrs_init__(**kwargs)
File "<attrs generated init pyattck_data.attack.MitreAttck>", line 14, in __attrs_init__
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 66, in __attrs_post_init__
raise te
File "/<path_venv>/lib/python3.10/site-packages/pyattck_data/attack.py", line 62, in __attrs_post_init__
data = TYPE_MAP.get(item['type'])(**item)
TypeError: 'NoneType' object is not callable
Anyone knows where is the issue? Maybe I have forgotten to import something? It would be helpful to know if this module actually works in another version. This one is the lasted stable one ATTOW.
UPDATE
There is am issue with this project. Mitre added some new features that are not supported by the module and make it unusable.
There is an issue on github related to this.
They have already fixed this issue in future releases. You just need to update your package pyattck-data form the bugged version 2.5.2 to 2.6.1 (or any newer).
If you are using pip, just run this:
pip install --upgrade pyattck-data
If you are using conda (inside your venv):
conda update pyattck-data
I was following up on a tutorial to build a python keylogger and ended up with this problem. I have gone over my codes about 10 times and compared it with other sources but yet still getting the same error. I have seen similar complaints while looking for a solution, and I hypothesize that it might be my computer( Mac OSX 10.12 sierra, MacBook Pro (13-inch, Mid 2010)). I am not a computer expert so I am not too sure.
If it is my system architecture, how do I by-pass it ?
if not, what am I missing in the code or where is my error ?
import pyxhook
log_file = "/Users/VemPC/Desktop/log_file.log"
def onPress(event):
fob = open(log_file, 'a')
fob.write(event.key)
fob.write('\n')
if event.key.ascii == 96 :
fob.close()
new_hook.cancel()
new_hook = pyxhook.HookManager()
new_hook.KeyDown = onPress
new_hook.HookKeyboard()
new_hook.start()
Error:
Traceback (most recent call last):
File "key_logger.py", line 15, in <module>
new_hook = pyxhook.HookManager()
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/pyxhook/pyxhook.py", line 67, in __init__
self.local_dpy = display.Display()
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/protocol/display.py", line 85, in __init__
name, protocol, host, displayno, screenno = connect.get_display(display)
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/support/connect.py", line 73, in get_display
return mod.get_display(display)
File "/Users/VemPC/Desktop/Challenges/venv/lib/python3.7/site-packages/Xlib/support/unix_connect.py", line 61, in get_display
raise error.DisplayNameError(display)
Xlib.error.DisplayNameError: Bad display name ""
pyxhook seems to be a linux specific library. Specifically, it is an implementation of PyHook for linux, using X, the window system library. MacOS provides some support for this, but not all, as MacOS is not built on X. It seems like you won't be able to use this library on your system.
This is my first time working with machine learning libraries, I used to make it all myself, and when I did it worked, but I guess that when everyone tells you not to do the job yourself and let the libraries do it for you, you eventually try, and I tried "gym" of OpenAI on python, my code is very simple(I found it on a youtube video that explains how to use this library since I had no idea what I am getting into)
import gym
env = gym.make("MountainCar-v0")
env.reset()
done = False
while not done:
action = 2
newState, reward, done, _ = env.step(action)
env.render()
env.close()
this code returns me this error:
Traceback (most recent call last):
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 378, in getattr
return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'get_default'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user/PycharmProjects/TestOnGymLibrary/me/RoeeHerzovich/TestOnGymLibrary
/Core.py", line 11, in
env.render()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\core.py", line 235, in render
return self.env.render(mode, **kwargs)
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\mountain_car.py", line 78, in render
from gym.envs.classic_control import rendering
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\gym\envs\classic_control\rendering.py", line 27, in
from pyglet.gl import *
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 239, in
import pyglet.window
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1896, in
gl._create_shadow_window()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\gl__init__.py", line 208, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window\win32__init__.py", line 134, in init
super(Win32Window, self).init(*args, **kwargs)
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 501, in init
display = get_platform().get_default_display()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\window__init__.py", line 1845, in get_default_display
return pyglet.canvas.get_display()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\canvas__init__.py", line 77, in get_display
from pyglet.app import displays
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app__init__.py", line 175, in
event_loop = EventLoop()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\app\base.py", line 119, in init
self.clock = clock.get_default()
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet__init__.py", line 384, in getattr
import(import_name)
File "C:\Users\user\PycharmProjects\TestOnGymLibrary\venv\lib\site-packages\pyglet\clock.py", line 166, in
_default_time_function = time.clock
AttributeError: module 'time' has no attribute 'clock'
I tried looking in places for this, but I haven't seen that...
I have gym, matplotlib and pyglet installed, I checked them and I even tried to --upgrade them and it said it is already upgraded, so I don't know what is going on. Can anyone please help me with it?
I appreciate all of your comments :)
The true error comes from the bottom of the trace you posted:
_default_time_function = time.clock AttributeError: module 'time' has no attribute 'clock'
This error has been addressed here.
Options:
Find where time.clock() is being called, and change it to time.perf_counter()
Downgrade to 3.7
Except for the time.perf_counter() there was another thing that needed to be changed. I have written it all in here.
Thanks to everyone who helped me here
Answer:
Class: Clock.py
Row: 166
old: _default_time_function = time.clock
changed to: _default_time_function = time.perf_counter()
Class: Clock.py
Row: 251
old: self.next_ts = self.time()
changed to: self.next_ts = self.time
This script should workm in google colab
!apt install xvfb -y
!pip install pyvirtualdisplay
!pip install piglet
from pyvirtualdisplay import Display
display = Display(visible=0, size=(1400, 900))
display.start()
So I'm trying to get scapy to work on my windows computer. After a lot of work I finally was able to load the library without any errors. However when I call the function sniff(count=1) I get an error. It seems that a variable called "device" is getting the value None. Here is the error :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python34\lib\site-packages\scapy\arch\windows\__init__.py", line 445, in sniff
s = L2socket(type=ETH_P_ALL, *arg, **karg)
File "C:\Python34\lib\site-packages\scapy\arch\pcapdnet.py", line 266, in __init__
self.ins = open_pcap(iface, 1600, self.promisc, 100)
File "C:\Python34\lib\site-packages\scapy\arch\windows\__init__.py", line 223, in <lambda>
pcapdnet.open_pcap = lambda iface,*args,**kargs: _orig_open_pcap(pcap_name(iface),*args,**kargs)
File "C:\Python34\lib\site-packages\scapy\arch\pcapdnet.py", line 251, in <lambda>
open_pcap = lambda *args,**kargs: _PcapWrapper_pypcap(*args,**kargs)
File "C:\Python34\lib\site-packages\scapy\arch\pcapdnet.py", line 215, in __init__
self.iface = create_string_buffer(device.encode('ascii'))
AttributeError: 'NoneType' object has no attribute 'encode'
Thanks In Advance For Any Help :)
After downloading the new development version and tinkering around with the timeouts of some of the powershell commands I fixed it! Guess it was just a bug with the old version. Scapy doesn't have the best Windows support.
I was using PYTTSX yesterday with no issues at all - it was acting exactly as expected and working fine. However, when I tried to run the exact same code not two hours later it threw this error:
Traceback (most recent call last):
File "C:\Python27\FUCK.py", line 2, in <module>
engine = pyttsx.init()
File "C:\Python27\lib\site-packages\pyttsx\__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\engine.py", line 45, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Python27\lib\site-packages\pyttsx\driver.py", line 64, in __init__
self._module = __import__(name, globals(), locals(), [driverName])
File "C:\Python27\lib\site-packages\pyttsx\drivers\sapi5.py", line 19, in <module>
import win32com.client
File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 11, in <module>
import gencache
File "C:\Python27\lib\site-packages\win32com\client\gencache.py", line 662, in <module>
__init__()
File "C:\Python27\lib\site-packages\win32com\client\gencache.py", line 56, in __init__
_LoadDicts()
File "C:\Python27\lib\site-packages\win32com\client\gencache.py", line 109, in _LoadDicts
version = p.load()
EOFError
and it has been throwing this error ever since. The code which was working fine before hasn't been changed at all, and the same code works fine on my Linux partition, this error seems to be windows exclusive. Any idea what it could be?
It is a simple procedure:
Go to python27 folder
Search for dicts.dat
Delete that folder
It will work because I have done it