steelbrain / linter

A Base Linter with Cow Powers http://steelbrain.me/linter/
MIT License
1.1k stars 178 forks source link

`$PATH` only present when Atom is launched from command line #150

Closed dmnd closed 9 years ago

dmnd commented 10 years ago

When Atom is launched from the command line with atom, it has access to $PATH as defined by the shell so the linter can often find executables.

But if Atom is launched via the dock, Spotlight, Applications folder, or other GUI method, it does not inherit $PATH. This means that linters will fail to find their executables. I bet this problem is behind a lot of the bug reports that see the spawn ENOENT message.

rodrigoSyscop commented 9 years ago

As jjoedouglas said, just edit ~/.atom/init.coffee. Go to menu Atom > Open Your Init Script, just add this lines at the end of the file:

process.env.PATH = ["/usr/bin",
                    "/usr/local/bin",
                    ].join(":")

Works for me.

tr33m4n commented 9 years ago

Just FYI, under Linux/Ubuntu I had to add /bin to the path:

process.env.PATH = ["/bin",
                    "/usr/bin",
                    "/usr/local/bin",
                    ].join(":")

Otherwise certain elements of the settings page wouldn't work correctly, such as searching for a package to install (would throw an error saying it could not find uname)

Cheers Dan

Trefex commented 9 years ago

Adding

process.env.PATH = ["/usr/bin",
                    "/usr/local/bin",
                    ].join(":")

to .atom/init.coffee fixed the issue for me.

:+1:

bee-git commented 9 years ago

Using Atom 0.198.0 on Windows 8.1 Professional together with XAMPP. Trying to use linter-php.

Have entered the following line at the end of .atom/init.coffee

process.env.PATH = ["C:/PortableApps/XAMPP/App/xampp/php", process.env.PATH].join(":")

With this entered, and if the linter detects an error, I get this error message:

'php' could not be spawned. Is it installed and on your path? 
If so please open an issue on the package spawning the process.

with a "Uncaught Error: spawn php ENOENT" in the log file.

I tried adding the following lines to the .atom/config.cson file:

"linter-php":
    phpExecutablePath: "C:/PortableApps/XAMPP/App/xampp/php/"

in addition to the entry in the .atom/init.coffee file that I mentioned above, but that didn't eliminate the problem.

In other words, the problems that others have mentioned in this thread seem to still be occurring in the version of the linter that I'm using on Windows 8.1, and the proposed workarounds don't seem to solve the problem.

UPDATE (2015-05-15) - Checked to see if this problem could be addressed by adding the directory with the php executable to the overall system PATH variable. Doing that does, in fact, address the problem - the linter then works correctly. The PATH variable can be changed using "View Advanced System Settings", which brings up the "System Properties" dialog, and the PATH variable can be changed for either the user or the system by clicking on the "Environment Variables" button and editing the PATH variable contents and then saving the changes.

jean-io commented 9 years ago

Path should contain only directory, right? not a binary like php, so try this:

process.env.PATH = ["C:/PortableApps/XAMPP/App/xampp/", process.env.PATH].join(":")
bee-git commented 9 years ago

@Ricain - Thank you for the suggestion. However, C:/PortableApps/XAMPP/App/xampp/php/ is, in fact, the directory where the php executable php.exe is located. That is, the fully specified path and file name of the php executable is

C:/PortableApps/XAMPP/App/xampp/php/php.exe

As I mentioned in the update to my original post, the problem can be solved by placing the path for the php executable in the system PATH variable. But that really shouldn't be necessary given the configuration and init script options that are supposed to allow you to specify where the executable is located.

beck commented 9 years ago

Has anyone else noticed that when you checkout a different branch (in a project dir already opened in atom), the path is destroyed? Thus in turn, breaking linter.

chrisandrewcl commented 9 years ago

Hey guys,

process.env.PATH = ["/usr/bin",
                    "/usr/local/bin"].join(":")

also tried

process.env.PATH = ["/usr/bin",
                    "/usr/local/bin",
                    process.env.PATH].join(":")

to my ~/.atom/init.coffee didn't work. I also noted that Atom when started from command line works fine but didn't when started from my Xubuntu panel, so I edited the Atom shortcut (laucher) in my panel and changed the command from /opt/atom/atom %F to bash --login -c "atom", as suggested above.

