Comments (8)
I managed to get this to work by moving the install to the root of the workflow folder
from alfred-workflow.
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.
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.
The problem seems to be that you installed to libs
and tried to import from lib
.
from alfred-workflow.
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.
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.
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.
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)
- Cache Image HOT 5
- Basic auth HOT 3
- Pass parameter to subprocess HOT 5
- Tutorial options for keywords need to be updated for Alfred 4 HOT 11
- set_config raises error when the bundle id is null HOT 4
- Setting only arg on Variables adds line break HOT 1
- will it support python3? HOT 1
- python3 has no cpickle HOT 1
- cant get output HOT 11
- chr() arg not in range(256) error when trying to use Beautiful Soup 4 HOT 1
- workflow:magic not working?
- API functionality question
- AlertCautionIcon.icns does not exist on Big Sur
- ERROR: [Script Filter] JSON error
- Google SDK
- Can't get Script Filter to find the pinboard.py file from the tutorial HOT 1
- [Feature request] Possible to open bookmarks from root?
- Not working on the latest MacOS 12.3 HOT 11
- How to fetch chrome cookie?
- Issues with notify.notify in release version HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alfred-workflow.