Mojo-SDK安装
运行环境:windows11+wsl2(ubuntu1804)
官方推荐:wsl2(ubuntu2204),我下面是wsl2(ubuntu1804),发现有些问题,不知道是不是ubuntu版本问题,如果报错可参考如下命令行升级:
bash
# 确保版本可升级,需要Prompt=lts
sudo nano /etc/update-manager/release-upgrades
# 使用CTRL+S保存,然后CTRL+X退出nano。
# 升级系统组件并检查软件更新
sudo apt update
# 更新软件
sudo apt upgrade -y
# 更新发行版
sudo do-release-upgrade
截至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.
bash
curl https://get.modular.com | \
MODULAR_AUTH=mut_b2c22398bcc949a6a803dfe01d09fc06 \
sh -
可能会出现报错:
bash
modular: error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory
解决(这里优点乱,试了好几种方法,后面莫名其妙,运行这个命令就没报错了):
bash
sudo apt install libevent-dev ncurses-dev build-essential bison pkg-config
继续执行上面脚本,出现如下 not found报错
bash
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)
继续解决上述报错:
检查版本:
bash
(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.
编辑源:
bash
sudo vi /etc/apt/sources.list
添加高版本的源
bash
deb http://th.archive.ubuntu.com/ubuntu jammy main #添加该行到文件
运行升级
bash
sudo apt update
sudo apt install libc6
再次检查版本
bash
(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脚本,没有再报错
step4:
Install the Mojo SDK:
bash
modular install mojo
报错:
bash
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
bash
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ modular --version
modular 0.1.4 (6b54d308)
貌似没报错了
bash
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ mojo # 这里应该还是有点问题的,没有进入类似python的窗口
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ mojo --version
mojo 0.2.1 (64d14e85)
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$
补充:20230910
重新执行上面流程,莫名其妙安装成功(可能是升级sudo apt update,升级了一些依赖性)
bash
🔥 Mojo installed! 🔥
Now run the following commands if you are using bash:
echo 'export MODULAR_HOME="/home/dongyongfei786/.modular"' >> ~/.bashrc
echo 'export PATH="/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
If you are using ZSH, run the following commands:
echo 'export MODULAR_HOME="/home/dongyongfei786/.modular"' >> ~/.zshrc
echo 'export PATH="/home/dongyongfei786/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
Then enter 'mojo' to start the Mojo REPL.
For tool help, enter 'mojo --help'.
For more docs, see https://docs.modular.com/mojo.
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ MOmojo
MOmojo: command not found
(torch) dongyongfei786@DESKTOP-3QNKDLL:~$ mojo
Welcome to Mojo! 🔥
Expressions are delimited by a blank line.
Type `:mojo help` for further assistance.
1>
截个图记录一下:
step5.
Open the Ubuntu workspace in VS Code with this:
bash
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
bash
(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$