Jump to content

Trouble using 3rd party module in script filter


Recommended Posts

Hi My first post on any forum hope it goes well,

 

I am trying to make a workflow to help me use git for my job, I am trying to make a script filter which lists remote branches, I need to import git from GitPython.

I have installed script inside workflow directory using pip3

ran this in my workflow root.

pip install --target . gitpython

file system looks like this in my workflow folder:

.				gitdb-4.0.10.dist-info
..				info.plist
GitPython-3.1.36.dist-info	smmap
git				smmap-5.0.0.dist-info
gitdb

 

my script filter looks like this

import sys
import json
from git import git

r = Repo('~/Workspaces/apollo')
remote_refs = r.remote().refs

for refs in remote_refs:
    print(refs.name)

subtitle = ' '.join(refs)

query = sys.argv[1]

out = {"items": [
    {
        "uid": "desktop",
        "type": "file",
        "title": query,
        "subtitle": "sub" + subtitle,
        "arg": "123",
        "autocomplete": "Desktop",
        "icon": {
            "type": "fileicon",
            "path": "~/Desktop"
        }
    }
]}

sys.stdout.write(json.dumps(out))

when I debug my flow I get this error:

line 3, in <module>
    from git import git
ModuleNotFoundError: No module named 'git'

 

also one question I have because I am not very proficient with python, if anyone can inform me why does alfred's script filter not import modules installed globally, like any other script on my machine.

 

Thanks in advance

Link to comment

Welcome @papunag209,

 

You also need to set PYTHONPATH to include the new folder where you installed the script.

 

6 hours ago, papunag209 said:

why does alfred's script filter not import modules installed globally, like any other script on my machine.

 

It’s your shell that knows where those are, not the scripts. Alfred by design does not load your shell environment. See Understanding the Scripting Environment.

Link to comment
  • 2 weeks later...

Thanks @vitor I found a workaround to add module path inside script itself, will read into resource you provided, thanks again

 

Don't know if this is best practice probably not but if its any help for anyone here is my workaround

global_module_path = "/opt/homebrew/lib/python3.11/site-packages"
sys.path.append(global_module_path)

 

Edited by papunag209
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...