Mojo-SDK详细安装教程

Mojo-SDK安装

Mojo-SDK详细安装教程_第1张图片

运行环境:windows11+wsl2(ubuntu1804)
截至20230909,windows,mac系统暂时不支持

step1:

Install VS Code, the WSL extension, and the Mojo extension.

step2:

Install Ubuntu 22.04 for WSL and open it.

step3:

In the Ubuntu terminal, install the Modular CLI:
The script requires root or sudo privileges to run.

curl https://get.modular.com | \
  MODULAR_AUTH=mut_b2c22398bcc949a6a803dfe01d09fc06 \
  sh -

可能会出现报错:

modular: error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory

解决(这里优点乱,试了好几种方法,后面莫名其妙,运行这个命令就没报错了):

sudo apt install libevent-dev ncurses-dev build-essential bison pkg-config

继续执行上面脚本,出现如下 not found报错

Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
modular: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by modular)
modular: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by modular)
modular: /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by modular)

继续解决上述报错:
检查版本:

(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ strings /lib/x86_64-linux-gnu/libc.so.6 |grep GLIBC_
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_2.18
GLIBC_2.22
GLIBC_2.23
GLIBC_2.24
GLIBC_2.25
GLIBC_2.26
GLIBC_2.27
GLIBC_PRIVATE

解决方案:添加一个高级版本系统的源,直接升级libc6.
编辑源:

sudo vi /etc/apt/sources.list

添加高版本的源

deb http://th.archive.ubuntu.com/ubuntu jammy main    #添加该行到文件

运行升级

sudo apt update
sudo apt install libc6

再次检查版本

(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ strings /lib/x86_64-linux-gnu/libc.so.6 |grep GLIBC_
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_2.13
GLIBC_2.14
GLIBC_2.15
GLIBC_2.16
GLIBC_2.17
GLIBC_2.18
GLIBC_2.22
GLIBC_2.23
GLIBC_2.24
GLIBC_2.25
GLIBC_2.26
GLIBC_2.27
GLIBC_2.28
GLIBC_2.29
GLIBC_2.30
GLIBC_2.31
GLIBC_2.32
GLIBC_2.33
GLIBC_2.34
GLIBC_2.35
GLIBC_PRIVATE

再次运行step3脚本,没有再报错
Mojo-SDK详细安装教程_第2张图片

step4:

Install the Mojo SDK:

modular install mojo

报错:

Testing `MODULAR_HOME=/home/dongyongfei786/.modular`
* `/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/bin/mojo`...
TEST: `mojo --help`... ERROR
Traceback (most recent call last):
  File "/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/scripts/post-install/self-test.py", line 342, in <module>
    main()
  File "/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/scripts/post-install/self-test.py", line 338, in main
    tester.test(args.test_jupyter)
  File "/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/scripts/post-install/self-test.py", line 269, in test
    self.test_mojo_help()
  File "/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/scripts/post-install/self-test.py", line 94, in test_mojo_help
    assert "mojo" in self.run_mojo("--help")[0]
AssertionError
modular: error: failed to run python:

但是能正常查看版本,安装成功了吗?应该是bug

(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ modular --version
modular 0.1.4 (6b54d308)

貌似没报错了

(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ mojo  # 这里应该还是有点问题的,没有进入类似python的窗口
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ mojo --version
mojo 0.2.1 (64d14e85)
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$

step5.

Open the Ubuntu workspace in VS Code with this:

code .
Step6

Get started with Hello World!
https://docs.modular.com/mojo/manual/get-started/hello-world.html
貌似没报错了,可下载example:https://github.com/modularml/mojo/tree/main/examples

(torch) dongyongfei786@DESKTOP-3QNKDLL:/mnt/g/dongyongfei786/mojo-tutorials/mojo/examples$ mojo hello.
Hello Mojo !
9
6
3
(torch) dongyongfei786@DESKTOP-3QNKDLL:/mnt/g/dongyongfei786/mojo-tutorials/mojo/examples$ ls
LICENSE    deviceinfo.mojo  hello     hello_interop.mojo  matmul.mojo  nbody.mojo  pymatmul.py  simple_interop.py
README.md  docker           hello.  mandelbrot.mojo     memset.mojo  notebooks   reduce.mojo
Hello from Python!
I can even print a numpy array:  [1 2 3]
(torch) dongyongfei786@DESKTOP-3QNKDLL:/mnt/g/dongyongfei786/mojo-tutorials/mojo/examples$ mojo mandelbrot.mojo
Number of hardware cores: 12
Vectorized: 23.953908999999999 ms
Parallelized: 3.572031 ms
Parallel speedup: 6.7059633581007558
(torch) dongyongfei786@DESKTOP-3QNKDLL:/mnt/g/dongyongfei786/mojo-tutorials/mojo/examples$

你可能感兴趣的:(mojo)