Hi,
I encountered an issue with a workflow I use that creates small preview tiles and saves them into a Markdown file for Obsidian. Suddenly, the script was unable to load the external libraries I had been using. Attempting to reinstall them via pip3 on the command line (I'm using a Mac M1 running macOS 14.4 with Python installed via Homebrew) resulted in the error message: 'error: externally-managed-environment.' However, I was able to resolve the issue by creating a virtual environment and installing the libraries there. Since I couldn't find a solution through Google, I developed a workaround.
Here's how I did it:
Inside the Workflow folder (e.g., ~/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow....), create a virtual environment via the terminal.
Install the necessary libraries using pip.
Call my script using a zsh script action within the workflow, like this:
# Get the URL from the previous action
url={query}
# activate the virtual environment
source env/bin/activate
# run the python script and put the result into the variable markdown
markdown=$(python3 script.py "$url")
# deactivate the virtual environment
deactivate
# output of the result for the next action
echo "$markdown"
Do you think there might be another way to approach this issue? I'm aware that one potential solution could involve calling pip with the option --break-system-packages, but ultimately, using a virtual environment seems like the better solution to me.
If you can read german, I wrote something more detailed in my blog https://bit.ly/48PRTwe.