M1 Mac打开Jupyter notebook

当我成功安装了Jupyter之后,发现无法通过

复制代码
jupyter notebook

开始工作。

最初的问题是

复制代码
zsh command not found

该问题是个路径问题,通过添加PATH环境变量就行了,设置环境变量时需要注意,zshrc和bash_profile中都可以设置,二者的区别是:每打开一个新的终端,zshrc就会被source(也就是设置的PATH被刷新一次),而bash_profile每次都需要手动source。为了安全起见,我的zshrc如下

vim ~/.zshrc

复制代码
alias python='python3'
source ~/.bash_profile

:wq退出保存

vim ~/.bash_profile

复制代码
export PATH="/usr/bin:$PATH"
export PATH="/Users/peisipand/Library/Python/3.8/bin:$PATH"

这样的操作过后,就不是command找不到的问题了,而是

NotADirectoryError: [Errno 20] Not a directory: 'xdg-settings'

貌似是一个很小众的问题,网上搜不到太多相关的解决方案。

这里有一个相关的回答,成功解决了我的问题。

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/webbrowser.py

找到该文件

复制代码
def register_standard_browsers():
    global _tryorder
    _tryorder = []

    if sys.platform == 'darwin':
        register("MacOSX", None, MacOSXOSAScript('default'))
        register("chrome", None, MacOSXOSAScript('chrome'))
        register("firefox", None, MacOSXOSAScript('firefox'))
        register("safari", None, MacOSXOSAScript('safari'))
        # OS X can use below Unix support (but we prefer using the OS X
        # specific stuff)

    if sys.platform[:3] == "win":
        # First try to use the default Windows browser
        register("windows-default", WindowsDefault)

        # Detect some common Windows browsers, fallback to IE
        iexplore = os.path.join(os.environ.get("PROGRAMFILES", "C:\\Program Files"),
                                "Internet Explorer\\IEXPLORE.EXE")
        for browser in ("firefox", "firebird", "seamonkey", "mozilla",
                        "netscape", "opera", iexplore):
            if shutil.which(browser):
                register(browser, None, BackgroundBrowser(browser))

将 if sys.platform[:3] == "win": 改成 elif sys.platform[:3] == "win": 就可以了。

相关推荐
Jackson@ML3 小时前
2026最新版Visual Studio安装使用指南
ide·c#·visual studio
chao_6666665 小时前
Claude Code for vscode 新手入门完整教程
ide·vscode·ai·编辑器·ai编程·claude
Satellite_H5 小时前
Keil + VSCode 优化开发体验
ide·vscode·编辑器
lingzhilab7 小时前
零知IDE—— ESP8266(ESP-12F)MESH 组网实现多设备智能家居控制系统(灯光 / 传感器 / 人体感应)
c++·ide·智能家居
2501_916007478 小时前
不越狱如何查看iOS 应用的详细信息及其文件目录结构
android·macos·ios·小程序·uni-app·cocoa·iphone
HAPPY酷9 小时前
Visual Studio 原生项目(.vcxproj) 和 CMake 项目对比
ide·visual studio
柠檬叶子C10 小时前
STM32CubeIDE 安装教程 | 2026最新STM32CubeIDE安装教程 | STM32CubeIDE保姆级安装教程
ide·stm32·嵌入式硬件
芒鸽10 小时前
macos上Rust 命令行工具鸿蒙化适配完全攻略
macos·rust·harmonyos
山有木兮啊10 小时前
VSCode Remote-SSH 连接Mac卡在初始化VSCode
vscode·macos·ssh
wy31362282110 小时前
android——Android Studio 路径迁移指南(释放 C 盘空间)
android·ide·android studio