Zulip Chat Archive

Stream: lean4

Topic: How to install Lean 4?


Kenny Lau (Jan 05 2021 at 11:51):

Bryan Gin-ge Chen said:

In case it's helpful for others, here are the steps I took to get a Lean 4 project up and running with vscode-lean4.

First, clone your favorite Lean 4 project, e.g. advent-of-lean-4:

git clone https://github.com/rwbarton/advent-of-lean-4.git

Update elan if you haven’t recently:

elan self update

Then install lean4 using elan:

elan install leanprover/lean4:4.0.0-m1

Navigate to your lean4 project directory, set an override for the Lean version, and open VS Code:

cd advent-of-lean-4
elan override set leanprover-lean4-4.0.0-m1
code .

Open the extensions tab in VS Code, search for vscode-lean4 and install it. It seems to override vscode-lean in all Lean projects, so for now I've disabled it globally and enabled it only in this workspace. Also, vscode-lean should also be disabled in Lean 4 projects, otherwise unicode shortcuts don't seem to work.

The extension should run when you open a .lean file and you can test the features mentioned in the README. For example, you can go through each of the files in advent-of-lean-4 and make the (relatively straightforward) fixes to get it to work with 4.0.0-m1.

edit: added reminder to update elan.
edit 2: added note about disabling vscode-lean to get unicode translation to work.

Reid Barton (Jan 05 2021 at 16:39):

I added a leanpkg.toml file to advent-of-lean-4 and fixed the programs that needed fixing, so a couple of the steps above can be skipped now.

Gihan Marasingha (Jan 06 2021 at 17:32):

Using vscode, how do I evaluate the 'main' function in a Lean file (assuming that question makes sense)? E.g. 1/a.leanin advent-of-lean-4.

Johan Commelin (Jan 06 2021 at 17:39):

#eval main?

Gihan Marasingha (Jan 06 2021 at 17:55):

I get an error message failed to synthesize Lean.Eval (List String → IO UInt32) when I try that.

Reid Barton (Jan 06 2021 at 18:04):

I don't know how to do it in vscode, but from the command line you can run lean --run 1/a.lean

Gihan Marasingha (Jan 06 2021 at 18:07):

@Reid Barton Thanks. Do I need to build the project first? I'm getting an error message about no such file a.in.

Reid Barton (Jan 06 2021 at 18:07):

You need an input file such as the one provided by https://adventofcode.com/2020/day/1

Gihan Marasingha (Jan 06 2021 at 18:08):

Oh, thanks!

Gihan Marasingha (Jan 06 2021 at 18:08):

Duh, I hadn't actually read the code.

James Caldwell (Mar 02 2023 at 23:14):

I'm running Ubuntu. I have had a lot of trouble getting to this point. I have elan installed and vs code with the lean extension. When I load a simple file that I have seen running in lean, vs code gets stuck with the perpetual message "Waiting for Lean server to start..."

λ > which lean
/home/jlc/.elan/bin/lean
λ > cd ~/.elan/bin/
λ > ls
elan lake lean leanc leanchecker leanmake leanpkg
λ >

Any ideas what tio try next?

Adam Topaz (Mar 02 2023 at 23:16):

Just to be sure, are you trying to isntall lean4?

James Caldwell (Mar 02 2023 at 23:59):

Yes - lean4.

James Caldwell (Mar 03 2023 at 00:00):

Sorry for the delay ... I took a break.

Arthur Paulino (Mar 03 2023 at 00:05):

Do you have a Lean 4 toolchain? What does elan toolchain list show?

James Caldwell (Mar 03 2023 at 00:06):

λ > elan toolchain list
stable (default)
leanprover/lean4:4.0.0-m1
leanprover/lean4:4.0.0-m3
leanprover/lean4:nightly
leanprover/lean4:stable
λ >

Arthur Paulino (Mar 03 2023 at 00:08):

Do you have a Lean 4 project you want to open? Or do you want to start a project from scratch?

James Caldwell (Mar 03 2023 at 00:09):

Start a new one.

James Caldwell (Mar 03 2023 at 00:09):

Here's the director I'm working in.

ls -al
total 32
drwxrwxr-x 3 jlc jlc 4096 Mar 2 14:56 .
drwxrwxr-x 4 jlc jlc 4096 Mar 2 14:51 ..
drwxrwxr-x 7 jlc jlc 4096 Mar 2 14:56 .git
-rw-rw-r-- 1 jlc jlc 54 Mar 2 14:56 .gitignore
-rw-rw-r-- 1 jlc jlc 2522 Feb 23 15:07 GodelGentzen.lean
-rw-rw-r-- 1 jlc jlc 227 Mar 2 14:56 lakefile.lean
-rw-rw-r-- 1 jlc jlc 76 Mar 2 14:56 Main.lean
-rw-rw-r-- 1 jlc jlc 20 Mar 2 14:56 Translations.lean
λ >

Adam Topaz (Mar 03 2023 at 00:10):

Did you install the lean4 vscode extension?

Adam Topaz (Mar 03 2023 at 00:10):

In any case, you should open the project folder itself in vscode, not individual files

Arthur Paulino (Mar 03 2023 at 00:10):

You're missing a lean-toolchain file. Example: https://github.com/leanprover-community/mathlib4/blob/master/lean-toolchain

James Caldwell (Mar 03 2023 at 00:11):

Yes - when I open the file GodelGentzen.lean .... that's when it fails to start lean.

James Caldwell (Mar 03 2023 at 00:12):

OK - what do I need to do to get it?

Adam Topaz (Mar 03 2023 at 00:13):

Will lake init do it? I'm not sure. The usual way to start new projects is lake new, and that will add all the necessary files. I don't know how youb obtained this folder without a toolchain file.

James Caldwell (Mar 03 2023 at 00:14):

I sucessfully ran "lake int translations" earlier ... when I try to run it again I'm told I already ran it.

James Caldwell (Mar 03 2023 at 00:15):

I created the folder and copied the file GodelGentzen.lean into it.

Arthur Paulino (Mar 03 2023 at 00:16):

I think you ran with an old toolchain. Try deleting your current folder, run elan default leanprover/lean4:nightly-2023-02-24 and then run the lake init command again

Arthur Paulino (Mar 03 2023 at 00:19):

Actually, run lake new instead of lake init

Arthur Paulino (Mar 03 2023 at 00:19):

lake new SomeProjectName

James Caldwell (Mar 03 2023 at 00:19):

I just hit CR on the lake init ... should I do lake new?

Arthur Paulino (Mar 03 2023 at 00:20):

Hmm, if your folder is not a mess at this point you should be fine

James Caldwell (Mar 03 2023 at 00:20):

Also, should I be in the folder when I run it ... or one level up?

Arthur Paulino (Mar 03 2023 at 00:21):

lake init turns your current folder into a Lake project. lake new creates a new folder

Arthur Paulino (Mar 03 2023 at 00:22):

But if you ran lake init then you should be ready to kickoff VS Code with code .

James Caldwell (Mar 03 2023 at 00:23):

OK - I want it to be a level down so I ran "lake new tranbslations". I'm going down into translations and starting vscode.

James Caldwell (Mar 03 2023 at 00:24):

It works! Thank you so much.


Last updated: Dec 20 2023 at 11:08 UTC