Files
docs/开发文档/python/mojo教程.md
2026-01-14 11:27:47 +08:00

58 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 安装Mojo
打开终端并安装modular命令行工具
```sh
curl -s https://get.modular.com | sh -
```
然后使用以下命令登录到您的Modular帐户
```sh
modular auth
```
现在您可以安装Mojo SDK
```sh
modular install mojo
```
设置环境变量以便访问mojo命令行界面如果您使用的是Bash请运行以下命令
```sh
MOJO_PATH=$(modular config mojo.path) \
&& BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \
&& echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \
&& echo 'export PATH="'$MOJO_PATH'/bin:$PATH"' >> "$BASHRC" \
&& source "$BASHRC"
```
安装 MAX SDK
```
modular install max
```
安装 [MAX 引擎 Python](https://docs.modular.com/engine/reference/python/engine) 包:
```
MAX_PATH=$(modular config max.path) \ && python3 -m pip install --find-links $MAX_PATH/wheels max-engine
```
设置环境变量,以便您可以访问 [`max`](https://docs.modular.com/engine/reference/cli/) 和 [`mojo`](https://docs.modular.com/mojo/cli/) CLI
```
MAX_PATH=$(modular config max.path) \
&& BASHRC=$( [ -f "$HOME/.bash_profile" ] && echo "$HOME/.bash_profile" || echo "$HOME/.bashrc" ) \
&& echo 'export MODULAR_HOME="'$HOME'/.modular"' >> "$BASHRC" \
&& echo 'export PATH="'$MAX_PATH'/bin:$PATH"' >> "$BASHRC" \
&& source "$BASHRC"
```
要检查您当前的Mojo版本请使用`--version`选项:
```sh
mojo --version
```
要升级到最新的Mojo版本请使用`modular update`命令:
```sh
modular update mojo
```
### 更新Modular CLI[](https://mojocn.org/mojo/manual/getstarted/getmojo.html#%E6%9B%B4%E6%96%B0modular-cli)
运行以下命令在您的系统上更新CLI。
```sh
sudo apt update
sudo apt install modular
```