Mac 配置 Anaconda + Jupyter + Julia 环境

Mac 配置 Anaconda + Jupyter + Julia 环境

1. Anaconda 安装

1.1 Homebrew 安装

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

在这里插入图片描述

1.2 Anaconda 安装

brew install anaconda

在这里插入图片描述

2. 配置 Jupyter Lab

随着不同软件环境的安装,在每一个虚拟环境中都安装 Jupyter 十分麻烦,也不便于进行统一管理。其实我们可以搭建一个 Jupyter 的虚拟环境,专门用于管理所有的 Anaconda 虚拟环境。

这个过程可以分为以下三步:
在这里插入图片描述

2.1 搭建 Jupyter Lab 虚拟环境

conda create --name jupyter_env jupyterlab python=3.8

2.2 安装 nb_conda_kernels

管理多环境插件主要有两个,一个是 nb_conda, 另一个是 nb_conda_kernel 。区别是第一个可以直接管理其他环境,第二个需要在对应的虚拟环境中安装 kernel 。根据实际的使用情况,本文推荐使用第二个,因为第一个可能与某些虚拟环境发生冲突,如R环境。

nb_conda_kernels 是一个 Jupyter 的插件,可以管理多个Conda 环境下的 Jupyter 核心(kernels),整合多 Conda 环境中各種不同的虚拟环境。

nb_conda_kernels 必须安裝在 Jupyter(Jupyter Notebook 或 JupyterLab)所在的 Conda 环境中。

conda activate jupyter_env
conda install nb_conda_kernels

2.3 修改配置文件

将 Jupyter Lab 的内核管理器设为 nb_conda_kernels : c.ServerApp.kernel_spec_manager_class='nb_conda_kernels.manager.CondaKernelSpecManager'

jupyter lab --generate-config
vim .jupyter/jupyter_lab_config.py

在这里插入图片描述

2.4 安裝 Jupyter 核心(Kernels)

所有需要在 Jupyter 中通过 nb_conda_kernels 来使用的 Conda 环境,都需要安裝对应语言的 Jupyter 核心(kernels)。

  • 安装 Python 的 Jupyter 核心
conda activate <name_env>
conda install ipykernel
  • 安装 R 的 Jupyter 核心
conda activate <name_env>
conda install r-irkernel
R -e 'IRkernel::installspec()'
  • 安装 Stata 核心
conda activate <name_env>
conda install -c conda-forge stata_kernel
python -m stata_kernel.install

3. Julia 环境搭建

3.1 Mac Intel_x64 Julia 环境

conda activate <name_env>
julia
import Pkg
Pkg.add("IJulia")
Pkg.build("IJulia")
Pkg.rm("IJulia")

在这里插入图片描述

3.2 Mac arm Julia 环境搭建

  • Anaconda 搭建 Julia 出现的问题
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.

PackagesNotFoundError: The following packages are not available from current channels:

  - julia

Current channels:

  - https://conda.anaconda.org/conda-forge/osx-arm64
  - https://conda.anaconda.org/conda-forge/noarch
  - https://repo.anaconda.com/pkgs/main/osx-arm64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/r/osx-arm64
  - https://repo.anaconda.com/pkgs/r/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

在这里插入图片描述

  • 安装 juliaup
conda install -c conda-forge juliaup
  • 查看可用的 Julia 版本
juliaup list
 Channel                Version
