Jump to content

Newby Help: Running a ZSH command with Default Env.


Recommended Posts

This is probably a newby question (I'm not very familiar with the OSX Shell).

 

I need to run a two line script in the terminal:

 

cd /Users/jgoldberg/Dropbox/Mac/Downloads/Census
python3.9 api_conn.py

 

python3.9 was installed on my machine via anaconda and so is in a (base) environment. If I open a terminal and type those two commands, they execute as expected. But if I try to run those two commands from "Terminal Command" action in workflows, it can't find the python3.9.

 

Any tips on how I can change the workflow to use the proper environment, or how I can chance my environment variables to make the workflow work?

 

Thanks!

 

-Jason
 

Link to comment

Three ways:

  1. Use the full path to your tool. Instead of python3.9, call /usr/local/bin/python3.9 (or whatever the path is). Simplest method.
  2. source your shell’s configuration file before calling your script. Example: source "${HOME}/.zshrc". Highest chance of success, but may make your code marginally slower.
  3. Set PATH before calling your python installation. Similar to 1 and gives you access to more tools.

Link to comment

I suspect I am having a similar problem after upgrading to a new iMac. Specifically, the workflow Copy name [1.6] has /usr/bin/python as the Language variable. $PATH does contain the paths to Python in /opt/Anaconda but workflow fails and the log shows:

 

````

[12:58:37.371] Copy name [1.6][Hotkey] Processing complete
[12:58:37.379] Copy name [1.6][Hotkey] Passing output '' to Run Script
[12:58:37.452] Copy name [1.6][Run Script] Processing complete
[12:58:37.456] Copy name [1.6][Run Script] Passing output '' to Post Notification
[12:58:37.457] Copy name [1.6][Run Script] Passing output '' to Copy to Clipboard

````

 

How might I ensure that the workflow uses the correct install of Python?

 

Thanks.

Link to comment
16 minutes ago, jeremycherfas said:

I suspect I am having a similar problem


I wouldn’t call this a problem, Alfred does it by design.

 

Making your Workflow mostly independent of external changes benefits you both as a Workflow developer and a Workflow user: by ensuring everyone has a similar starting point, changing the environment must be a conscious decision with clear consequences.

 

18 minutes ago, jeremycherfas said:

Specifically, the workflow Copy name [1.6] has /usr/bin/python as the Language variable.


Then that is what it will use. That’s the default on macOS.

 

19 minutes ago, jeremycherfas said:

$PATH does contain the paths to Python in /opt/Anaconda


That doesn’t matter if the Workflow is using a full path to the executable.

 

20 minutes ago, jeremycherfas said:

but workflow fails and the log shows


There’s no error there.

 

20 minutes ago, jeremycherfas said:

How might I ensure that the workflow uses the correct install of Python?


I don’t know which Workflow you’re talking about, so it’s impossible to say.

 

Where did you get it from? You should ask this on the forum post or GitHub repo where you found the Workflow, so the creator and it’s users can see your issue and help.

Link to comment
Just now, jeremycherfas said:

I did in fact mention the name of the workflow, as you indeed quoted.

 

Yes, you mentioned the name but didn’t link to it. I had no way of knowing where you got it from and I was on a (very slow) phone at the time, meaning that if I changed tabs to spend an unknown amount of time searching the web for whatever you might be mentioning, I could’ve lost what I had already written.

 

So it was either helping with the limited information you gave, or possibly being unable to help at all. When requesting assistance, you should strive to make life easier to potential helpers. That helps you by lowering the friction needed for people to look into your issue. The higher the friction, the lower the chance other people will investigate.

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