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

Question:

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:xampphtdocsprojectsitesproject.localhostthemesprojectlesshome.less to C:xampphtdocsprojectsitesproject.localhostthemesprojectcsshome.css
error: less2css error: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
  File "C:Program FilesSublime Text 3sublime_plugin.py", line 549, in run_
    return self.run(edit)
  File "less2css in C:UsersmyMachineAppDataRoamingSublime Text 3Installed PackagesLess2Css.sublime-package", line 48, in run
  File "less2css in C:UsersmyMachineAppDataRoamingSublime Text 3Installed PackagesLess2Css.sublime-package", line 15, in __init__
  File "less2css in C:UsersmyMachineAppDataRoamingSublime Text 3Installed PackagesLess2Css.sublime-package", line 29, in show
  File "C:Program FilesSublime Text 3sublime.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  
Asked By: NewtonEntropy

||

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}AppDataRoamingnpm
    

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

     ;C:UserscknoettgAppDataRoamingnpm

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:lessbin”. In that instance, you would add:

    ;C:lessbin

to your environment variable PATH.

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

    less2css in C:UsersmyMachineAppDataRoamingSublime Text 3Installed PackagesLess2Css.sublime-package

It is possible that your Python file is hardcoded with the path C:UsersmyMachineAppDataRoamingSublime Text 3Installed PackagesLess2Css.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}AppDataRoamingSublime Text 3Installed 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}AppDataRoamingSublime Text 3Installed 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!

Answered By: 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

Answered By: SLdragon

You can install less compiler by

npm install less

then you can find the compiler in this path

node_modulesless

then copy the lessc file to where your .less file is, then run the compiler in cmd

lessc styles.less styles.css

done!

On windows you can install git-bash terminal.
Then execute npm install less. This would install it locally.
Then in the git-bash terminal navigate to your project folder and execute
./node_modules/less/bin/lessc css/styles.less css/styles.css

Answered By: Ravi

This Command Solved my issue:

npm install -g less
Answered By: Isha Shaw
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.