---------------------------------------------------------------
 0                      0.7.0+0.x64.apple.darwin14
 0.7                    0.7.0+0.x64.apple.darwin14
 0.7.0                  0.7.0+0.x64.apple.darwin14
 0.7.0~x64              0.7.0+0.x64.apple.darwin14
 0.7~x64                0.7.0+0.x64.apple.darwin14
 0~x64                  0.7.0+0.x64.apple.darwin14
 1                      1.10.0+0.aarch64.apple.darwin14
 1.0                    1.0.5+0.x64.apple.darwin14
 1.0.0                  1.0.0+0.x64.apple.darwin14
 1.0.0~x64              1.0.0+0.x64.apple.darwin14
 1.0.1                  1.0.1+0.x64.apple.darwin14
 1.0.1~x64              1.0.1+0.x64.apple.darwin14
 1.0.2                  1.0.2+0.x64.apple.darwin14
 1.0.2~x64              1.0.2+0.x64.apple.darwin14
 1.0.3                  1.0.3+0.x64.apple.darwin14
 1.0.3~x64              1.0.3+0.x64.apple.darwin14
 1.0.4                  1.0.4+0.x64.apple.darwin14
 1.0.4~x64              1.0.4+0.x64.apple.darwin14
 1.0.5                  1.0.5+0.x64.apple.darwin14
 1.0.5~x64              1.0.5+0.x64.apple.darwin14
 1.0~x64                1.0.5+0.x64.apple.darwin14
 1.1                    1.1.1+0.x64.apple.darwin14
 1.1.0                  1.1.0+0.x64.apple.darwin14
 1.1.0~x64              1.1.0+0.x64.apple.darwin14
 1.1.1                  1.1.1+0.x64.apple.darwin14
 1.1.1~x64              1.1.1+0.x64.apple.darwin14
 1.1~x64                1.1.1+0.x64.apple.darwin14
 1.2                    1.2.0+0.x64.apple.darwin14
 1.2.0                  1.2.0+0.x64.apple.darwin14
 1.2.0~x64              1.2.0+0.x64.apple.darwin14
 1.2~x64                1.2.0+0.x64.apple.darwin14
 1.3                    1.3.1+0.x64.apple.darwin14
 1.3.0                  1.3.0+0.x64.apple.darwin14
 1.3.0~x64              1.3.0+0.x64.apple.darwin14
 1.3.1                  1.3.1+0.x64.apple.darwin14
 1.3.1~x64              1.3.1+0.x64.apple.darwin14
 1.3~x64                1.3.1+0.x64.apple.darwin14
 1.4                    1.4.2+0.x64.apple.darwin14
 1.4.1                  1.4.1+0.x64.apple.darwin14
 1.4.1~x64              1.4.1+0.x64.apple.darwin14
 1.4.2                  1.4.2+0.x64.apple.darwin14
 1.4.2~x64              1.4.2+0.x64.apple.darwin14
 1.4~x64                1.4.2+0.x64.apple.darwin14
 1.5                    1.5.4+0.x64.apple.darwin14
 1.5.0                  1.5.0+0.x64.apple.darwin14
 1.5.0-beta1            1.5.0-beta1+0.x64.apple.darwin14
 1.5.0-beta1~x64        1.5.0-beta1+0.x64.apple.darwin14
 1.5.0-rc2              1.5.0-rc2+0.x64.apple.darwin14
 1.5.0-rc2~x64          1.5.0-rc2+0.x64.apple.darwin14
 1.5.0~x64              1.5.0+0.x64.apple.darwin14
 1.5.1                  1.5.1+0.x64.apple.darwin14
 1.5.1~x64              1.5.1+0.x64.apple.darwin14
 1.5.2                  1.5.2+0.x64.apple.darwin14
 1.5.2~x64              1.5.2+0.x64.apple.darwin14
 1.5.3                  1.5.3+0.x64.apple.darwin14
 1.5.3~x64              1.5.3+0.x64.apple.darwin14
 1.5.4                  1.5.4+0.x64.apple.darwin14
 1.5.4~x64              1.5.4+0.x64.apple.darwin14
 1.5~x64                1.5.4+0.x64.apple.darwin14
 1.6                    1.6.7+0.x64.apple.darwin14
 1.6.0                  1.6.0+0.x64.apple.darwin14
 1.6.0-beta1            1.6.0-beta1+0.x64.apple.darwin14
 1.6.0-beta1~x64        1.6.0-beta1+0.x64.apple.darwin14
 1.6.0-rc1              1.6.0-rc1+0.x64.apple.darwin14
 1.6.0-rc1~x64          1.6.0-rc1+0.x64.apple.darwin14
 1.6.0-rc2              1.6.0-rc2+0.x64.apple.darwin14
 1.6.0-rc2~x64          1.6.0-rc2+0.x64.apple.darwin14
 1.6.0-rc3              1.6.0-rc3+0.x64.apple.darwin14
 1.6.0-rc3~x64          1.6.0-rc3+0.x64.apple.darwin14
 1.6.0~x64              1.6.0+0.x64.apple.darwin14
 1.6.1                  1.6.1+0.x64.apple.darwin14
 1.6.1~x64              1.6.1+0.x64.apple.darwin14
 1.6.2                  1.6.2+0.x64.apple.darwin14
 1.6.2~x64              1.6.2+0.x64.apple.darwin14
 1.6.3                  1.6.3+0.x64.apple.darwin14
 1.6.3~x64              1.6.3+0.x64.apple.darwin14
 1.6.4                  1.6.4+0.x64.apple.darwin14
 1.6.4~x64              1.6.4+0.x64.apple.darwin14
 1.6.5                  1.6.5+0.x64.apple.darwin14
 1.6.5~x64              1.6.5+0.x64.apple.darwin14
 1.6.6                  1.6.6+0.x64.apple.darwin14
 1.6.6~x64              1.6.6+0.x64.apple.darwin14
 1.6.7                  1.6.7+0.x64.apple.darwin14
 1.6.7~x64              1.6.7+0.x64.apple.darwin14
 1.6~x64                1.6.7+0.x64.apple.darwin14
 1.7                    1.7.3+0.x64.apple.darwin14
 1.7.0                  1.7.0+0.aarch64.apple.darwin14
 1.7.0-beta1            1.7.0-beta1+0.x64.apple.darwin14
 1.7.0-beta1~x64        1.7.0-beta1+0.x64.apple.darwin14
 1.7.0-beta2            1.7.0-beta2+0.x64.apple.darwin14
 1.7.0-beta2~x64        1.7.0-beta2+0.x64.apple.darwin14
 1.7.0-beta3            1.7.0-beta3+0.aarch64.apple.darwin14
 1.7.0-beta3~aarch64    1.7.0-beta3+0.aarch64.apple.darwin14
 1.7.0-beta3~x64        1.7.0-beta3+0.x64.apple.darwin14
 1.7.0-beta4            1.7.0-beta4+0.aarch64.apple.darwin14
 1.7.0-beta4~aarch64    1.7.0-beta4+0.aarch64.apple.darwin14
 1.7.0-beta4~x64        1.7.0-beta4+0.x64.apple.darwin14
 1.7.0-rc1              1.7.0-rc1+0.aarch64.apple.darwin14
 1.7.0-rc1~aarch64      1.7.0-rc1+0.aarch64.apple.darwin14
 1.7.0-rc1~x64          1.7.0-rc1+0.x64.apple.darwin14
 1.7.0-rc2              1.7.0-rc2+0.aarch64.apple.darwin14
 1.7.0-rc2~aarch64      1.7.0-rc2+0.aarch64.apple.darwin14
 1.7.0-rc2~x64          1.7.0-rc2+0.x64.apple.darwin14
 1.7.0-rc3              1.7.0-rc3+0.aarch64.apple.darwin14
 1.7.0-rc3~aarch64      1.7.0-rc3+0.aarch64.apple.darwin14
 1.7.0-rc3~x64          1.7.0-rc3+0.x64.apple.darwin14
 1.7.0~aarch64          1.7.0+0.aarch64.apple.darwin14
 1.7.0~x64              1.7.0+0.x64.apple.darwin14
 1.7.1                  1.7.1+0.aarch64.apple.darwin14
 1.7.1~aarch64          1.7.1+0.aarch64.apple.darwin14
 1.7.1~x64              1.7.1+0.x64.apple.darwin14
 1.7.2                  1.7.2+0.aarch64.apple.darwin14
 1.7.2~aarch64          1.7.2+0.aarch64.apple.darwin14
 1.7.2~x64              1.7.2+0.x64.apple.darwin14
 1.7.3                  1.7.3+0.x64.apple.darwin14
 1.7.3~x64              1.7.3+0.x64.apple.darwin14
 1.7~x64                1.7.3+0.x64.apple.darwin14
 1.8                    1.8.5+0.aarch64.apple.darwin14
 1.8.0                  1.8.0+0.aarch64.apple.darwin14
 1.8.0-beta1            1.8.0-beta1+0.aarch64.apple.darwin14
 1.8.0-beta1~aarch64    1.8.0-beta1+0.aarch64.apple.darwin14
 1.8.0-beta1~x64        1.8.0-beta1+0.x64.apple.darwin14
 1.8.0-beta2            1.8.0-beta2+0.x64.apple.darwin14
 1.8.0-beta2~x64        1.8.0-beta2+0.x64.apple.darwin14
 1.8.0-beta3            1.8.0-beta3+0.aarch64.apple.darwin14
 1.8.0-beta3~aarch64    1.8.0-beta3+0.aarch64.apple.darwin14
 1.8.0-beta3~x64        1.8.0-beta3+0.x64.apple.darwin14
 1.8.0-rc1              1.8.0-rc1+0.aarch64.apple.darwin14
 1.8.0-rc1~aarch64      1.8.0-rc1+0.aarch64.apple.darwin14
 1.8.0-rc1~x64          1.8.0-rc1+0.x64.apple.darwin14
 1.8.0-rc3              1.8.0-rc3+0.aarch64.apple.darwin14
 1.8.0-rc3~aarch64      1.8.0-rc3+0.aarch64.apple.darwin14
 1.8.0-rc3~x64          1.8.0-rc3+0.x64.apple.darwin14
 1.8.0-rc4              1.8.0-rc4+0.aarch64.apple.darwin14
 1.8.0-rc4~aarch64      1.8.0-rc4+0.aarch64.apple.darwin14
 1.8.0-rc4~x64          1.8.0-rc4+0.x64.apple.darwin14
 1.8.0~aarch64          1.8.0+0.aarch64.apple.darwin14
 1.8.0~x64              1.8.0+0.x64.apple.darwin14
 1.8.1                  1.8.1+0.aarch64.apple.darwin14
 1.8.1~aarch64          1.8.1+0.aarch64.apple.darwin14
 1.8.1~x64              1.8.1+0.x64.apple.darwin14
 1.8.2                  1.8.2+0.aarch64.apple.darwin14
 1.8.2~aarch64          1.8.2+0.aarch64.apple.darwin14
 1.8.2~x64              1.8.2+0.x64.apple.darwin14
 1.8.3                  1.8.3+0.aarch64.apple.darwin14
 1.8.3~aarch64          1.8.3+0.aarch64.apple.darwin14
 1.8.3~x64              1.8.3+0.x64.apple.darwin14
 1.8.4                  1.8.4+0.aarch64.apple.darwin14
 1.8.4~aarch64          1.8.4+0.aarch64.apple.darwin14
 1.8.4~x64              1.8.4+0.x64.apple.darwin14
 1.8.5                  1.8.5+0.aarch64.apple.darwin14
 1.8.5~aarch64          1.8.5+0.aarch64.apple.darwin14
 1.8.5~x64              1.8.5+0.x64.apple.darwin14
 1.8~aarch64            1.8.5+0.aarch64.apple.darwin14
 1.8~x64                1.8.5+0.x64.apple.darwin14
 1.9                    1.9.4+0.aarch64.apple.darwin14
 1.9.0                  1.9.0+0.aarch64.apple.darwin14
 1.9.0-alpha1           1.9.0-alpha1+0.aarch64.apple.darwin14
 1.9.0-alpha1~aarch64   1.9.0-alpha1+0.aarch64.apple.darwin14
 1.9.0-alpha1~x64       1.9.0-alpha1+0.x64.apple.darwin14
 1.9.0-beta2            1.9.0-beta2+0.aarch64.apple.darwin14
 1.9.0-beta2~aarch64    1.9.0-beta2+0.aarch64.apple.darwin14
 1.9.0-beta2~x64        1.9.0-beta2+0.x64.apple.darwin14
 1.9.0-beta3            1.9.0-beta3+0.aarch64.apple.darwin14
 1.9.0-beta3~aarch64    1.9.0-beta3+0.aarch64.apple.darwin14
 1.9.0-beta3~x64        1.9.0-beta3+0.x64.apple.darwin14
 1.9.0-beta4            1.9.0-beta4+0.aarch64.apple.darwin14
 1.9.0-beta4~aarch64    1.9.0-beta4+0.aarch64.apple.darwin14
 1.9.0-beta4~x64        1.9.0-beta4+0.x64.apple.darwin14
 1.9.0-rc1              1.9.0-rc1+0.aarch64.apple.darwin14
 1.9.0-rc1~aarch64      1.9.0-rc1+0.aarch64.apple.darwin14
 1.9.0-rc1~x64          1.9.0-rc1+0.x64.apple.darwin14
 1.9.0-rc2              1.9.0-rc2+0.aarch64.apple.darwin14
 1.9.0-rc2~aarch64      1.9.0-rc2+0.aarch64.apple.darwin14
 1.9.0-rc2~x64          1.9.0-rc2+0.x64.apple.darwin14
 1.9.0-rc3              1.9.0-rc3+0.aarch64.apple.darwin14
 1.9.0-rc3~aarch64      1.9.0-rc3+0.aarch64.apple.darwin14
 1.9.0-rc3~x64          1.9.0-rc3+0.x64.apple.darwin14
 1.9.0~aarch64          1.9.0+0.aarch64.apple.darwin14
 1.9.0~x64              1.9.0+0.x64.apple.darwin14
 1.9.1                  1.9.1+0.aarch64.apple.darwin14
 1.9.1~aarch64          1.9.1+0.aarch64.apple.darwin14
 1.9.1~x64              1.9.1+0.x64.apple.darwin14
 1.9.2                  1.9.2+0.aarch64.apple.darwin14
 1.9.2~aarch64          1.9.2+0.aarch64.apple.darwin14
 1.9.2~x64              1.9.2+0.x64.apple.darwin14
 1.9.3                  1.9.3+0.aarch64.apple.darwin14
 1.9.3~aarch64          1.9.3+0.aarch64.apple.darwin14
 1.9.3~x64              1.9.3+0.x64.apple.darwin14
 1.9.4                  1.9.4+0.aarch64.apple.darwin14
 1.9.4~aarch64          1.9.4+0.aarch64.apple.darwin14
 1.9.4~x64              1.9.4+0.x64.apple.darwin14
 1.9~aarch64            1.9.4+0.aarch64.apple.darwin14
 1.9~x64                1.9.4+0.x64.apple.darwin14
 1.10                   1.10.0+0.aarch64.apple.darwin14
 1.10.0                 1.10.0+0.aarch64.apple.darwin14
 1.10.0-alpha1          1.10.0-alpha1+0.aarch64.apple.darwin14
 1.10.0-alpha1~aarch64  1.10.0-alpha1+0.aarch64.apple.darwin14
 1.10.0-alpha1~x64      1.10.0-alpha1+0.x64.apple.darwin14
 1.10.0-beta1           1.10.0-beta1+0.aarch64.apple.darwin14
 1.10.0-beta1~aarch64   1.10.0-beta1+0.aarch64.apple.darwin14
 1.10.0-beta1~x64       1.10.0-beta1+0.x64.apple.darwin14
 1.10.0-beta2           1.10.0-beta2+0.aarch64.apple.darwin14
 1.10.0-beta2~aarch64   1.10.0-beta2+0.aarch64.apple.darwin14
 1.10.0-beta2~x64       1.10.0-beta2+0.x64.apple.darwin14
 1.10.0-beta3           1.10.0-beta3+0.aarch64.apple.darwin14
 1.10.0-beta3~aarch64   1.10.0-beta3+0.aarch64.apple.darwin14
 1.10.0-beta3~x64       1.10.0-beta3+0.x64.apple.darwin14
 1.10.0-rc1             1.10.0-rc1+0.aarch64.apple.darwin14
 1.10.0-rc1~aarch64     1.10.0-rc1+0.aarch64.apple.darwin14
 1.10.0-rc1~x64         1.10.0-rc1+0.x64.apple.darwin14
 1.10.0-rc2             1.10.0-rc2+0.aarch64.apple.darwin14
 1.10.0-rc2~aarch64     1.10.0-rc2+0.aarch64.apple.darwin14
 1.10.0-rc2~x64         1.10.0-rc2+0.x64.apple.darwin14
 1.10.0-rc3             1.10.0-rc3+0.aarch64.apple.darwin14
 1.10.0-rc3~aarch64     1.10.0-rc3+0.aarch64.apple.darwin14
 1.10.0-rc3~x64         1.10.0-rc3+0.x64.apple.darwin14
 1.10.0~aarch64         1.10.0+0.aarch64.apple.darwin14
 1.10.0~x64             1.10.0+0.x64.apple.darwin14
 1.10~aarch64           1.10.0+0.aarch64.apple.darwin14
 1.10~x64               1.10.0+0.x64.apple.darwin14
 1~aarch64              1.10.0+0.aarch64.apple.darwin14
 1~x64                  1.10.0+0.x64.apple.darwin14
 alpha                  1.10.0+0.aarch64.apple.darwin14
 alpha~aarch64          1.10.0+0.aarch64.apple.darwin14
 alpha~x64              1.10.0+0.x64.apple.darwin14
 beta                   1.10.0+0.aarch64.apple.darwin14
 beta~aarch64           1.10.0+0.aarch64.apple.darwin14
 beta~x64               1.10.0+0.x64.apple.darwin14
 lts                    1.6.7+0.x64.apple.darwin14
 lts~x64                1.6.7+0.x64.apple.darwin14
 rc                     1.10.0+0.aarch64.apple.darwin14
 rc~aarch64             1.10.0+0.aarch64.apple.darwin14
 rc~x64                 1.10.0+0.x64.apple.darwin14
 release                1.10.0+0.aarch64.apple.darwin14
 release~aarch64        1.10.0+0.aarch64.apple.darwin14
 release~x64            1.10.0+0.x64.apple.darwin14
  • 选择需要的 Julia 版本
