new-modular-project

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
When the user wants to create a new project, first infer as many options as possible from the user's request (e.g., "new Mojo project" means type=Mojo, "called foo" means name=foo). Then use a structured multiple-choice prompt (not plain text) to gather only the remaining unspecified options in a single interaction. Do NOT ask about options the user has already provided or implied. The options to determine are:
  1. Project name — ask if not specified
  2. Type of project — Mojo or MAX (infer from context if the user said "Mojo project" or "MAX project")
  3. Environment manager — Pixi (recommended) or uv
  4. If uv: UV project type — full uv project (
    uv init
    +
    uv add
    , recommended) or quick uv environment (
    uv venv
    +
    uv pip install
    , lighter weight)
  5. Channel — nightly (latest features, recommended) or stable (production)
Then follow the appropriate section below (Pixi or uv) to initialize the project and choose
max
or
mojo
as appropriate. For stable versions in the below examples,
mojo
will start with a 0. prefix (0.26.1.0.0.0) where
max
packages will not (26.1.0.0.0).
NOTE: Do not look for or use
magic
for Mojo or MAX projects, it is no longer supported. Pixi has fully replaced its capabilities.

当用户想要创建新项目时,首先从用户的请求中推断出尽可能多的选项(例如,“new Mojo project”表示项目类型为Mojo,“名为foo”表示项目名称为foo)。然后使用结构化的选择题提示(而非纯文本),在一次交互中仅收集剩余未指定的选项。不要询问用户已经提供或隐含的选项。需要确定的选项包括:
  1. 项目名称——若未指定则询问
  2. 项目类型——Mojo或MAX(如果用户提到“Mojo project”或“MAX project”,可从上下文推断)
  3. 环境管理器——Pixi(推荐)或uv
  4. 若选择uvUV项目类型——完整uv项目(
    uv init
    +
    uv add
    ,推荐)或快速uv环境(
    uv venv
    +
    uv pip install
    ,更轻量化)
  5. 渠道——nightly(最新功能,推荐)或stable(生产环境)
随后根据选择的环境(Pixi或uv),按照下方对应的章节初始化项目,并选择合适的
max
mojo
。在以下示例的稳定版本中,
mojo
版本号将以0.开头(如0.26.1.0.0.0),而
max
包的版本号则不会(如26.1.0.0.0)。
注意:请勿为Mojo或MAX项目寻找或使用
magic
,该工具已不再受支持。Pixi已完全替代了它的功能。

Pixi (Recommended)

Pixi(推荐)

Pixi manages Python, Mojo, and other dependencies in a reproducible manner inside a controlled environment.
First, determine if
pixi
is installed. If it is not available for use at the command line, install it using the latest instructions found on https://pixi.prefix.dev/latest/#installation
You may need to place the
pixi
tool in the local shell environment after installation if it had not already been installed.
Pixi在受控环境中以可复现的方式管理Python、Mojo及其他依赖项。
首先,确认
pixi
是否已安装。若命令行中无法使用
pixi
,请访问https://pixi.prefix.dev/latest/#installation,按照最新说明进行安装。
安装完成后,若
pixi
未自动加入本地Shell环境,你可能需要手动配置。

Nightly

Nightly版本

bash
undefined
bash
undefined

New project

新项目

pixi init [PROJECT]
-c https://conda.modular.com/max-nightly/ -c conda-forge
&& cd [PROJECT] pixi add [max / mojo] pixi shell
pixi init [PROJECT]
-c https://conda.modular.com/max-nightly/ -c conda-forge
&& cd [PROJECT] pixi add [max / mojo] pixi shell

Existing project - add to pixi.toml channels first:

现有项目 - 先在pixi.toml中添加渠道:

[workspace]

[workspace]

channels = ["https://conda.modular.com/max-nightly/", "conda-forge"]

channels = ["https://conda.modular.com/max-nightly/", "conda-forge"]

pixi add [max / mojo]
undefined
pixi add [max / mojo]
undefined

Stable (v26.1.0.0.0)

稳定版本(v26.1.0.0.0)

bash
undefined
bash
undefined

New project

新项目

