Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS .app has a different $PATH when launched from terminal #4273

Closed
jgillman opened this issue Sep 30, 2018 · 12 comments
Closed

MacOS .app has a different $PATH when launched from terminal #4273

jgillman opened this issue Sep 30, 2018 · 12 comments

Comments

@jgillman
Copy link
Contributor

@jgillman jgillman commented Sep 30, 2018

Apologies if this has been posted before, I found closed $PATH-related issues, but none that seemed fitting.

When I launch qutebrowser from the command line in MacOS the PATH includes everything I would expect and I'm able to correctly spawn mpv {url} and stuff like that. When I launch qutebrowser from the .app the PATH is extremely short and I can't spawn anything that's not built into the system.

I'm running 10.13.6 and installed qutebroswer with Homebrew.

PATH when launched from command line

PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/jgillman/perl5/bin:/Users/jgillman/bin:/Users/jgillman/.dotfiles/bin:/usr/local/lib/node_modules:/Users/jgillman/node_modules/.bin:/Users/jgillman/.dotfiles/fzf/bin:/usr/local/sbin:/usr/local/opt/fzf/bin

PATH when lauched from .app

PATH = /usr/bin:/bin:/usr/sbin:/sbin

This all makes sense since launching it from the command line would inherit the environment from which it was launched, but it's annoying that it's not included when launched from the app. Not sure if that's a fixable thing, or if the solution is to always launch from the terminal.

@The-Compiler
Copy link
Member

@The-Compiler The-Compiler commented Sep 30, 2018

Nothing that qutebrowser can do about that - you'll need to find a way to set a system-wide path on macOS, or just use full paths with :spawn.

@jgkamat
Copy link
Member

@jgkamat jgkamat commented Sep 30, 2018

There are quite a lot of issues about this already, but I'll try to write everything that I know in one place for search-ability.

This is a problem because the path from .profile is not propogated to gui applications in mac os. There are some ways you can set the PATH in mac os, but I don't know how much success you'll have with that.

Workarounds:

  1. Launch from the terminal, as you are doing now, to inherit the terminal's path
  2. Use config.py to append the path values you want before the browser starts
  3. Use absolute paths to any executables you run, instead of relying on PATH.
@jgillman
Copy link
Contributor Author

@jgillman jgillman commented Sep 30, 2018

Thanks @jgkamat! Sorry for the extra noise but I appreciate the compiled workarounds.

Would it be worth adding this as a "known" in the FAQ or Troubleshooting sections? idk how often this "issue" comes up.

@jgkamat
Copy link
Member

@jgkamat jgkamat commented Sep 30, 2018

This does come up quite a lot, so I would be fine with adding an entry to the FAQ personally. I don't have access to a Mac OS machine though, so I can't test/validate anything, so I can't be the one to write it :P

@jgillman
Copy link
Contributor Author

@jgillman jgillman commented Sep 30, 2018

PR incoming 😉

@Bounga
Copy link

@Bounga Bounga commented Mar 6, 2020

I found another way to address this bug that I think is much better and will work for any GUI app.

You can add the extra needed paths in /etc/launchd.conf like so:

setenv PATH /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin

Feed launchd with added values (it will be automatic after a restart, the following command is only necessary if you don't want to reboot):

egrep "^setenv\ " /etc/launchd.conf | xargs -t -L 1 launchctl

you can now restart your Dock and Spotlight:

killall Dock
killall Spotlight

Now every GUI app you launch inherit of this PATH env variable, either you launch it by clicking the icon in Applications folder or using Spotlight!

@tbsmn
Copy link

@tbsmn tbsmn commented Apr 2, 2020

I have the same problem here. Can someone help me how to find the extra needed PATH?

Also with MacVim I have a very similar problem maybe the solution of @Bounga would fix this too. That would be awesome.

@The-Compiler
Copy link
Member

@The-Compiler The-Compiler commented Apr 2, 2020

@tbsmn Something like which mpv in a terminal should tell you where that binary is.

@tbsmn
Copy link

@tbsmn tbsmn commented Apr 2, 2020

Thank you for that fast reply!
mpv is in /usr/local/bin/mpv

But @jgillman has two PATH depending how qutebrowser ist started.

PATH when launched from command line

PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/jgillman/perl5/bin:/Users/jgillman/bin:/Users/jgillman/.dotfiles/bin:/usr/local/lib/node_modules:/Users/jgillman/node_modules/.bin:/Users/jgillman/.dotfiles/fzf/bin:/usr/local/sbin:/usr/local/opt/fzf/bin

PATH when lauched from .app

PATH = /usr/bin:/bin:/usr/sbin:/sbin

How can I get these?

@The-Compiler
Copy link
Member

@The-Compiler The-Compiler commented Apr 2, 2020

The easiest way is probably :debug-pyeval os.environ['PATH'].

@Bounga
Copy link

@Bounga Bounga commented Apr 2, 2020

Thank you for that fast reply!
mpv is in /usr/local/bin/mpv

But @jgillman has two PATH depending how qutebrowser ist started.

PATH when launched from command line

PATH = /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/jgillman/perl5/bin:/Users/jgillman/bin:/Users/jgillman/.dotfiles/bin:/usr/local/lib/node_modules:/Users/jgillman/node_modules/.bin:/Users/jgillman/.dotfiles/fzf/bin:/usr/local/sbin:/usr/local/opt/fzf/bin

PATH when lauched from .app

PATH = /usr/bin:/bin:/usr/sbin:/sbin

How can I get these?

You should follow the instructions I added above.

This is related to how Mac OS application launcher (understand clicking the app icon or use spotlight) handle the PATH. It uses it’s own PATH variable that is set by launchd.

When you start an app from the term it inherits from the term PATH.

This is not true when using app launcher (which I can understand technically).

@tbsmn
Copy link

@tbsmn tbsmn commented Apr 2, 2020

Thank you @The-Compiler and @Bounga this worked perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.