juliaup add <version>
  • 本文使用最新的稳定版
juliaup add release
  • 将 Julia 设为系统默认调用
juliaup config channelsymlinks true 

在这里插入图片描述

  • 效果展示

在这里插入图片描述

在这里插入图片描述

3.3 其他

  • juliaup 基本使用方法

在这里插入图片描述

  • 核心御载

通过 conda 安装的核心可以通过 conda 进行卸载,而通过其他方式安装的核心卸载后,在 Jupyter 管理界面该核心可能依然存在,这时需要利用 Jupyter 的管理程序进行清除。

这种情况暂时只在 Stata 核心遇到,Julia核心本文并未验证,只是觉得可能会存在相应的问题。

jupyter kernelspec list
jupyter kernelspec remove <name_kernel>
  • 手动安装核心

当环境重新布属后,或者出现某些意外情况,jupyter lab 可能无法正常的与虚拟环境建立正常的连接或者无法检测到相应核心,此时需要手动安装相应的核心到 jupyter lab

python -m ipykernel install --user --name <name_env> --display-name "<kernel_name> (<name_env>)"

4. 初步测试

println("Hello, Julia")
2+3
3*7
Out[2] *3
2^big(1000)
@time factorial(BigInt(1000000));
length(string(factorial(BigInt(1000000)))) # 5 y medio millones  de dígitos...
3//4 + 2//7 #  racionales
(1+3//4im)*(3.2-4im) # complejos
pi

在这里插入图片描述

参考文献

  1. How to Add Julia to Jupyter Notebook
  2. JupyterLab 整合多 Conda 環境不同版本 Python、R 語言教學
  3. stata_kernel–Getting Started
  4. How to Best Use Julia with Jupyter
  5. install Julia in anaconda
  6. JuliaLang/juliaup
  7. 解决conda安装的虚拟环境 jupyter notebook 无法识别的问题
  8. Using R in a Jupyter Notebook
  9. installing R kernel to jupyter notebook in a different conda environment
  10. Conda environments not showing up in Jupyter Notebook
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值