pixi init [PROJECT]
-c https://conda.modular.com/max/ -c conda-forge
&& cd [PROJECT] pixi add "[max / mojo]==0.26.1.0.0.0" pixi shell
pixi init [PROJECT]
-c https://conda.modular.com/max/ -c conda-forge
&& cd [PROJECT] pixi add "[max / mojo]==0.26.1.0.0.0" pixi shell

Existing project

现有项目

pixi add "[max / mojo]==0.26.1.0.0.0"

---
pixi add "[max / mojo]==0.26.1.0.0.0"

---

uv

uv

uv is a fast and very popular package manager, familiar to developers coming from a Python background. It also works well with Mojo projects.
uv是一款快速且广受欢迎的包管理器,熟悉Python的开发者会对其感到亲切。它也能很好地适配Mojo项目。

Nightly (project)

Nightly版本(完整项目)

bash
uv init [PROJECT] && cd [PROJECT]
uv add [max / mojo] \
  --index https://whl.modular.com/nightly/simple/ \
  --prerelease allow
bash
uv init [PROJECT] && cd [PROJECT]
uv add [max / mojo] \
  --index https://whl.modular.com/nightly/simple/ \
  --prerelease allow

Stable (project)

稳定版本(完整项目)

bash
uv init [PROJECT] && cd [PROJECT]
uv add [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/
bash
uv init [PROJECT] && cd [PROJECT]
uv add [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/

Nightly (quick environment)

Nightly版本(快速环境)

bash
mkdir [PROJECT] && cd [PROJECT]
uv venv
uv pip install [max / mojo] \
  --index https://whl.modular.com/nightly/simple/ \
  --prerelease allow
bash
mkdir [PROJECT] && cd [PROJECT]
uv venv
uv pip install [max / mojo] \
  --index https://whl.modular.com/nightly/simple/ \
  --prerelease allow

Stable (quick environment)

稳定版本(快速环境)

bash
mkdir [PROJECT] && cd [PROJECT]
uv venv
uv pip install [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/
When using
uv
, you can use
max
or
mojo
directly by working within the project environment:
bash
 source .venv/bin/activate

bash
mkdir [PROJECT] && cd [PROJECT]
uv venv
uv pip install [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/
使用
uv
时,你可以通过进入项目环境直接使用
max
mojo
bash
 source .venv/bin/activate

pip

pip

Standard Python package manager.
标准Python包管理器。

Nightly

Nightly版本

bash
python3 -m venv .venv && source .venv/bin/activate
pip install --pre [max / mojo] \
  --index https://whl.modular.com/nightly/simple/
bash
python3 -m venv .venv && source .venv/bin/activate
pip install --pre [max / mojo] \
  --index https://whl.modular.com/nightly/simple/

Stable

稳定版本

bash
python3 -m venv .venv && source .venv/bin/activate
pip install [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/

bash
python3 -m venv .venv && source .venv/bin/activate
pip install [max / mojo] \
  --extra-index-url https://modular.gateway.scarf.sh/simple/

Conda

Conda

For conda/mamba users.
适用于conda/mamba用户。

Nightly

Nightly版本

bash
conda install -c conda-forge \
  -c https://conda.modular.com/max-nightly/ [max / mojo]
bash
conda install -c conda-forge \
  -c https://conda.modular.com/max-nightly/ [max / mojo]

Stable (v26.1.0.0.0)

稳定版本(v26.1.0.0.0)

bash
conda install -c conda-forge \
  -c https://conda.modular.com/max/ "[max / mojo]==0.26.1.0.0.0"

bash
conda install -c conda-forge \
  -c https://conda.modular.com/max/ "[max / mojo]==0.26.1.0.0.0"

Version Alignment with MAX

与MAX版本对齐

If using MAX with custom Mojo kernels, versions must match:
bash
undefined
若将MAX与自定义Mojo内核配合使用,版本必须保持一致:
bash
undefined

Check alignment

检查版本一致性

uv pip show mojo | grep Version # e.g., 0.26.2 pixi run mojo --version # Must match major.minor (e.g., 0.26.2)

Mismatched versions cause kernel compilation failures. Always use the same channel (stable or nightly) for both.

---
uv pip show mojo | grep Version # 示例:0.26.2 pixi run mojo --version # 必须与主版本.次版本匹配(示例:0.26.2)

版本不匹配会导致内核编译失败。请始终为两者使用相同的渠道(stable或nightly)。

---

References

参考资料