Now all my ruby related packages are working!

davidawad commented 9 years ago

@Trefex THANK YOUUUU. YOU HAVE SOLVED MY LIFELONG STRUGGLE WITH THIS EDITOR.

ssfrr commented 9 years ago

It seems that init.coffee isn't run until after packages are loaded, so if one of your packages tries to spawn a shell command that's not on your default $PATH then it still doesn't work. As fas as I can tell the only alternative in that case is tweaking the launcher to run Atom from within a shell environment.

rennsport commented 9 years ago

I'm running OS X 10.10.5 and Atom 1.0.9 and I'm having this issue both launching from GUI and terminal. Are there any other solutions other than editing the init.coffee because that doesn't seem to work for me.

steelbrain commented 9 years ago

@rennsport why not specify a path to the executable in linter config?

rennsport commented 9 years ago

@steelbrain So my linter directory is /Users/[user]/.atom/packages/linter what file would I need to edit because none are standing directly out as a config file.

steelbrain commented 9 years ago

@rennsport You won't need to edit any file for this, just goto settings view, the linter provider you want to specify executable for, and there should be a field for it.

rennsport commented 9 years ago

@steelbrain My linter provider doesn't seem to have those options in settings

steelbrain commented 9 years ago

@rennsport that is the base linter you are pointing at, by a "provider", I meant packages like "linter-jshint", "linter-eslint" and "linter-flake8"

rennsport commented 9 years ago

@steelbrain I feel slightly less capable now as I linked this project within the project itself without realizing it haha. Sadly however, the actual linter provider does not have such settings unless I'm missing something obvious again.

Edit: Under the configuration I am told I need to set the Executable Path, but there is no option for that and I'm not sure what file I would add it to.

steelbrain commented 9 years ago

@rennsport It does have that setting and it's called executable, see https://github.com/AtomLinter/linter-pylint/blob/master/lib/main.coffee#L9 but if you are unable to see it for some reasons, then I would suggest you try this and let me know the results of it

mv ~/.atom ~/.atom-bkp
apm install linter
apm install linter-pylint
rennsport commented 9 years ago

@steelbrain I now see said settings. Maybe the theme I was using hid them? Anyways I have now gotten around the first error, and I have a second (I apologize for my novice understand of this). Error: "Traceback (most recent call last):" I can show the full error in a pastebin or something similar.

steelbrain commented 9 years ago

@rennsport can we please chat in the atom slack or at least in a separate issue, I have to open up this super-long page each time and tons of people are notified each time via email/push.

anildigital commented 8 years ago

In linter-rubycop plugin,

I have rubocop command set like this.

/Users/anil/.gem/ruby/2.2.4/bin/rubocop

But when I open Ruby project from Atom menu File -> Open.., it gives me following error

Error: /Users/anil/.rubies/ruby-2.2.4/lib/ruby/2.2.0/rubygems/dependency.rb:315:in to_specs': Could not find 'rubocop' (>= 0) among 229 total gem(s) (Gem::LoadError) Checked in 'GEM_PATH=/Users/anil/.gem/ruby/2.2.0:/Users/anil/.rubies/ruby-2.2.4/lib/ruby/gems/2.2.0', executegem envfor more information from /Users/anil/.rubies/ruby-

But when I open project from command like like atom . I don't see this error.

My Atom version is 1.3.2 and I am using El Capitan.

Arcanemagus commented 8 years ago

This is an issue that is planning on being solved in Atom (see https://github.com/atom/atom/issues/4126), with a temporary workaround planned in https://github.com/AtomLinter/atom-linter/issues/62 for linter plugins that utilize the atom-linter package. For any that don't they will need to work around this limitation on their own.

I'm locking this issue as it hasn't been the proper repository for this issue for a very long time in the first place, and any further work on resolving the issues presented here will be done in the linked issues.

For any users on OS X until a workaround for Apple's "interesting" decision is put in place, the simplest method is to launch Atom from a terminal that has a full environment set up using atom ..

steelbrain commented 8 years ago

Here's an announcement for you, we have recently published a release of atom-linter (npm helper module for linter providers) that now automatically determines $PATH even if atom is not launched from terminal. Therefore all linters using it for execution, once updated to the new version, will be working consistently from both dock and CLI.