alfred-network-location
alfred-network-location copied to clipboard
support python3
using https://github.com/NorthIsUp/alfred-workflow-py3
Hey this doesn't seem to work? Getting an error about a package missing despite having said package installed
[23:32:48.236] ERROR: Network Location[[Script Filter](alfredpreferences:workflows%3Eworkflow%3Euser.workflow.63597988-55BC-4F83-A9E6-E386501BBED5%3EC548AB66-5E3A-4FDE-9357-8379F7B19007)] Code 1: .
23:32:48 workflow.py:2114 ERROR No module named 'requests'
Traceback (most recent call last):
File "/Users/ethan/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.63597988-55BC-4F83-A9E6-E386501BBED5/workflow/workflow.py", line 2092, in run
if self.version:
File "/Users/ethan/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.63597988-55BC-4F83-A9E6-E386501BBED5/workflow/workflow.py", line 1186, in version
from .update import Version
File "/Users/ethan/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.63597988-55BC-4F83-A9E6-E386501BBED5/workflow/update.py", line 34, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
23:32:48 workflow.py:2116 INFO for assistance, see: https://github.com/deanishe/alfred-network-location/issues
23:32:48 workflow.py:2136 DEBUG ---------- finished in 0.002s ----------
[23:32:48.238] Network Location[[Script Filter](alfredpreferences:workflows%3Eworkflow%3Euser.workflow.63597988-55BC-4F83-A9E6-E386501BBED5%3EC548AB66-5E3A-4FDE-9357-8379F7B19007)] {
"items": [
{
"title": "Error in workflow 'net.deanishe.alfred-network-location'",
"subtitle": "No module named 'requests'",
"valid": false,
"icon": {
"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
}
}
]
}
did you install module with right python instance?
What is the proper instance in this case? I use python 3.10 globally on my machine using pyenv. If I do a pip list
or sudo pip list
(packages available to all users) I see requests
❯ pip list | grep requests
requests 2.26.0
❯ sudo -H pip list | grep requests
requests 2.26.0

you can debug in alfred, type which python3
in it.
plus, i use /bin/zsh not /bin/bash
in my machine, it work well.
Yeah zsh
should be fine for this simple script, and it's been the default on macOS for a few years now (I use it as well).
How do you have python
setup on your machine? Are you just using the python3
that Apple includes on the system? I think the issue is because I use pyenv
. I'm not sure what the best way to get pyenv
into this script is.
00:59:53.003] ERROR: Network Location[[Script Filter](alfredpreferences:workflows%3Eworkflow%3Euser.workflow.BC3AD715-0496-4929-8E38-62E4FCC16A01%3EC548AB66-5E3A-4FDE-9357-8379F7B19007)] JSON error: JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0. in JSON:
/usr/bin/python3
{
"items": [
{
"title": "Error in workflow 'net.deanishe.alfred-network-location'",
"subtitle": "No module named 'requests'",
"valid": false,
"icon": {
"path": "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertStopIcon.icns"
}
}
]
}
It is using /usr/bin/python3
whereas with in my own terminal with pyenv
I get:
❯ which python3
/Users/ethan/.pyenv/shims/python3
I could symlink pyenv
over the system python3
, though I'd prefer not to. The three lines needed to enable pyenv
are
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
However putting them into the alfred script as follows doesn't change it from /usr/bin/python3
to the pyenv
shims.
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
which python3
python3 netloc.py list "$1"
Any thoughts? pyenv
info is here if you aren't aware of it.
if command -v pyenv >/dev/null; then
eval "$(pyenv init --path)"
fi
i add above code in ~/.zshenv
pyenv from brew install pyenv
Yep you are right seems you need to add that to your .zshenv for it to work. I ended up switching to this similar workflow that uses a bash script since it was lighter weight than using python.