Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'lessc' is not recognized as an internal or external command, operable program or batch file

I have been using Sublime Text 3 to compile .less css at work, but I can't get it to work on my local machine. I think it has something to do with the path variable for lessc, but I can't figure out how to find the path variable that I need to add to my path variable to make it work. Can some one help?

I'm using Windows 7 with Sublime Text 3.

Here is the error:

Writing file /C/xampp/htdocs/project/sites/project.localhost/themes/project/less/home.less with encoding UTF-8 (atomic)
[less2css] Converting C:\xampp\htdocs\project\sites\project.localhost\themes\project\less\home.less to C:\xampp\htdocs\project\sites\project.localhost\themes\project\css\home.css
error: less2css error: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 48, in run
  File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 15, in __init__
  File "less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package", line 29, in show
  File "C:\Program Files\Sublime Text 3\sublime.py", line 86, in error_message
    sublime_api.error_message(msg)
TypeError: String required
Running l e s s c   " . / m a i n . l e s s "   " . . / c s s / m a i n . c s s "     - - s o u r c e - m a p   - - n o - c o l o r  
like image 742
NewtonEntropy Avatar asked Jan 11 '23 19:01

NewtonEntropy


2 Answers

This is a good question, because the lessc path is dissimilar in many ways to normal installation paths on Windows. I was able to confirm that lessc does need to be added to your Windows environment variable called PATH in order to for sublime-less2css to work properly, and this is directly from the maintainer of the sublime-less2css module: https://github.com/timdouglas/sublime-less2css

  1. Open Control Panel
  2. type 'env' in the Control Panel Search Bar to bring up the 'Edit the system environment variables' option (select this option, then tell the User Account Control dialog to 'Continue')
  3. click the 'Environment Variables' button
  4. Go to the System Variables section --> click once on the line that says PATH --> click 'Edit'
  5. Add the following to the end of the strings in the window that comes up:

     ;C:\Users\{add_your_Windows_username_here}\AppData\Roaming\npm
    

Since my Windows user name is cknoettg, mine looks like this:

     ;C:\Users\cknoettg\AppData\Roaming\npm

Finally, click OK --> OK --> OK

Now, retry the program.

Important proviso: For this solution to work, you must have installed less on your Windows machine using npm - the Node.js Package Manager. (Which you can get here: http://nodejs.org/)

If you used a different method to install lessc, the exact path to add to your environment variables is going to be different than what I have suggested. Let's say you installed 'lessc' directly in a folder called "C:\less\bin". In that instance, you would add:

    ;C:\less\bin

to your environment variable PATH.

Also: I noticed in the error message that you posted the following line:

    less2css in C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package

It is possible that your Python file is hardcoded with the path C:\Users\myMachine\AppData\Roaming\Sublime Text 3\Installed Packages\Less2Css.sublime-package. IF that is the case, it is possible that your lessc program is in the path: C:\Users{insert_your_Windows_username_here}\AppData\Roaming\Sublime Text 3\Installed Packages\ .

IF this is true, then you will not only have to modify your Windows environment variable PATH with:

    ;C:\Users\{insert_your_Windows_username_here}\AppData\Roaming\Sublime Text 3\Installed Packages\

You will also have to manually edit your Python file by substituting the text 'myMachine' with your current Windows username on the machine that you are located on currently. You could even try just making this direct edit to the Python code without changing the Windows environment variable, but it may or may not work.

To see a way to run your program WITHOUT editing the environment variable, you can see here (although I don't recommend it for a variety of reasons, not the least of which is the additional typing involved each time you run your script): How to install and run lessc on top of node.js and Windows?

Good luck!

like image 150
Corey Knoettgen Avatar answered Jan 17 '23 19:01

Corey Knoettgen


Because your system cannot find the "lessc" commandline tool, you can simply install it using npm if you having node in your system:

npm install -g less

like image 42
SLdragon Avatar answered Jan 17 '23 19:01

SLdragon