Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mojo: Quickstart - Setup on MacOS(M1) #413

Open
hhstore opened this issue Oct 19, 2023 · 7 comments
Open

Mojo: Quickstart - Setup on MacOS(M1) #413

hhstore opened this issue Oct 19, 2023 · 7 comments
Labels
MacOS Mojo Python python 3.5+ (3.6, 3.7) vscode Visual Studio Code

Comments

@hhstore
Copy link
Owner

hhstore commented Oct 19, 2023

📖 Abstract:

  • ✅ M1 Mac 安装 Mojo 避坑指南 & 教程。

💯 Related:

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

M1 Mac 安装 mojo 教程

适用范围:

开荒 & 吃螃蟹态度:

  • 对 mojo 官方,多一点包容。
  • 下载 & 安装失败, 有些是·墙国·独有的问题。(少抱怨,想办法解决)
  • 开荒阶段,一切都是不完善的(各种坑),没耐心,还是别尝鲜,等 1.0 发布(当前是 0.4)。

踩坑说明:

macos 版本问题:

  • ✅ 亲测 macOS 12.4 正常。
  • ❌ 有群友反映 macOS 14 安装失败。

python 🐍 版本问题:

  • ✅ 这是原生安装(非虚拟机/docker).
  • ✅ 如果 Mac 基于 pyenv 管理多个 Python 版本,需要确保 global Python 版本 >= 3.10.x (3.9 会报错,早先 3.11 也会报错)
    • 如果你不知道 pyenv 是什么,不用管,你不会遇到此问题。
    • mojo 安装脚本,会自动安装依赖的 Python 版本。
  • ❌ 发现 rye 会污染 pyenv 的 Python path(which python), 需卸载 rye.
# 卸载 rye:
rye self uninstall

# 设置全局 Python 版本:
 pyenv versions
  system
  3.9.13
  3.9.13
  3.10.5
* 3.10.6 (set by /Users/dev/.pyenv/version)


# 正常状态:
 which python
/Users/dev/.pyenv/shims/python

网络🪜问题:

  • 💩 fuck GFW。
  • ✅ 如果使用 clash pro 等工具,建议开全局模式+增强模式,同时代理不要走 HK🇭🇰(阻断严重),会导致下载 modular失败。
  • ✅ 推荐走美国🇺🇸(贼快)和日本🇯🇵(一般快)节点。
  • ✅ 走美国🇺🇸 节点,下载+安装 mojo,可以 1~2 分钟内搞定。(实测 20~30M/s 下载速度)
  • ✅ 走日本🇯🇵 节点,大概 2~3 分钟。(实测 1~5M/s 下载速度)

下载速度:

  • 通过分析, modular/mojo 官方下载资源,存在 aws s3 上。
  • s3 是不限速的,·千兆网· + 美国🇺🇸🪜 实测, 最高下载速度到 35M/s。(Mojo 官方理解不了下载失败)
  • 如果你没有下载速度,不怪 Mojo 和 aws。

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

M1 Mac 安装流程:

  • 💡 解决 Python 版本(3.10) 问题 和 梯子🪜(推荐走美国🇺🇸节点),基本可以正常安装 mojo。

安装 modular:

# 安装 modular:
curl https://get.modular.com | \
  MODULAR_AUTH=mut_a27b34525bed433bb61ea88654a814bb \
  sh -

# 查看 modular 安装成功:
 modular -v
modular 0.2.1 (5144fffe)

安装 mojo:

  • 此处 mojo 下载过程容易失败,不要使用 HK 🇭🇰 代理,阻断严重。(推荐美国🇺🇸,日本🇯🇵)
  • 如果失败,反复尝试几次。
# auth:
modular auth mut_a27b34525bed433bb61ea88654a814bb

# 一键安装命令, 如果失败, 重试几次:
modular clean && modular auth mut_a27b34525bed433bb61ea88654a814bb &&
modular install mojo
  • 安装截图:
image image

添加环境变量:

  • fish: 添加到 ~/.config/fish/conf.d/env.fish 文件
# for mojo:
set -gx MODULAR_HOME "$HOME/.modular"
set -gx PATH "$PATH:$MODULAR_HOME/pkg/packages.modular.com_mojo/bin"
  • zsh:
echo 'export MODULAR_HOME="/Users/dev/.modular"' >> ~/.zshrc
echo 'export PATH="/Users/dev/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.zshrc

# 激活:
source ~/.zshrc
  • bash:
echo 'export MODULAR_HOME="/Users/dev/.modular"' >> ~/.bashrc
echo 'export PATH="/Users/dev/.modular/pkg/packages.modular.com_mojo/bin:$PATH"' >> ~/.bashrc

# 激活:
source ~/.bashrc

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

Vscode 配置 Mojo 开发环境:

安装 vscode 插件:

  • mojo 插件
  • Dev Containers: 其实此处不需要(Intel Mac 需要),不过建议掌握此插件用法,搭配 docker 容器/虚拟机,非常非常好用。

mojo 插件设置环境变量:

  • ✅ mojo 插件,需要设置一下环境变量。(同系统环境变量)
  • ✅ 根据提示设置。设置成功后,导入 mojo 模块,vscode 会有代码提示 + 补全 + API doc
  • ✅ 如果系统的环境变量不生效,就手动设置一下。(我用 fish,似乎当前并不可用,手动配)

配置完成效果:

  • ✅ vscode + mojo 插件, 已经支持补全 和 函数 docs 索引。也支持·代码格式化·。
  • ✅ 暂时不能跳转到标准库代码,(暂未开源, 可以理解)后续应该会逐步支持。
  • ✅ 运行示例:
image
  • ✅ 综上,vscode + mojo 插件,目前已经可以正常开发,体验已经比较丝滑。
  • ✅ mojo 可以写起来了。

欢迎关注如下几个 repos/orgs:

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

1

3 similar comments
@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

1

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

1

@hhstore
Copy link
Owner Author

hhstore commented Oct 19, 2023

1

@hhstore hhstore added Python python 3.5+ (3.6, 3.7) MacOS vscode Visual Studio Code Mojo labels Oct 19, 2023
@hhstore hhstore changed the title Mojo: Quickstart - Setup on MacOS(M1) with Orbstack Mojo: Quickstart - Setup on MacOS(M1) Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MacOS Mojo Python python 3.5+ (3.6, 3.7) vscode Visual Studio Code
Projects
None yet
Development

No branches or pull requests

1 participant