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.
Related
I am using OpenGL to render a scene in python. My code works perfectly fine on windows but, for some reason, I'm having issues when importing opengl.gl on MacOS.
The issue arises when calling from OpenGL.GL import ... in both python scripts and the python console.
More specifically here is the exact call in my script:
from OpenGL.GL import glGenBuffers, glBindBuffer, glBufferData, \
glGenVertexArrays, glBindVertexArray, glEnableVertexAttribArray, glVertexAttribPointer, \
glDrawArrays, glUseProgram, glEnable, glDisable, \
GL_ARRAY_BUFFER, GL_STATIC_DRAW, GL_DEPTH_TEST, \
GL_FLOAT, GL_FALSE, \
GL_TRIANGLES, GL_LINES, GL_LINE_STRIP
This results in the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 35, in GL
return ctypesloader.loadLibrary(
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/ctypesloader.py", line 36, in loadLibrary
return _loadLibraryWindows(dllType, name, mode)
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/ctypesloader.py", line 89, in _loadLibraryWindows
return dllType( name, mode )
File "/usr/local/Cellar/python#3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: ('dlopen(OpenGL, 10): image not found', 'OpenGL', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/iyadboustany/Desktop/lensmaster/Lensmaster.py", line 18, in <module>
from MainWindow import MainWindow
File "/Users/iyadboustany/Desktop/lensmaster/MainWindow.py", line 14, in <module>
from Robot import Robot
File "/Users/iyadboustany/Desktop/lensmaster/Robot.py", line 8, in <module>
from Graphics.Scene import DHNode
File "/Users/iyadboustany/Desktop/lensmaster/Graphics/Scene.py", line 13, in <module>
from OpenGL.GL import glGenBuffers, glBindBuffer, glBufferData, \
File "/usr/local/lib/python3.8/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
from OpenGL import error as _error
File "/usr/local/lib/python3.8/site-packages/OpenGL/error.py", line 12, in <module>
from OpenGL import platform, _configflags
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 36, in <module>
_load()
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/__init__.py", line 33, in _load
plugin.install(globals())
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 97, in install
namespace[ name ] = getattr(self,name,None)
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 62, in GetCurrentContext
return self.CGL.CGLGetCurrentContext
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 45, in CGL
def CGL(self): return self.GL
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
value = self.fget( obj )
File "/usr/local/lib/python3.8/site-packages/OpenGL/platform/darwin.py", line 41, in GL
raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)
Notes:
Running glxgears works just fine.
I'm running macOS Big Sur beta (20A5343i)
I'm using python 3.8.5
I installed opengl using pip: pip3 install PyOpenGL PyOpenGL_accelerate
This error is because Big Sur no longer has the OpenGL library nor other system libraries in standard locations in the file system and instead uses a cache. PyOpenGL uses ctypes to try to locate the OpenGL library and it fails to find it. Fixing ctypes in Python so that it will find the library is the subject of this pull request
https://github.com/python/cpython/pull/21241
So a future version of Python should resolve the problem.
To fix it now you can edit PyOpenGL file OpenGL/platform/ctypesloader.py changing line
fullName = util.find_library( name )
to
fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'
Since I hate the idea of patching a Python package (plus it is really hard to manage that with use of Conda to install said package), I offer this kludge as a workaround for until Python gets its Big Sur (aka Big Nuisance) update:
try:
import OpenGL as ogl
try:
import OpenGL.GL # this fails in <=2020 versions of Python on OS X 11.x
except ImportError:
print('Drat, patching for Big Sur')
from ctypes import util
orig_util_find_library = util.find_library
def new_util_find_library( name ):
res = orig_util_find_library( name )
if res: return res
return '/System/Library/Frameworks/'+name+'.framework/'+name
util.find_library = new_util_find_library
except ImportError:
pass
It's better to change this to
fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)
otherwise GLUT won't work. At least, this let me run the Cozmo SDK's 3d stuff again.
FYI, in my case it was:
fullName = '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/OpenGL'
None of these are really very suitable answers - there were several issues with both MacOS and pyOpenGL.
Fortunately, however - everything seems to be working at last if we upgrade to Python3.10 (or above)
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!
The release notes for libarchive state that because of an older version of libarchive being included within MacOS they recommend changing LD_LIBRARY_PATH to point towards the location of the recent copy of libarchive.
I've used this code to try and achieve that but I get an error message when I run the script.
import os
print os.environ.get('LD_LIBRARY_PATH') #Check what the current path is
os.environ['LD_LIBRARY_PATH'] = '/Library/Python/2.7/site-packages/'
print os.environ.get('LD_LIBRARY_PATH') #Check the variable has been set
import libarchive.public
Error:
None
/Library/Python/2.7/site-packages/
Traceback (most recent call last):
File "scratch.py", line 8, in <module>
import libarchive.public
File "/Library/Python/2.7/site-packages/libarchive/public.py", line 1, in <module>
from libarchive.adapters.archive_read import \
File "/Library/Python/2.7/site-packages/libarchive/adapters/archive_read.py", line 7, in <module>
import libarchive.calls.archive_read
File "/Library/Python/2.7/site-packages/libarchive/calls/archive_read.py", line 17, in <module>
c_archive_read_support_filter_all = libarchive.archive_read_support_filter_all
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(0x7fb08b741000, archive_read_support_filter_all): symbol not found
I cant find a great answer to this anywhere out there.
It is not clear from the tool documentation, but based on a thread: https://github.com/dsoprea/PyEasyArchive/issues/16 I set another environment variable to the place where the underlying c library could be found. In my case, it was put there by homebrew on my mac.
os.environ['LA_LIBRARY_FILEPATH']='/usr/local/opt/libarchive/lib/libarchive.dylib'
import libarchive.public
worked for me.
I'm using Python Tools for Visual Studio with py.test. I'm able to use pytest fine if I run the script without debugging, but when I run with debugging, the script crashes. Below is my code and the output that I get in the console window. I've searched for Google for answers but I've come up with nothing that solves this issue; it seems like no one has had this exact problem before. I'm running Visual Studio 2013, with PTVS 2.1 VS 2013.
#Code
import pytest
if __name__ == "__main__":
pytest.main("--resultlog=resultlog.txt")
#Output
! C:\Python34\lib\site-packages\colorama\ansitowin32.py
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\_pytest\main.py", line 80, in wrap_session
config.do_configure()
File "C:\Python34\lib\site-packages\_pytest\config.py", line 618, in do_configure
self.hook.pytest_configure(config=self)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 521, in __call__
return self._docall(self.methods, kwargs)
File "C:\Python34\lib\site-packages\_pytest\core.py", line 528, in _docall
firstresult=self.firstresult).execute()
File "C:\Python34\lib\site-packages\_pytest\core.py", line 394, in execute
res = method(*args)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 41, in pytest_configure
reporter = TerminalReporter(config, sys.stdout)
File "C:\Python34\lib\site-packages\_pytest\terminal.py", line 101, in __init__
self._tw = self.writer = py.io.TerminalWriter(file)
File "C:\Python34\lib\site-packages\py\_io\terminalwriter.py", line 130, in __init__
file = colorama.AnsiToWin32(file).stream
File "C:\Python34\lib\site-packages\colorama\ansitowin32.py", line 68, in __init__
convert = on_windows and not wrapped.closed and not on_emulated_windows and is_a_tty(wrapped)
AttributeError: '_DebuggerOutput' object has no attribute 'closed'
Q: How can this error be resolved so that I can debug from inside Visual Studio?
It's a bug in PTVS that has been fixed for the upcoming 2.2 release.
There's no build with the fix yet, but you can just apply it yourself, as it is in a .py file and does not require recompilation. The file that you need is:
C:\Users\...\AppData\Local\Microsoft\VisualStudio\12.0Exp\Extensions\Microsoft\Python Tools for Visual Studio\2.1\visualstudio_py_debugger.py
Find class _DebuggerOutput in it, and add the following at the end of it:
def __getattr__(self, name):
return getattr(self.old_out, name)
I need to display notifications in MacOS. Simply running the script with python can display notification. But whenever I pack the script using Pyinstaller, I get the following error. Seems like Pyinstaller is having some problem with working on Mac notifications. I also tried using pync (Python binding for terminal notifier). In all cases, simply running the app python notify.py works, but freezing the script using Pyinstaller doesn't seem to work.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/Foundation/__init__.py", line 10, in <module>
from CoreFoundation import *
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/CoreFoundation", line 19, in <module>
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/objc._bridgesupport", line 121, in initFrameworkWrapper
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 939, in resource_exists
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1392, in has_resource
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1447, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
logout
I am using the following Python script to display notification
import Foundation
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
I had similar problems and this is how I made it work. You need not use Foundation as its making the problem with Pyinstaller (Not sure why this is causing an issue) and is not used elsewhere in your code.
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
At this point, it may throw some error or the notification just don't show up. Just add CFBundleIdentifier key into the info.plist file generated by pyinstaller.