giovannicoppola / alfred-convert

Convert between different units in Alfred
Other
57 stars 1 forks source link

ImportError: cannot import name 'six' #5

Closed haakonstorm closed 8 months ago

haakonstorm commented 8 months ago

conv has worked flawlessly for a long time, now I can't find out why it throws this:

/pkg_resources/__init__.py", line 57, in <module>
    from pkg_resources.extern import six
ImportError: cannot import name 'six' from 'pkg_resources.extern' (
Screenshot of iTerm2 at 28 Feb 2024 at 12_39_13

Any tips for debugging this? Latest alfred, homebrew, everything updated. API key the same. Installed conv via Alfred gallery.

Is this an issue of python2 vs python3?

haakonstorm commented 8 months ago

From what I can figure out, this is an issue of python3 versions. There's .pyc files shipped with this workflow for python 3.9, 3.10 and 3.11. My system has brew installed python 3.12.2.

When the workflow runs, there are init functions under pkg_resources/extern that try to import libraries packaging, six, pyparsing and appdirs. When those aren't found in the pycache, it looks in pkg_resources/extern for those .py files there but they aren't there and hence fails.

There is also this in the workflow itself:

export PYTHONPATH="$PWD/lib"
export PATH=/opt/homebrew/bin:/usr/local/bin:$PWD/lib/bin:$PATH

This doesn't make sense to me. $PWD resolves to the workflow path itself upon workflow run, and the subfolder lib doesnt even exist there. The logic to include /opt/homebrew/bin:/usr/local/bin first in path, I don't understand why. Also lib/bin doesn't exist. I'm not sure how to proceed from here. I've tried moving the .py files it complains about, from the _vendor folder where they do exist, but then it complains up the chain when I debug from within Alfred.

giovannicoppola commented 8 months ago

both lines are irrelevant now, as 1) the libraries are no longer in a lib folder, and 2) newer Alfred versions (>5 I think) have already the brew python in the path. The pyc files are irrelevant as well. What do you get with which -a python3?

haakonstorm commented 8 months ago

Aha, that is nice to know. I'm running latest Alfred. which -a python3: /opt/homebrew/bin/python3 /usr/bin/python3

haakonstorm commented 8 months ago

So the workflow is running my homebrew python, I added python3 --version >&2 to the workflow shellcode:

Screenshot of Alfred Preferences at 29 Feb 2024 at 14_42_20
haakonstorm commented 8 months ago

Explicitly running /usr/bin/python3 resolves the problem and workflow works. That is python v3.9.6. /usr/bin/python3 convert.py "$1"

giovannicoppola commented 8 months ago

yes, this is what I was going to suggest! sometimes multiple 🐍 can entangle you! Also, unless you use Convert primarily for currency exchanges, you might want to check the new Unit Converter from the Alfred team, it's fast and a bit more flexible.

haakonstorm commented 8 months ago

Thanks for this! I'm sticking with this because it has both crypto, fiat and units in one package :) Greetings from rainy Oslo, Norway to wherever you are buddy! 🙏

haakonstorm commented 8 months ago

(I'm closing this issue as workaround worked on my setup. Still, perhaps the issue should be investigated and a generalized solution should be found?)