Mojo-SDK详细安装教程

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$
相关推荐
bbqz0074 个月前
逆向WeChat(六)
c++·微信·小程序·逆向·mojo·嗅探·抓包https·devtool·sniff
ecoolper4 个月前
【maven插件】org.codehaus.mojo:build-helper-maven-plugin:timestamp-property
java·maven·mojo
bbqz0074 个月前
逆向WeChat (五)
c++·微信·逆向·mojo·ipc·wechat·mmmojo
启航学途4 个月前
Mojo 实现排序功能
mojo·mojo 实现排序功能·mojo入门·mojo基础·mojo教程·mojo sort排序·mojo 排序api
2401_857439695 个月前
分布式智能:Mojo模型在分布式系统中的动态使用策略
分布式·mojo
2401_857600955 个月前
Mojo模型与A/B测试:数据驱动决策的科学
mojo
2401_857026235 个月前
批量预测的加速器:Mojo模型的批处理预测能力
mojo
2401_857439695 个月前
压缩Mojo模型:轻装上阵的机器学习模型
人工智能·机器学习·mojo
代码之光_19805 个月前
云端智能:在云环境中部署Mojo模型的全面指南
mojo
杨哥带你写代码5 个月前
深度学习优化:Mojo模型中自定义特征的稀疏表示处理
人工智能·深度学习·mojo