# Conda env + Install jupyter

**<mark>For Backup</mark>**

---

编辑 /etc/apt/sources.list 文件

```plaintext
deb https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main non-free contrib
deb-src https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main non-free contrib
```

更改完 sources.list 文件后，运行 sudo apt update 更新索引以生效

当前 python 版本

```plaintext
# python -V
Python 3.11.9
```

当前 pip 版本

```plaintext
# pip -V   
pip 24.1.1 from /usr/lib/python3/dist-packages/pip (python 3.11)
```

下载最新 miniconda 脚本

```plaintext
$ wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py312_24.9.2-0-Linux-x86_64.sh

$ file Miniconda3-py312_24.9.2-0-Linux-x86_64.sh 
Miniconda3-py312_24.9.2-0-Linux-x86_64.sh: POSIX shell script, ASCII text executable, with very long lines (2754)
```

以 root 身份安装

```plaintext
# sh Miniconda3-py312_24.9.2-0-Linux-x86_64.sh 
Welcome to Miniconda3 py312_24.9.2-0
In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>> 
ANACONDA TERMS OF SERVICE
...
Do you accept the license terms? [yes|no]
>>> yes
Miniconda3 will now be installed into this location:
/root/miniconda3
  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below
[/root/miniconda3] >>> 
...
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes
...
==> For changes to take effect, close and re-open your current shell. <==
Thank you for installing Miniconda3!
```

按照提示，得退出再重开 shell 才能生效

```plaintext
(base) # python -V
Python 3.12.7

# conda -V                                
conda 24.9.2
```

安装 3.9 版本的 python

```plaintext
# conda create --name python309 python=3.9
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
...
The following NEW packages will be INSTALLED:
...
Proceed ([y]/n)? y
Downloading and Extracting Packages:                                                                                                                               
Preparing transaction: done                                                                                                                      
Verifying transaction: done                                                                                                                      
Executing transaction: done  
```

安装 3.13 版本的 python

```plaintext
# conda create --name python313 python=3.13
Channels:
 - defaults
Platform: linux-64
Collecting package metadata (repodata.json): done
Solving environment: done
...
The following NEW packages will be INSTALLED:
...
Proceed ([y]/n)? y
Downloading and Extracting Packages:                                                                                                                                         
Preparing transaction: done                                                                                                                      
Verifying transaction: done                                                                                                                      
Executing transaction: done         
```

激活 3.9 版本的 python

```plaintext
(base) # conda activate python309                                                                                                                        
(python309) # python -V
Python 3.9.20
```

激活 3.13 版本的 python

```plaintext
(python309) # conda activate python313                                                                                                                                                
(python313) # python -V               
Python 3.13.0
```

回到基础版本的 python

```plaintext
(python313) # conda deactivate                                                                                                                                                   
(python309) # conda deactivate                                                                                                                             
(base) # python -V               
Python 3.12.7
```

切换到 3.9 版本的 python 并更换pip源设置，使用清华源，安装 pyecharts

```plaintext
(python309) # pip install pyecharts -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
(python309) # pip list                                                                      
Package      Version
------------ -------
Jinja2       3.1.4
MarkupSafe   3.0.2
pip          24.2
prettytable  3.12.0
pyecharts    2.0.7
setuptools   75.1.0
simplejson   3.19.3
some-package 0.1
wcwidth      0.2.13
wheel        0.44.0
```

安装 jupyter

```plaintext
(python309) # apt-get install jupyter
```

运行 jupyter notebook

```plaintext
# jupyter notebook
Running as root is not recommended. Use --allow-root to bypass.
```

按照提示添加 --allow-root 参数

```plaintext
# jupyter notebook --allow-root
Jupyter Notebook 6.4.13 is running at:
```

浏览器成功打开
