Ask Different (Apple)
Q&A for power users of Apple hardware and software
Latest Questions
1
votes
0
answers
66
views
Why can't I uninstall Python 3.13?
I want to uninstall Python 3.13 and only keep 3.9. I tried using brew but just get this error: ```sh brew uninstall python@3.13 Error: No such keg: /opt/homebrew/Cellar/python@3.13 ``` I don't have admin permissions to manually delete the files in `/Library`: ```sh which python3.13 /Library/Framewor...
I want to uninstall Python 3.13 and only keep 3.9.
I tried using brew but just get this error:
brew uninstall python@3.13
Error: No such keg: /opt/homebrew/Cellar/python@3.13
I don't have admin permissions to manually delete the files in /Library
:
which python3.13
/Library/Frameworks/Python.framework/Versions/3.13/bin/python3.13
How can I actually remove this version?
Running the following command shows python is located in /Library but I can't remove it due to not having sudo access.
type python3
python3 is /Library/Frameworks/Python.framework/Versions/3.13/bin/python3
zio
(11 rep)
Jul 16, 2025, 08:04 PM
• Last activity: Jul 22, 2025, 01:07 PM
0
votes
0
answers
33
views
Gatekeeper Disk Write Workaround?
I am developing a Python software and I'd like to generate a logs folder where .log files can populate for user-debug. When I run the file through the main init. and the .app created by PyInstaller, the logs folder generates just fine. But when I test the app distribution (creating a .dmg), the .app...
I am developing a Python software and I'd like to generate a logs folder where .log files can populate for user-debug. When I run the file through the main init. and the .app created by PyInstaller, the logs folder generates just fine. But when I test the app distribution (creating a .dmg), the .app gets flagged by Gatekeeper. I can open it through Settings>Privacy & Security, but my logs file won't generate (due to com.apple.quarantine attribute).
Anyone have a recommended workaround to give my software writing ability? I'd prefer not to pay the developer subscription...Thanks!
harryt
(1 rep)
Jul 1, 2025, 06:23 PM
105
votes
6
answers
292362
views
How to install specific version of python on OS X
I need to install python3.4 on my OS X. Tried to do it with `brew install python3` and now I have python 3.5.1. But I need py3.4. How can I install python3.4 on my Mac?
I need to install python3.4 on my OS X.
Tried to do it with
brew install python3
and now I have python 3.5.1. But I need py3.4.
How can I install python3.4 on my Mac?
Paul
(875 rep)
May 6, 2016, 06:58 PM
• Last activity: Jun 20, 2025, 04:12 AM
1
votes
0
answers
322
views
Learning Python, can't install scikit-learn
On my Windows machine, I ran `pip3 install scikit-learn` and it installed without any problems, however, on my Mac, I've tried a lot of things: ```atom@macbook-pro: ~ $ brew list [17:21:35] ==> Formulae ca-certificates glib libidn2 libunistring little-cms2 ncurses pipx tree-sitter zstd cairo gmp lib...
On my Windows machine, I ran
pip3 install scikit-learn
and it installed without any problems, however, on my Mac, I've tried a lot of things:
@macbook-pro: ~
$ brew list [17:21:35]
==> Formulae
ca-certificates glib libidn2 libunistring little-cms2 ncurses pipx tree-sitter zstd
cairo gmp libimagequant libuv lua neovim pixman unibilium
fontconfig graphite2 liblinear libvterm luajit nmap python@3.12 utf8proc
freetype harfbuzz libmpc libx11 luv numpy readline watch
fribidi htop libpng libxau lz4 openblas scikit-image webp
gcc icu4c libraqm libxcb lzo openjpeg scipy wget
gettext isl libssh2 libxdmcp mpdecimal openssl@3 sqlite xorgproto
giflib jpeg-turbo libtermkey libxext mpfr pcre2 tcl-tk xsimd
git libevent libtiff libxrender msgpack pillow tmux xz
==> Casks
android-file-transfer firefox iina microsoft-teams transmission-remote-gui wireshark
dozer freecad inkscape shadowsocksx-ng-r visual-studio-code zoom
dropbox google-chrome jellyfin-media-player steam vlc
eddie google-earth-pro microsoft-auto-update teamviewer warp
atom@macbook-pro: ~
$ brew install scikit-learn [17:21:38]
Warning: No available formula with the name "scikit-learn". Did you mean scikit-image?
==> Searching for similarly named formulae and casks...
==> Formulae
scikit-image ✔
To install scikit-image ✔, run:
brew install scikit-image ✔
FAIL
atom@macbook-pro: ~
$ pip3 install scikit-learn [17:21:44]
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:
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.
FAIL
atom@macbook-pro: ~
$ pipx install scikit-learn [17:21:52]
Note: Dependent package 'numpy' contains 1 apps
- f2py
No apps associated with package scikit-learn. Try again with '--include-deps' to include apps of dependent packages, which are listed above. If
you are attempting to install a library, pipx should not be used. Consider using pip or a similar tool instead.
FAIL
I've also tried the commands on the official website, https://scikit-learn.org/stable/install.html , which produce similar errors as my system doesn't recognize pip
and the -U
flag doesn't make a difference.
What am I doing wrong?
ohshitgorillas
(31 rep)
May 4, 2024, 12:26 AM
• Last activity: Jun 10, 2025, 12:26 AM
3
votes
1
answers
1443
views
Yet another issue with a homebrew update => python upgrade => "No module named 'praw'" (missing site-packages)
I ran through a few upgrades of homebrew, in the past, and all python scripts I used to use were running fine, post python updates, meaning the upgrades got all necessary site-packages properly accounted for. Today my luck ended using the same mechanism: `brew update && brew upgrade && brew cleanup...
I ran through a few upgrades of homebrew, in the past, and all python scripts I used to use were running fine, post python updates, meaning the upgrades got all necessary site-packages properly accounted for.
Today my luck ended using the same mechanism:
brew update && brew upgrade && brew cleanup --prune=all
), and I see my new python version at 3.12.2 having replaced my previous 3.11, but missing tons of stuff in /usr/local/lib/python3.12/site-packages
(as compared to 3.11). Some of them are the praw ones, thus the obvious "No module named 'praw'"
when trying to run a python script dependent on it.
I do recall having had a similar issue, a while ago, which I thought I fixed with some simple pip install --upgrade praw
or python -m pip install --upgrade praw
, but these are now coming back with the "error: externally-managed-environment"
.
Any ideas how I could fix this?
Papi Antoniadis
(31 rep)
Feb 27, 2024, 12:56 PM
• Last activity: Jun 10, 2025, 12:25 AM
1
votes
1
answers
58
views
Can't get a Python package installed
There are twelve executables named `python` on my intel macbook pro.  None of them are in my path, but "python3" in my path points to version 3.13.4 installed by homebrew. When I try `python3 -m pip install pinyin` I get two screens of diagnostics, starting with × This environment is exter...
There are twelve executables named
python
on my intel macbook pro. None of them are in my path, but "python3" in my path points to version 3.13.4 installed by homebrew.
When I try python3 -m pip install pinyin
I get two screens of diagnostics, starting with
× 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.
but brew install pip
says there is no formula for pip.
I need to run a python script that starts with
import sys
import re
import pinyin
but it errs with a complaint about pinyin on line 3
I also tried doing it with the Apple-installed P{ython, but no success there either.
Advice?
Update: After studying those two screens of diagnostics, it seemed to advise me to install and use pipx
instead. So I did that, and then pipx install pinyin
said pinyin is already installed! So I tried running the intended command again and got the same complaint:
WGroleau@MacBookPro pinyin % python3 convert_pinyin.py test.pinyin.php test.pinyin.php
Traceback (most recent call last):
File "/Users/WGroleau/ChiCal/pinyin/convert_pinyin.py", line 3, in
import pinyin
ModuleNotFoundError: No module named 'pinyin'
WGroleau@MacBookPro pinyin %
WGroleau
(5370 rep)
Jun 9, 2025, 12:41 AM
• Last activity: Jun 9, 2025, 06:47 AM
1
votes
2
answers
289
views
Can I stop macOS asking for screen recording permission while using mss.mss() in a python script?
I am trying to use mss to capture a portion of my screen using the following code: ``` import mss import cv2 import numpy as np monitor_region = { "top": 810, "left": 1070, "width": 660, "height": 300 } def get_frame(display_frame=False): with mss.mss() as sct: # Capture a single frame img = sct.gra...
I am trying to use mss to capture a portion of my screen using the following code:
Unfortunately, this isn't just a one-time thing, it happens for every screenshot request I make. This is not feasible when I am making multiple requests. Hence, I am looking for a way to disable this security check.
I have allowed terminal full access to the disk, and to screen and audio recording in my system settings. This still didn't work so I am currently using pyautogui to automatically allow this, but this is still slow (takes ~0.2 seconds to get rid of) for my application.
I am expecting a solution to guide me to disable the above security check.
Is it possible to eliminate further requests?
edit: output of the given command (
import mss
import cv2
import numpy as np
monitor_region = {
"top": 810,
"left": 1070,
"width": 660,
"height": 300
}
def get_frame(display_frame=False):
with mss.mss() as sct:
# Capture a single frame
img = sct.grab(monitor_region)
# Convert to NumPy array and display
frame = np.array(img)
# print(frame)
# print("frame dim = ", frame.shape)
if display_frame:
cv2.imshow("Captured Region", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()
When running, my mac keeps prompting for permission and
I have to click allow for every request.

read ~/Library/Group\ Containers/group.com.apple.replayd/ScreenCaptureApprovals
):
{
"/Applications/Shottr.app/Contents/MacOS/Shottr" = {
kScreenCaptureApprovalLastAlerted = "2125-06-05 15:25:33 +0000";
kScreenCaptureApprovalLastUsed = "2125-06-05 15:25:33 +0000";
};
"com.apple.Terminal" = {
kScreenCaptureApprovalLastAlerted = "2125-06-05 15:25:33 +0000";
kScreenCaptureApprovalLastUsed = "2125-06-05 15:25:33 +0000";
};
}
tiny_sleasel
(23 rep)
Jun 2, 2025, 11:34 PM
• Last activity: Jun 6, 2025, 03:32 PM
0
votes
2
answers
183
views
New to MacOS, setting up my python virtual environment
I'm fairly new to MacOS, when i try to directly do ``` pip install ``` the terminal whether in VScode or the normal mac terminal gives the output as ``` zsh: command not found: pip ``` But if i execute the same command after activating my virtual environment, it works. can anyone help in explaining...
I'm fairly new to MacOS, when i try to directly do
pip install
the terminal whether in VScode or the normal mac terminal gives the output as
zsh: command not found: pip
But if i execute the same command after activating my virtual environment, it works.
can anyone help in explaining this.
Ayush Kumar
(1 rep)
Apr 29, 2025, 08:10 PM
• Last activity: Jun 1, 2025, 10:03 AM
2
votes
2
answers
62
views
mDNS discovery work on shell, but not in LaunchAgent
I've built a simple Python script that tries to discover my Sonos speakers via mDNS/UPnP/Bonjour and set some music sources to them. This is done using the [soco](https://soco.readthedocs.io/en/latest/getting_started.html) lib. The script works well when started on the shell. Starting it from a Laun...
I've built a simple Python script that tries to discover my Sonos speakers via mDNS/UPnP/Bonjour and set some music sources to them. This is done using the [soco](https://soco.readthedocs.io/en/latest/getting_started.html) lib.
The script works well when started on the shell.
Starting it from a LaunchAgent (same machine, same user), it can't find the speakers.
import soco
from soco import discovery
found_speakers = discovery.discover(timeout=30)
Label
sonos
ProgramArguments
/usr/local/bin/poetry
run
sonos-sanitizer
RunAtLoad
StandardErrorPath
/var/log/sonos/sonos.stderr
StandardOutPath
/var/log/sonos/sonos.stdout
StartCalendarInterval
Hour
5
Minute
35
WorkingDirectory
/Users/xxx/Code/sonos_sanitzer
I'm a bit puzzled as of why it doesn't seem to get network access when run via LaunchAgent. I've even extended the discovery timeout to 30 seconds.
System is macOS 15 Sequoia.
Caveat: The Mac is connected to multiple networks using VLANs.
MerlinDE
(151 rep)
May 17, 2025, 03:08 PM
• Last activity: May 24, 2025, 08:11 AM
3
votes
1
answers
252
views
which certificate/identifiers/profilers should be used for python script to be distributed as a pyinstaller build/bundle outside the app store?
My program works as follows In a while loop, it checks for the active window change - AppKit library used from AppKit import NSWorkspace active_window = (NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']) if the active window changes to from some other window to google chrome, I...
My program works as follows
In a while loop, it checks for the active window change - AppKit library used
from AppKit import NSWorkspace
active_window = (NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName'])
if the active window changes to from some other window to google chrome, I need get the url from the chrome's current tab using apple script as :
url="""tell application "System Events"
tell application "Google Chrome" to get the URL of the active tab of window 1 as string
end tell"""
This script is running fine, I can able to get the current window name and also url
I need to know which kind of identifier, provisioning profile, certificate should be used for the same
Im confused of choosing the certificate
I don't have any idea if I need to have a provisioning profile
Im not going to place this app in mac app store, I just wanted to use this app to support another electron application
Any help is appreciated
chitharthan
(315 rep)
Aug 4, 2020, 08:52 AM
• Last activity: May 11, 2025, 07:09 AM
2
votes
2
answers
1762
views
What causes excessive CPU use by taskgated, notifyd, and launchd processes?
I've looked around *a lot* to try to find the answer to this but have thus far been unsuccessful. I am programming in Python, and I have code that takes a long time to run (hours to months depending on the application) and I am trying to optimize it. On larger thread systems (once I get above ≈8 thr...
I've looked around *a lot* to try to find the answer to this but have thus far been unsuccessful. I am programming in Python, and I have code that takes a long time to run (hours to months depending on the application) and I am trying to optimize it. On larger thread systems (once I get above ≈8 threads, but especially >18 threads), I run into a situation where the system is using up a large amount of my CPU instead of the actual code I want to run. On a 12-thread machine as I type this, the system is using ≈25–30% of my total CPU. If I try to run it on a 36-thread machine, the system takes >70% of the CPU which is simply unworkable (though running two instances of the code, limiting each to 18 threads, cuts this overhead back, oddly enough).
The Activity Monitor indicates that
is using at least 10%, while
,
, and
are also using several percent, each (along with
at 1% so I should turn off Spotlight, and sometimes
spikes to >40%, but that's more rare ... note that that process is another launch system daemon).
My older hypothesis was that it was a disk I/O issue, since the code was writing and reading many small files to try to keep track of certain things and recover if I needed to stop it.
My now-working hypothesis, based on what I could find online about the interactions between
and
, is that this particular chunk of code is spawning a large number of processes and macOS's launching and security daemons are taking large amounts of CPU to make sure those processes are safe. These are things like calling "mv" and "rm" from the command line (os.system(...) in my Python code), and spawning other code that take a second or two to run (such as in a different conda environment when two have conflicting installs of necessary components). I count at least 40 potential spots where this chunk of code is possibly spawning child processes, and I thread it so that it's doing that concurrently however many threads there are (so, on a 12-thread machine, 12x40 over the course of ~10 seconds). It doesn't seem to me like this should be making my system take up so much CPU, but that's my best guess at the moment.
Possibly related, the
is constantly spitting out to log files, "MacOS error: -67062", which again I've searched for and found no luck with diagnosing the issue. And,
is spawning a lot of "\\" messages in the Console, but its CPU% is around 0.3% so I'm less concerned about that.
My apologies for rambling a bit here, but I'm trying to provide the information I have, and hopefully someone here has an idea. If I can get rid of this 25% or larger issue, that can save months of time.
For what it's worth, I'm running macOS 10.14.5 and ..4 on two desktops, and 10.15.5 on a laptop. Same issue for all. Running in Linux on a nearly identical 36-thread system build does not have the overhead issue (but I really don't want to switch to Linux) which is another reason why I don't think it's a disk I/O problem.
Stuart Robbins
(129 rep)
Aug 12, 2020, 05:42 AM
• Last activity: Apr 23, 2025, 06:05 AM
1
votes
1
answers
505
views
Python installation broken after Homebrew auto updated
My `python` installation was messed up after I ran the command `brew install curl` causing Homebrew to auto update. Since then, I discovered that `matplotlib` was not installed (it was before the update), which I had to install with `brew` and not `pip`, and whenever I import the newly installed `ma...
My
python
installation was messed up after I ran the command brew install curl
causing Homebrew to auto update.
Since then, I discovered that matplotlib
was not installed (it was before the update), which I had to install with brew
and not pip
, and whenever I import the newly installed matlplotlib.pyplot
, there is an error regarding not finding PIL
. Installing Pillow
does not have any effect on this error.
Is there a way to reverse that to when everything worked well on my Mac? I am running macOS Sonoma 14.5.
Any help is welcome. Thanks!
============= ERROR on importing matplotlib =============================
himilcon [Documents] % python3
Python 3.12.4 (main, Jun 6 2024, 18:26:44) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "", line 1, in
File "/opt/homebrew/Cellar/python-matplotlib/3.9.1/libexec/lib/python3.12/site-packages/matplotlib/__init__.py", line 159, in
from . import _api, _version, cbook, _docstring, rcsetup
File "/opt/homebrew/Cellar/python-matplotlib/3.9.1/libexec/lib/python3.12/site-packages/matplotlib/rcsetup.py", line 28, in
from matplotlib.colors import Colormap, is_color_like
File "/opt/homebrew/Cellar/python-matplotlib/3.9.1/libexec/lib/python3.12/site-packages/matplotlib/colors.py", line 52, in
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
>>> quit()
>
>
=========== auto update initial lines ===================================
himilcon [depends] % brew install curl
==> Auto-updating Homebrew...
Adjust how often this is run with HOMEBREW_AUTO_UPDATE_SECS or disable with
HOMEBREW_NO_AUTO_UPDATE. Hide these hints with HOMEBREW_NO_ENV_HINTS (see man brew
).
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> New Formulae
libgit2@1.7 tdb
==> New Casks
avbeam duplicateaudiofinder twingate
Error: Unexpected method 'appcast' called on Cask adoptopenjdk8.
Follow the instructions here:
https://github.com/Homebrew/homebrew-cask#reporting-bugs
You have 125 outdated formulae and 1 outdated cask installed.
Error: Unexpected method 'appcast' called on Cask adoptopenjdk8.
Follow the instructions here:
https://github.com/Homebrew/homebrew-cask#reporting-bugs
Error: Unexpected method 'appcast' called on Cask adoptopenjdk8.
Follow the instructions here:
https://github.com/Homebrew/homebrew-cask#reporting-bugs
==> Migrating formula atk to at-spi2-core
==> Unlinking atk
==> Moving atk versions to /opt/homebrew/Cellar/at-spi2-core
==> Relinking at-spi2-core
Warning: at-spi2-core is outdated!
To avoid broken installations, as soon as possible please run:
brew upgrade
Or, if you're OK with a less reliable fix:
brew upgrade at-spi2-core
==> Downloading https://ghcr.io/v2/homebrew/core/curl/manifests/8.8.0
########################################################################################################################################### 100.0%
==> Fetching dependencies for curl: brotli, libunistring, gettext, libidn2, libnghttp2, ca-certificates, openssl@3, libssh2, openldap, rtmpdump, xz and zstd
Himilcon Carvalho
(11 rep)
Jul 18, 2024, 03:00 PM
• Last activity: Apr 15, 2025, 01:04 AM
1
votes
1
answers
42
views
Numeric keypad not working in Python interpreter on Magic Keyboard
The numeric keypad on my Magic Keyboard does not work when I am running the Python interpreter in interactive mode. The regular numbered keys do work for entering numbers. But when I try to enter a number on the numeric keypad when I am running the Python interpreter (launched from the Terminal) I g...
The numeric keypad on my Magic Keyboard does not work when I am running the Python interpreter in interactive mode. The regular numbered keys do work for entering numbers. But when I try to enter a number on the numeric keypad when I am running the Python interpreter (launched from the Terminal) I get no response.
Also, the numeric keypad on my Magic Keyboard DOES work properly when I am using other apps, including, but not limited to, TextEdit, Numbers, irb (the interpreter for the Ruby language), Terminal (when I am not in the Python interpreter), and every other app that I have tried.
I am now running Python 3.13.2
Richard Fuhr
(191 rep)
Mar 10, 2025, 10:02 PM
• Last activity: Apr 11, 2025, 07:02 AM
14
votes
5
answers
42606
views
Will macOS Big Sur remove the default Python installation for good?
[I initially thought that this would happen with Catalina](https://apple.stackexchange.com/q/361840/321512), but since it didn't happen, a similar question is again relevant: My question is two fold: - **When I eventually update to macOS Big Sur, will the Python (2.7.X) installation – which currentl...
[I initially thought that this would happen with Catalina](https://apple.stackexchange.com/q/361840/321512) , but since it didn't happen, a similar question is again relevant:
My question is two fold:
- **When I eventually update to macOS Big Sur, will the Python (2.7.X) installation – which currently ships with macOS – get removed from my system?**
- **What about if I do a fresh install; will
python
be gone then?**
Relevant section from macOS Catalina 10.15 Release Notes (emphasis mine):
>## Scripting Language Runtimes
>### Deprecations
> - Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app. (49764202)
> - Use of Python 2.7 isn’t recommended as this version is included in macOS for compatibility with legacy software. **Future versions of macOS won’t include Python 2.7.** Instead, it’s recommended that you run python3 from within Terminal. (51097165)
>
> Source: https://developer.apple.com/documentation/macos-release-notes/macos-catalina-10_15-release-notes
I can't find anything about this in [Big Sur's release notes](https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes) though.
Edit: I am not actively using Python 2, I'm simply wondering this since it might affect some 3rd party software which relies on the OS's Python installation.
ruohola
(1029 rep)
Nov 12, 2020, 09:17 PM
• Last activity: Apr 2, 2025, 03:59 PM
0
votes
1
answers
37
views
Python 3 - problem converting keyboard input to integer
I'm having a problem using the int() function on a user input from the keyboard in Python 3 (latest version from website). The actual program will perform various numerical calculations, but I have written a short test program that shows the problem. The int() function works fine for values embedded...
I'm having a problem using the int() function on a user input from the keyboard in Python 3 (latest version from website). The actual program will perform various numerical calculations, but I have written a short test program that shows the problem. The int() function works fine for values embedded in the code, but crashes if the same number/format is entered via the keyboard.
1. dummy_num = (2.5) #just an example float number
2. dummy_num = int(dummy_num) #converts 2.5 to integer 2
3. print (f"{dummy_num}") #verifies result of "2"
4. variable_test = input ("type 2.5 please:")
5. print (f"{variable_test}") #verifies 2.5 is actually entered
6. variable_test = int(variable_test)
The program runs as expected for lines 1 to 5. If 2.5 is entered via the keyboard in line 4, line 5 prints 2.5, but then line 6 crashes the program.
An error message is generated as follows:
variable_test = int(variable_test)
ValueError: invalid literal for int() with base 10: '2.5'
I don't understand why the int() function works fine for the value "2.5" in line 2, but crashes in line 6 - even though line 5 shows that the number entered is indeed 2.5 and the same program instruction works fine in line 2.
Sorry if this is a newbie error, but I have run out of ideas. Note that I put a few #comments in the above code just for the purpose of this question.
Cliff Merry
(3 rep)
Mar 31, 2025, 10:05 AM
• Last activity: Mar 31, 2025, 11:44 AM
0
votes
0
answers
41
views
What is in `/usr/bin/python3`?
I'm on macOS Sequoia 15.3.2, and I've been experiencing some weird behavior with `/usr/bin/python3` lately. Usually it seems like a perfectly normal Python 3.9 binary: ```none $ /usr/bin/python3 --version Python 3.9.6 ``` But then when I `cd` into a directory with [`use flake`](https://github.com/ni...
I'm on macOS Sequoia 15.3.2, and I've been experiencing some weird behavior with
/usr/bin/python3
lately. Usually it seems like a perfectly normal Python 3.9 binary:
$ /usr/bin/python3 --version
Python 3.9.6
But then when I cd
into a directory with [use flake
](https://github.com/nix-community/nix-direnv) in its [.envrc
](https://direnv.net/) file, it suddenly starts pretending like it doesn't exist:
$ /usr/bin/python3 --version
error: tool 'python3' not found
But the _file_ does exist:
$ stat /usr/bin/python3
File: /usr/bin/python3
Size: 118848 Blocks: 24 IO Block: 4096 regular file
Device: 1,14 Inode: 1152921500312496951 Links: 78
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ wheel)
Access: 2025-03-06 05:06:02.000000000 -0500
Modify: 2025-03-06 05:06:02.000000000 -0500
Change: 2025-03-06 05:06:02.000000000 -0500
Birth: 2025-03-06 05:06:02.000000000 -0500
Curiously, its first 4 bytes are 0xCAFEBABE
, which I thought [was associated with Java](https://stackoverflow.com/a/2808684/5044950) :
$ xxd /usr/bin/python3 | head
00000000: cafe babe 0000 0002 0100 0007 0000 0003 ................
00000010: 0000 4000 0000 7f20 0000 000e 0100 000c ..@.... ........
00000020: 8000 0002 0000 c000 0001 1040 0000 000e ...........@....
00000030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000040: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000060: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000070: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 0000 0000 0000 0000 0000 0000 0000 ................
But, naively, I don't see "Java" mentioned anywhere in the binary; that is, this command returns nothing:
$ strings /usr/bin/python3 | grep -i java
**What is in /usr/bin/python3
on macOS?** What kind of binary is it, and why does it print this bizarre "tool 'python3' not found" error message in some situations?
Sam Estep
(101 rep)
Mar 19, 2025, 05:09 PM
• Last activity: Mar 19, 2025, 05:35 PM
0
votes
0
answers
37
views
AppleScript to Schedule Emails for Specific Date
I am in the process of writing a small Python Script to automate sending some emails that I send every week, specifically every Monday at 8 AM. The Python script calculates when the next Monday will be, fills in the email template with the specific information, and then schedules it. I have been abl...
I am in the process of writing a small Python Script to automate sending some emails that I send every week, specifically every Monday at 8 AM. The Python script calculates when the next Monday will be, fills in the email template with the specific information, and then schedules it. I have been able to get the AppleScript to create the email, put in the recipient, and put the signature, but I have not been able to get it to click on the schedule to send email button and schedule it for 8 AM. Here is the current AppleScript I have:
tell application "Mail"
set theSender to "{sender_email}"
set newMessage to make new outgoing message with properties {{subject:"Interest in {position} at {company}", content:"{email_body}", visible:true}}
tell newMessage
make new to recipient at end of to recipients with properties {{address:"{recipient_email}"}}
set sender to theSender
end tell
end tell
tell application "System Events"
tell process "Mail"
set frontmost to true
tell window "Interest in {position} at {company}"
click pop up button "Signature:"
delay 0.5
click menu item "AccountName" of menu of pop up button "Signature:"
-- Wait for UI to update
delay 1
end tell
-- Access the menu directly through menu bar item name
-- This uses exact menu hierarchy: Message menu > Send Later...
tell menu bar 1
tell menu bar item "Message"
tell menu "Message"
click menu item "Send Later..."
end tell
end tell
end tell
delay 1
-- In the schedule dialog that appears
tell sheet 1 of window "Interest in {position} at {company}"
set value of text field 1 to "{next_monday_formatted}"
set value of text field 2 to "8:00 AM"
click button "Schedule"
end tell
end tell
end tell
Everything works but the scheduling part, and this is the last attempt I have made. I know that there are email automation tools, but I want to learn how to code this by myself and integrate it into the terminal. Any help would be appreciated, thanks!
Esteban Puyana
(1 rep)
Mar 15, 2025, 11:04 PM
0
votes
1
answers
49
views
Obliterating any trace of icon, but it still appears in Python-made notifications
I am using [Jorrick's MacOS notifications generator][1] to make custom popup notifications. Whenever one appears, it uses the Python Launcher rocketship icon, like this: [![screenshot of notification][2]][2] I want to replace the rocketship image with the System Settings gear icon. So, I followed [A...
I am using Jorrick's MacOS notifications generator to make custom popup notifications. Whenever one appears, it uses the Python Launcher rocketship icon, like this:
I want to replace the rocketship image with the System Settings gear icon. So, I followed Apple Insider's tutorial on how to do so, and succeeded. This method only works with images, not .icns files - maybe there's a lead there.
I also deleted PythonLauncher.icns, the picture of the rocketship, made a .icns of the gear, and put it in the same directory with the same name, so hopefully the program would use that as the icon.
Now, PythonLauncher.app uses the gear icon in several places, but annoyingly, still not the notification icon!
1. The Python I'm executing to make the notification. I run it with


python3 notifgen.py
from Terminal.
2. The gear.png icon is used in the Get Info window
3. The gear.png icon is used in Finder
4. The gear.png icon is used in the Dock
5. The .icns file I made to replace the rocketship. Changing this file does not change the previous three icons.
6. The notification, still using the rocketship icon, even though that icon does not exist anywhere on my system. I deleted all traces of it.
To be sure I deleted all copies of the old rocketship icon, I ran sudo find / -iname '*PythonLauncher*' 2>/dev/null | tee ~/Documents/python/pythonlaunchersearch.txt
. The ouput of that command is below - I added newlines and explanatory comments, and opened each file in Finder to check what it was.
#a directory which contains one directory, which is empty
/System/Volumes/Data/private/var/folders/68/kk888d5s1g99nsjkfvml43rm0000gp/C/org.python.PythonLauncher
#a text file
/System/Volumes/Data/Users/cn13431/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.python.pythonlauncher.sfl3
#the results of my find command, tee'd into a file
/System/Volumes/Data/Users/cn13431/Library/CloudStorage/OneDrive-[company name redacted]/Documents/python/pythonlaunchersearch.txt
#OneDrive junk
/System/Volumes/Data/Users/cn13431/Library/Group Containers/UBF8T346G9.OneDriveStandaloneSuite/OneDrive - [company name redacted].noindex/OneDrive - [company name redacted]/Documents/python/pythonlaunchersearch.txt
#a picture of the system settings gear icon that I renamed to PythonLauncher.icns to match the old image (the rocket)
/System/Volumes/Data/Applications/Python 3.13/Python Launcher.app/Contents/Resources/PythonLauncher.icns
#a directory which contains one directory, which is empty
/private/var/folders/68/kk888d5s1g99nsjkfvml43rm0000gp/C/org.python.PythonLauncher
#a text document
/Users/cn13431/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.python.pythonlauncher.sfl3
#OneDrive junk
/Users/cn13431/Library/CloudStorage/OneDrive-[company name redacted]/Documents/python/pythonlaunchersearch.txt
#OneDrive junk
/Users/cn13431/Library/Group Containers/UBF8T346G9.OneDriveStandaloneSuite/OneDrive - [company name redacted].noindex/OneDrive - [company name redacted], Inc/Documents/python/pythonlaunchersearch.txt
#the same system settings gear image as before - it shows up twice in search results.
/Applications/Python 3.13/Python Launcher.app/Contents/Resources/PythonLauncher.icns
I could never be a detective, because I can't find where this rocketship icon is hiding. **How is Python still accessing the rocketship icon, even when it no longer exists? And how can I change the icon to be the System Settings gear instead?**
Sharing an alternative to Jorrick's package that does allow to change the icon would also be a great answer.
Postnote: The commented icon
variable in the python program isn't helpful - that puts a small icon in the bottom right, like this:

SuperDialga
(11 rep)
Feb 12, 2025, 05:37 PM
• Last activity: Mar 15, 2025, 11:02 PM
4
votes
1
answers
1008
views
Why does Python's readline.read_history_file not work from a script, but work interactively?
I asked over on Stack Overflow, but this seems a problem specific to Mac OS X as the error does not happen on other OS (ubuntu for example). https://stackoverflow.com/q/42637680/447830 repeated below: So. I own the file named ~/.osc_history, as shown below: $ w 17:53 up 3:15, 5 users, load averages:...
I asked over on Stack Overflow, but this seems a problem specific to Mac OS X as the error does not happen on other OS (ubuntu for example).
https://stackoverflow.com/q/42637680/447830 repeated below:
So. I own the file named ~/.osc_history, as shown below:
$ w
17:53 up 3:15, 5 users, load averages: 1.30 1.17 1.10
USER TTY FROM LOGIN@ IDLE WHAT
kyma console - 14:39 3:14 -
kyma s001 - 17:20 - w
$ ls -l ~/.osc_history
-rw-r--r-- 1 kyma staff 13 Mar 6 17:41 /Users/kyma/.osc_history
$ ls -lO ~/.osc_history
-rw-r--r-- 1 kyma staff - 13 Mar 6 17:41 /Users/kyma/.osc_history
The header in the file is correct:
$ cat ~/.osc_history
_HiStOrY_V2_
From the interactive prompt, the following code runs fine:
$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os.path
>>> import readline
>>> histfile = os.path.join(os.path.expanduser("~"), ".osc_history")
>>> histfile
'/Users/kyma/.osc_history'
>>> readline.read_history_file(histfile)
>>> ^D
However, when I attempt to run the following, which I've called "yeuch.py"...
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import readline # Command line history
import os.path
histfile = os.path.join(os.path.expanduser("~"), ".osc_history")
if not os.path.isfile(histfile): # If there's no history file...
empty = open(histfile, "a") # ... create an ALMOST empty one...
empty.write("_HiStOrY_V2_\n") # ... with the special header line
empty.close()
readline.read_history_file(histfile) # Read history from previous sessions
readline.set_history_length(1000) # Default length was -1 (infinite)
...I see:
$ python yeuch.py
Traceback (most recent call last):
File "yeuch.py", line 14, in
readline.read_history_file(histfile) # Read history from previous sessions
IOError: [Errno 1] Operation not permitted
What the heck's going on? (I hope I'm not overlooking some stupid typo multiple times and am not a readline code expert enough to spot the error myself.)
Ubuntourist
(141 rep)
Mar 7, 2017, 12:58 AM
• Last activity: Mar 8, 2025, 11:05 PM
2
votes
1
answers
307
views
Python on Terminal cannot resolve DNS queries
I have a weird issue with Python on macOS Sequoia for the last couple of days. It did not happen right after the upgrade, it worked initially. Python in Terminal.app cannot resolve any DNS queries. However, the Python console and the builtin Terminal in PyCharm works just fine. Here's a sample; the...
I have a weird issue with Python on macOS Sequoia for the last couple of days. It did not happen right after the upgrade, it worked initially. Python in Terminal.app cannot resolve any DNS queries. However, the Python console and the builtin Terminal in PyCharm works just fine.
Here's a sample; the
http
command is [HTTPie](http://httpie.io) , a Python based utility:
% http google.com
http: error: gaierror: [Errno 8] nodename nor servname provided, or not known
Couldn’t resolve the given hostname. Please check the URL and try again.
% python3
Python 3.12.6 (main, Sep 6 2024, 19:03:47) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getaddrinfo('google.com', 80)
Traceback (most recent call last):
File "", line 1, in
File "/opt/homebrew/Cellar/python@3.12/3.12.6/Frameworks/Python.framework/Versions/3.12/lib/python3.12/socket.py", line 976, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
>>> ^D
% curl google.com
...
% dig google.com
...
;; ANSWER SECTION:
google.com. 41 IN A 142.250.184.206
;; Query time: 14 msec
;; SERVER: 192.168.178.1#53(192.168.178.1)
;; WHEN: Fri Oct 04 10:13:02 CEST 2024
;; MSG SIZE rcvd: 55
% http -v 142.250.184.206
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 142.250.184.206
User-Agent: HTTPie/3.2.3
HTTP/1.1 301 Moved Permanently
...
As you can see, network connections in general are fine, only DNS queries can't be resolved. They time out after about 30 seconds. However, the same within PyCharm works fine.
I've read about HTTP_PROXY
environment variables maybe being a problem, but I don't have those set.
I don't know enough about DNS resolution and how Python uses it to even know where to look. Any ideas?
deceze
(1441 rep)
Oct 4, 2024, 08:24 AM
• Last activity: Mar 6, 2025, 11:00 AM
Showing page 1 of 20 total questions