eth-sri / lmql

A language for constraint-guided and efficient LLM programming.
https://lmql.ai
Apache License 2.0
3.48k stars 191 forks source link

Explicitly use python3 #314

Closed tillfalko closed 3 months ago

tillfalko commented 5 months ago

The Issue

The Node backend makes system calls to python, but this symlink is not available on e.g. a fresh install of Ubuntu/WSL2.

On such a system it is still possible to install lmql and run lmql playground, but as soon as you hit 'Run', you'll get

Compiled successfully!

You can now view web in the browser.

  Local:            http://localhost:3000
  On Your Network:  http://172.20.20.84:3000

Note that the development build is not optimized.
To create a production build, use yarn build.

webpack compiled successfully
Error: spawn python ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn python',
  path: 'python',
  spawnargs: [ 'live.py', 'endpoints', 'lmql' ],
  cmd: 'python live.py endpoints lmql'
}

I suspect the reason this wasn't caught earlier is that installing conda creates a python symlink. So very few developers would encounter this issue.

The Solution

Simply replace all OS calls to python with python3.

lbeurerkellner commented 4 months ago

Thanks for this. One question I have regarding this: Under conda, is python3 always the conda version? If not, this could cause issues in some cases, no?

tillfalko commented 4 months ago

I cannot find documentation to cite here, but the python and python3 symlinks are both in Conda's bin directory, which gets added to your PATH. They point to the same location

$ which python
/home/f/miniconda3/bin/python
$ file /home/f/miniconda3/bin/python
/home/f/miniconda3/bin/python: symbolic link to python3.11
$
$ which python3
/home/f/miniconda3/bin/python3
$ file /home/f/miniconda3/bin/python3
/home/f/miniconda3/bin/python3: symbolic link to python3.11
$
$ which python3.11
/home/f/miniconda3/bin/python3.11

So if you have Conda installed, python3 should work just like python. I really don't think there is any benefit to using python.

lbeurerkellner commented 3 months ago

Sorry for the delay. I just tested this under conda, and it should indeed not cause any issues. Thank you for this contribution.