Shell Environment Loading
On macOS, an app launched by a GUI launcher (Finder, Dock, Spotlight, etc.) inherits a relatively empty environment, and there are no sane ways to change it. The situation caused complaints about tools working in a terminal not working when launched from the IDE. That is why the IDE attempts to load a shell environment on startup. To do this, it starts a shell in background and instructs it to run a helper process. And since 2021.2, the IDE shows a notification when the loading fails.
The most common reason is a shell initialization script interacting with a terminal. The IDE has to use the -i option to run a shell in the interactive mode because environment modifications usually occur in ~/*rc scripts, and these scripts take the ability to interact with a terminal for granted. Unfortunately, a shell launched from the IDE has no access to a terminal, and the loading either fails with an error or times out (for more details, look for the "can't get shell environment" line in the log).
To fix the loading and get rid of the notification, please change the script so that all possible terminal interactions are skipped when a shell is launched by the IDE; one possible way is to put them inside conditional blocks:
if [ -z "$INTELLIJ_ENVIRONMENT_READER" ]; then
...
fi
Please sign in to leave a comment.
I got this error message on startup:
The error popup directed here, but nothing on this page addresses what to do if we don't have zsh located in /usr/local/bin.
Is there a setting to change the location IntelliJ uses for zsh?
@Matthew That message means either there is no '/usr/local/bin/zsh' in your system or the IDE is slow to use the zsh shell to get the environment variables so it gave up and shows that notification.
The IDE uses the `SHELL` environment variables to find your system default shell and runs it to get all environment variables.
Please check if you have '/usr/local/bin/zsh' in your system. If you don't have zsh in that folder, it means you have configured your default shell in the system to the wrong path.
macOS by default has '/bin/zsh` in a system instead of that path.
If you have '/usr/local/bin/zsh`, check running zsh -l is faster or if it needs several seconds. Also, try suggestions here to see if it fixes your issue: https://youtrack.jetbrains.com/issue/IDEA-276617/PhpStorm-has-failed-to-load-the-environment-from-bin-zsh.-Integration-with-tools-that-rely-on-environment-variables-may-work#focus=Comments-27-5290436.0-0
Hmmm, between using chsh to make sure my default zsh was /bin/zsh and rebooting, the issue seems to have gone away.
I am sorry I must be dumb, but please explain like I am 5. Is “The script” is the ~/*rc script? and “all possible terminal interactions” does that mean the whole file including all of the exports and aliases?
I have complex setup scripts which have a 25 year history. I have followed the advice about using INTELLIJ_ENVIRONMENT_READER to skip interactive operations. Nonetheless, the PATH does not seem to be set correctly. Is there any way to determine which PATH IntelliJ Idea is using?
What's your OSes? Is it Linux or macOS?
If it is Linux, please refer to the guide here https://wiki.archlinux.org/title/environment_variables#Graphical_environment to configure a PATH for graphical environment, relogin the user or restart the system to see if it helps.
If it is macOS, try one of the way here: https://stackoverflow.com/q/22465332, close the IDE, start it again.
Hi Lejia.
Thanks for responding. I'm on MacOS. I revisited my startup scripts, and using INTELLIJ_ENVIRONMENT_READER, I avoided everything except the functions and definitions I needed to set PATH. This seems to have fixed my problem.
My SHELL env variable is somehow not where IDE is looking for shell executable:
$ echo $SHELL
/opt/homebrew/bin/fish
IDE: PyCharm has failed to load the environment from '/usr/local/bin/fish'. Integration with tools that rely on environment variables may work incorrectly.
@Ilya Kamen Hi, please click IDE main menu `Help | Show Log in Finder`, find the idea.log, upload it in https://uploads.jetbrains.com/, share the upload id here for investigating this issue.
Lejia Chen 2024_06_04_AcccPPUXXvGLtUBqqe9FWT
Background: I've migrated MacOS from intel cpu to m3, then reinstalled brew, anaconda, fish, python. Then I've migrated from pycharm 2023 to pycharm 2024, the latest.
Here are shell settings in IDE: 2024_06_04_xBEMxL29Qzg1KucfnjUvR7
In the log, I saw:
> java.lang.RuntimeException: $SHELL points to a missing or non-executable file: /usr/local/bin/fish
I think you haven't configured the fish shell to the default shell in macOS system.
Please check the https://stackoverflow.com/a/20506404 's “From Terminal” section, restart the system to see if it helps.
What script? Where do we put this code:
For anyone using zsh who had this issue, where the above article didn't help (or the article just wasn't clear enough).
Added this to my .zshrc file: