Jump to content

Adding Python Libraries for custom workflow


Recommended Posts

Hello guys,

 

Running v3.

 

Question : My workflow needs a Python library that isn't shipped with OSX... as I'm using my workflows on multiple machines I'd rather NOT have to install various python packages everywhere.

 

Now I couldn't find any information on where to add python libraries that are to be used for a custom workflow...

 

Any information on this ?

 

Thanks,

 

Cheers,

Link to comment

Ohh and I also didn't find how to call the imported Python libraries.

 

e.g. I'm trying to add tld library: https://pypi.python.org/pypi/tld#downloads

 

Once downloaded I get all these files here :

 

Screen-Shot-2016-06-15-10-58-25-DWsfGGto

 

Now :

 

1) What files/folder should I move to my workflow (and where is my workflow folder in which I must paste these files/folder)

2) What do I need to do to be able to use basic commands using the Python Library I've added, e.g.:

 
from tld import get_tld
from tld.utils import update_tld_names
update_tld_names()

print get_tld("{query}")

Thanks !!

Link to comment

Best thing to do with Python libraries is to install them in the workflow directory alongside info.plist.

Right-click on your workflow in Alfred Preferences and select Open in Terminal.

Now you're in the workflow directory. This is the working directory when Alfred runs your workflow, and you can import any Python packages/modules in it directly.

So, in Terminal just run:

pip install -U --target=. tld [<package2>...]

Note: That probably won't work if your pip is installed in a Homebrew Python due to a pip bug. You need to install pip in the system Python.

Link to comment
  • 7 years later...

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...