0%

我一般选择在 base 环境中安装 jupyter lab

所以,在 base 环境中,需要安装 nb_conda_kernels,这个是一个与 Conda 集成的 Jupyter 插件,它允许你在 Jupyter 中使用 Conda 环境中的不同内核。

然后,创建一个新的环境,比如 py310,在这个环境里面需要安装 ipykernel

ipykernel 包是 Jupyter 的一个关键组件,它提供了 IPython 内核,允许 Jupyter 与 IPython 交互式计算环境进行通信。

在jupyter lab页面中刷新,就可以自由选择 python 环境了,如下图所示:

Anaconda 是一个用于科学计算的 Python 发行版,支持 Linux, Mac, Windows, 包含了众多流行的科学计算、数据分析的 Python 包。

Anaconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 下载。

TUNA 还提供了 Anaconda 仓库与第三方源(conda-forge、msys2、pytorch等,查看完整列表,更多第三方源可以前往校园网联合镜像站查看)的镜像,各系统都可以通过修改用户目录下的 .condarc 文件来使用 TUNA 镜像源。Windows 用户无法直接创建名为 .condarc 的文件,可先执行 conda config —set show_channel_urls yes 生成该文件之后再修改。

注:由于更新过快难以同步,他们不同步pytorch-nightly, pytorch-nightly-cpu, ignite-nightly这三个包。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

即可添加 Anaconda Python 免费仓库。

运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。

Miniconda 是一个 Anaconda 的轻量级替代,默认只包含了 python 和 conda,但是可以通过 pip 和 conda 来安装所需要的包。

Miniconda 安装包可以到 https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/ 下载。

我的操作系统是macOS Catalina 10.15.7
Python 3.8

通过源码安装Qlib,记录一下掉过的坑。

总的来说,按照官方说明文档,执行安装命令,一般不会有问题。

cython一定要更新,upgrade

pip要和python环境里面的版本一致,不确定是否一致,可以python -m pip install xxx的方式。

也可以通过pip show pip查看位置。

通过源码安装,pip install .,尽量不通过 pip install pyqlib来安装,更不能通过 python setup.py install来安装。

qlib安装在python=3.8下面,3.9目前支持不好。

创建python=3.8的虚拟环境后,想要在 jupyter lab 里面的 kernel select 中显示出来,需要在3.8的虚拟环境中执行命令:
pip install ipykernel

如果错误的添加了kernel,需要这样删除:jupyter kernelspec remove kernel_name

在python3.8的环境里面,要安装pip install ipywidgets,还有pip install tqdm

安装好了以后,运行qlib/examples/workflow_by_code.ipynb,在train model这里,有报错:

意思就是libomp这个库文件没有被加载到。

后来尝试了很多方法,按网上说的,都是brew install libomp

我的macOS版本太旧,brew都已经不支持了。要升级到macOS 12,但我的笔记本又不支持。

然后又找了各种办法通过源码来安装libomp。

又去搞了半天编译工具。

最后通过简单的两步搞定了问题。

1
2
3
4
5
6
7
8
9
$ pip uninstall lightgbm

Found existing installation: lightgbm 4.2.0
Uninstalling lightgbm-4.2.0:
Would remove:
/opt/anaconda3/envs/py38/lib/python3.8/site-packages/lightgbm-4.2.0.dist-info/*
/opt/anaconda3/envs/py38/lib/python3.8/site-packages/lightgbm/*
Proceed (Y/n)? y
Successfully uninstalled lightgbm-4.2.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$ conda install lightgbm
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

environment location: /opt/anaconda3/envs/py38

added / updated specs:
- lightgbm


The following packages will be downloaded:

package | build
---------------------------|-----------------
blas-1.0 | openblas 45 KB
libgfortran-5.0.0 |11_3_0_hecd8cb5_28 142 KB
libgfortran5-11.3.0 | h9dfd629_28 1.4 MB
libopenblas-0.3.21 | h54e7dc3_0 4.9 MB
lightgbm-4.1.0 | py38hcec6c5f_0 1.4 MB
llvm-openmp-14.0.6 | h0dcd299_0 288 KB
numpy-1.24.3 | py38h57a7bef_0 12 KB
numpy-base-1.24.3 | py38hc93c6d9_0 6.5 MB
pooch-1.7.0 | py38hecd8cb5_0 85 KB
scipy-1.10.1 | py38h9034365_1 20.9 MB
------------------------------------------------------------
Total: 35.8 MB

The following NEW packages will be INSTALLED:

blas pkgs/main/osx-64::blas-1.0-openblas
libgfortran pkgs/main/osx-64::libgfortran-5.0.0-11_3_0_hecd8cb5_28
libgfortran5 pkgs/main/osx-64::libgfortran5-11.3.0-h9dfd629_28
libopenblas pkgs/main/osx-64::libopenblas-0.3.21-h54e7dc3_0
lightgbm pkgs/main/osx-64::lightgbm-4.1.0-py38hcec6c5f_0
llvm-openmp pkgs/main/osx-64::llvm-openmp-14.0.6-h0dcd299_0
numpy pkgs/main/osx-64::numpy-1.24.3-py38h57a7bef_0
numpy-base pkgs/main/osx-64::numpy-base-1.24.3-py38hc93c6d9_0
pooch pkgs/main/osx-64::pooch-1.7.0-py38hecd8cb5_0
scipy pkgs/main/osx-64::scipy-1.10.1-py38h9034365_1


Proceed ([y]/n)? y

核心错误就出在我们之前都是通过pip来安装的,像这种有大量依赖的库,最好还是要通过conda install来安装。

最后qlib的work_flow在macOS下成功运行。