{"id":9888,"library":"lesscpy","title":"lesscpy - Python LESS Compiler","description":"lesscpy is a Python compiler for LESS stylesheets, converting .less files into standard CSS. Its current version is 0.15.1, released in 2018. The project is largely unmaintained, with no significant development since its last release, indicating a maintenance-only status.","status":"maintenance","version":"0.15.1","language":"en","source_language":"en","source_url":"https://github.com/lesscpy/lesscpy","tags":["css","less","compiler","stylesheet","frontend"],"install":[{"cmd":"pip install lesscpy","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for lexical analysis and parsing of LESS code.","package":"ply"},{"reason":"Used for minifying the compiled CSS output.","package":"cssmin"}],"imports":[{"note":"This is the main function to compile LESS code. It's also commonly accessed as `lesscpy.compile` after a general `import lesscpy`.","symbol":"compile","correct":"from lesscpy import compile"}],"quickstart":{"code":"from io import StringIO\nimport lesscpy\n\n# Example LESS code as a string\nless_code = \"\"\"\n@primary-color: #3498db;\n@spacing: 10px;\n\n.container {\n  max-width: 960px;\n  margin: 0 auto;\n  padding: @spacing;\n\n  h1 {\n    color: @primary-color;\n    margin-bottom: @spacing * 2;\n  }\n\n  p {\n    line-height: 1.6;\n  }\n}\n\n.button {\n  background-color: @primary-color;\n  color: white;\n  padding: @spacing @spacing * 2;\n  border: none;\n  cursor: pointer;\n\n  &:hover {\n    opacity: 0.9;\n  }\n}\n\"\"\"\n\n# Compile the LESS code from a StringIO object\n# lesscpy.compile expects a file-like object or a filename string.\n# The 'minify' argument is common for output control.\ncss_output = lesscpy.compile(StringIO(less_code), minify=True)\n\nprint(\"--- Compiled and Minified CSS ---\")\nprint(css_output)","lang":"python","description":"This quickstart demonstrates how to compile a LESS string into minified CSS using the `lesscpy.compile` function, which accepts a file-like object (like `StringIO`) as input."},"warnings":[{"fix":"For projects requiring the latest LESS features, consider using the official Node.js LESS compiler or a more actively maintained alternative. For existing `lesscpy` projects, limit LESS usage to features available prior to 2018.","message":"Due to lack of active development since 2018, `lesscpy` may not fully support newer LESS features (e.g., modern CSS Grid functions, advanced color functions, or recent syntax improvements).","severity":"gotcha","affected_versions":"0.15.1 and earlier"},{"fix":"Ensure all paths in `@import` directives are correct and relative to the input LESS file. Explicitly handle file I/O with UTF-8 encoding (e.g., `open('file.less', 'r', encoding='utf-8')`).","message":"File system operations and path resolution within LESS files (e.g., `@import` directives) can be sensitive to the current working directory or system encoding, potentially leading to `FileNotFoundError` or `UnicodeDecodeError`.","severity":"gotcha","affected_versions":"0.15.1 and earlier"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Review the LESS code for advanced features. Try to simplify the LESS or adapt it to `lesscpy`'s known capabilities. If possible, test the problematic LESS snippet against an official LESS compiler to confirm its validity.","cause":"The LESS code contains syntax not supported by `lesscpy`, likely a newer LESS feature or a subtle deviation from `lesscpy`'s parsing capabilities.","error":"lesscpy.lessc.errors.LesscpySyntaxError: Syntax Error: Unexpected '@' at line X, col Y"},{"fix":"Verify that all `@import` paths are correct and relative to the main LESS file being compiled. If compiling LESS from a string that has `@import`s, ensure the imported files are accessible in the current working directory or `lesscpy` might need configuration (though this is less common for simple string compilation).","cause":"An `@import` directive within your LESS file refers to a file that `lesscpy` cannot locate. This is often due to incorrect relative paths or the file not being in `lesscpy`'s expected search path.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'path/to/imported/file.less'"},{"fix":"When reading LESS files, explicitly specify the encoding, e.g., `with open('file.less', 'r', encoding='utf-8') as f: lesscpy.compile(f, ...)`.","cause":"`lesscpy` attempted to read a LESS file or input string with an incorrect character encoding, often defaulting to a system-specific encoding instead of UTF-8.","error":"UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position X: character maps to <undefined>"}]}