Giter Club home page Giter Club logo

Comments (8)

fspinillo avatar fspinillo commented on July 28, 2024

I managed to get this to work by moving the install to the root of the workflow folder

from alfred-workflow.

deanishe avatar deanishe commented on July 28, 2024

pip install --target=my-workflow-root-dir/lib python-lib-name requests

What error did you get? What command did you run exactly?

Assuming you're in Terminal in the root directory of your workflow (i.e. where info.plist is), the following correctly installs requests:

> pip install --target=libs requests

with the workflow code exactly as you posted it.

Also, the above will only work if you run the script from the workflow root directory, i.e. lib is an immediate subdirectory of the working directory (which is how Alfred runs workflows).

You need to specify paths relative to your script (or absolute paths) in libraries= to be able to run the workflow script from outside the workflow root:

wf = Workflow(libraries=[os.path.join(os.path.dirname(__file__), 'lib')])

or

wf = Workflow(libraries=[os.path.abspath(os.path.join(os.path.dirname(__file__), 'lib'))])

for an absolute path.

from alfred-workflow.

fspinillo avatar fspinillo commented on July 28, 2024

I navigated to my directory where there workflow is and ran

pip install --target=libs requests

In that folder is the following structure http://d.pr/i/2jb9

When I run the workflow I get the following error:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: 17:26:13 workflow.py:1256 ERROR    No module named requests
Traceback (most recent call last):
  File "/Users/Frank/Dropbox/Documents/Alfred/Alfred.alfredpreferences/workflows/user.workflow.CD2BC608-BC56-46FD-818E-8B92B95CA14B/workflow/workflow.py", line 1254, in run
    func(self)
  File "uber.py", line 9, in main
    import requests
ImportError: No module named requests

The full code I'm using can be see here: http://d.pr/n/Jzjs I apologize for the mess of it, still new to this and working through cleaning this up

from alfred-workflow.

deanishe avatar deanishe commented on July 28, 2024

The problem seems to be that you installed to libs and tried to import from lib.

from alfred-workflow.

fractaledmind avatar fractaledmind commented on July 28, 2024

lib vs libs is real. The images show that. That might solve the problem entirely, but would he also need an empty init.py file in libs to make it available to Python?

from alfred-workflow.

deanishe avatar deanishe commented on July 28, 2024

I'm pretty sure that is the problem.

Adding an empty __init__.py is an alternative mechanism to using libraries=.

If there's an __init__.py in your lib directory, you can just do:

from lib import requests
from lib import other_library
...

from alfred-workflow.

fspinillo avatar fspinillo commented on July 28, 2024

Good catch on the lib vs libs thing. After fixing that and making the init file I was still getting the error and then I realized I misinterpreted your howto. When I read 'my-workflow-directory' I was thinking that meant the workflow folder. Moved lib out of there into the root, as you intended, and all is good.

Thanks for the patience

from alfred-workflow.

deanishe avatar deanishe commented on July 28, 2024

No problem. The instructions could be clearer. I'll fix that.

After fixing that and making the init file

There's no need to create an __init__.py file in a libraries directory. (Note: it must be named __init__.py with the underscores; see the one in the workflow directory).

As describe in my previous comment, libraries= is an alternative to using an __init__.py file. You don't need both.

If you specify a directory using libraries=, you can import the libraries installed in it directly, e.g., import requests, but if you add an __init__.py file to the directory (let's call it lib) instead, you have to do, e.g., from lib import requests.

There's little point to doing both.

from alfred-workflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.