#๐Ÿ”’ how do i run this

82 messages ยท Page 1 of 1 (latest)

sullen fox
#

/usr/local/bin/python3 /Users/otto/Developer/python/AFK.py
otto@Ottos-MacBook-Air python % /usr/local/bin/python3 /Users/otto/Developer/python/AFK.py
Exception in thread Thread-1 (listen):
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/init.py", line 294, in listen
_os_keyboard.listen(self.direct_callback)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/keyboard/_darwinkeyboard.py", line 430, in listen
raise OSError("Error 13 - Must be run as administrator")
OSError: Error 13 - Must be run as administrator

if i use sudo then i get a segmentation error

hardy schoonerBOT
#

@sullen fox

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

river jasper
#

what error do you get when you sudo

exotic hornet
#

What are you trying to run?

#

Can you Share the code @sullen fox ?

#

I'd be wary about running anything with elevated privileges.

#

Especially if it's something you've downloaded from the Internet.

sullen fox
#
import keyboard
import time

timeGone = 0
keyPresses = []
start = False

# Function to handle key presses
def handle_key_press(key):
    global keyPresses
    if key == "w":
        keyPresses.append("w")
    elif key == "a":
        keyPresses.append("a")
    elif key == "s":
        keyPresses.append("s")
    elif key == "d":
        keyPresses.append("d")
    elif key == "e":
        keyPresses.append("e")

# Function to handle key releases
def handle_key_release(key):
    global keyPresses
    if key in keyPresses:
        keyPresses.remove(key)

# Start listening for key presses
keyboard.on_press(handle_key_press)
keyboard.on_release(handle_key_release)

# Wait for 'r' key to start
while not start:
    if keyboard.read_key() == "r":
        start = True

# Main loop
while True:
    time.sleep(1/50)
    timeGone += 1/50
    if not start:
        continue
    elif keyboard.read_key() == "r":
        break

# Stop listening for key events
keyboard.unhook_all()

# Reverse the list of key presses
keyPressesReversed = keyPresses[::-1]

# Map keys to their opposites
key_map = {"w": "s", "a": "d", "s": "w", "d": "a"}

# Simulate key presses using pynput
from pynput.keyboard import Key, Controller

keyboard_controller = Controller()

for key in keyPressesReversed:
    if key in key_map:
        keyboard_controller.press(key_map[key])
    else:
        keyboard_controller.press(key)

# Release all keys
for key in keyPressesReversed:
    if key in key_map:
        keyboard_controller.release(key_map[key])
    else:
        keyboard_controller.release(key)

@exotic hornet

sullen fox
#

@river jasper

river jasper
#

can you send that error please

sullen fox
# river jasper can you send that error please

Traceback (most recent call last):
File "/Users/otto/Developer/python/AFK.py", line 1, in <module>
import keyboard
ModuleNotFoundError: No module named 'keyboard'
otto@Ottos-MacBook-Air python %

#

i tried pip and brew installing it again didn work

river jasper
#

that's not segmentation error

sullen fox
#

it was before

river jasper
#

do you have multiple versions of python installed by any chance?

sullen fox
#

i dont think so

#

i can do like python3 --version right

#

Python 3.12.3

river jasper
#

check which python

sullen fox
#

?

river jasper
#

on the terminal

sullen fox
#

python version 3.12.3 do u mean that

river jasper
#

type which python

sullen fox
#

oh k

#

python not found

that is so wierd i have been using it for like over a year and that never happened

river jasper
#

how do you usually run it

sullen fox
#

terminal or just vscode

#

i just decide tbh that doesnt really matter

river jasper
#

ohh lol type which python3

sullen fox
#

that makes more sense lol ur on windows right

river jasper
#

android

sullen fox
#

it gives me my path

/opt/homebrew/bin/python3

river jasper
#

only this?

sullen fox
#

yh]

river jasper
#

OK because in the error message you run a different python

sullen fox
#

yh i realised ill un it again

river jasper
#

in local/bin

sullen fox
#

Traceback (most recent call last):
File "/Users/otto/Developer/python/AFK.py", line 1, in <module>
import keyboard
ModuleNotFoundError: No module named 'keyboard'

#

that not normal

river jasper
#

when you pip install you only install the package to one specific python version

sullen fox
#

idk i did it ages ago

river jasper
#

type in cmd python 3 followed by import keyboard

sullen fox
#

idk ill do pip3 install keyboard again

river jasper
#

it will still install it to the same python

river jasper
sullen fox
#

python3 import keyboard
/opt/homebrew/Cellar/[email protected]/3.12.3/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/otto/Developer/python/import': [Errno 2] No such file or directory

river jasper
#

no

#

press enter and then type import

sullen fox
#

k

#

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'keyboard'

river jasper
#

so in both versions it's not installed

sullen fox
#

k so what i do

river jasper
#

pip install

sullen fox
#

i did

river jasper
#

which pip

#

there are different pips for different pythons

sullen fox
#

pip pip3 and pipx

river jasper
#

try python3 -m pop install

#

pip

sullen fox
#

otto@Ottos-MacBook-Air python % python3 -m pip install
error: externally-managed-environment

ร— This environment is externally managed
โ•ฐโ”€> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.

If you wish to install a Python library that isn't in Homebrew,
use a virtual environment:

python3 -m venv path/to/venv
source path/to/venv/bin/activate
python3 -m pip install xyz

If you wish to install a Python application that isn't in Homebrew,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. You can install pipx with

brew install pipx

You may restore the old behavior of pip by passing
the '--break-system-packages' flag to pip, or by adding
'break-system-packages = true' to your pip.conf file. The latter
will permanently disable this error.

If you disable this error, we STRONGLY recommend that you additionally
pass the '--user' flag to pip, or set 'user = true' in your pip.conf
file. Failure to do this can result in a broken Homebrew installation.

Read more about this behavior here: <https://peps.python.org/pep-0668/>

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

river jasper
#

oh yeah linux stuff

sullen fox
#

huh

#

im not on linux

river jasper
#

oh Mac os yeah

#

I've never this brew thing so let me do some research

sullen fox
#

k

river jasper
#

an easy fix would be to uninstall macOs ๐Ÿ˜†

sullen fox
#

no thanks

river jasper
#

OK I've done my research

#

I hate macos even more now

#

Basically either create a virtual environment and install your packages in that environment or
do pip install --break-system-packages keyboard

#

I'd go for the first approach

sullen fox
#

k

#

how do i do the first one

river jasper
#
python3 -m venv .venv
source .venv/bin/activate
exotic hornet
river jasper
#

I've never had a mac system

#

apologize

hardy schoonerBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.