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": 就可以了。

相关推荐
程序员果子1 小时前
零拷贝:程序性能加速的终极奥秘
linux·运维·nginx·macos·缓存·centos
天庭鸡腿哥1 小时前
macOS的功能,在Windows上也能实现
windows·microsoft·macos·visual studio·everything
Byron Loong2 小时前
【Debug】vscode 调试python,如何配置固定调试文件
ide·vscode·python
weixin_462446232 小时前
macOS 安装 git-lfs
git·macos
HealthScience5 小时前
vscode通过跳板机连接到服务器
服务器·ide·vscode
猿小猴子6 小时前
主流 AI IDE 之一的 Kiro 介绍
ide·ai·kiro
神码小Z6 小时前
为什么架构师岗位即将消失?学会使用Cursor的三大神器Rules、Memories、Commands!小白也能写出专家级代码!
ide·intellij-idea
摘星编程7 小时前
从云游戏到Mac远程操控:UU远程游戏、办公场景全覆盖
游戏·macos·uu远程
4***99747 小时前
工业网关助力Altivar320与S7-1200协同运行
ide·python·算法·spring·eclipse·sqlite·tornado
海市公约16 小时前
HTML网页开发从入门到精通:从标签到表单的完整指南
前端·ide·vscode·程序人生·架构·前端框架·html