Kali安装Anaconda
城南花已开 Lv5

Kali安装Anaconda

前言

Anaconda是一个免费开源的软件包管理器和环境管理器,用于科学计算、数据分析和机器学习。它可以帮助用户在Python环境中快速安装、升级和管理各种软件包,还可以根据需要创建和管理多个Python环境。Anaconda提供了一个名为Conda的命令行工具,用户可以通过Conda来管理他们的软件包和环境。Anaconda还包含了一系列常用的数据科学库和工具,如NumPy、SciPy、Pandas、Jupyter Notebook等。因此,Anaconda被广泛用于数据科学、机器学习和科学计算领域。

环境配置

使用清华源下载anaconda最新版本的就行了

Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

可以使用wget或者curl或者直接浏览器下载,将sh软件包cp到/tmp目录下

1
❯ bash Anaconda3-2024.10-1-Linux-x86_64.sh ##这边我下的是24年十月版本

一路回车,yes,anaconda会自动将安装目录添加到PATH

这样你就可以在Shell中直接执行conda命令

1
2
3
4
5
6
7
8
source ~/anaconda3/bin/activate
❯ conda -V
conda 24.9.2
conda search "^python$" ##使用search会在conda源中搜索关于python的信息
❯ conda config --show channels ##显示conda源,默认官方源
channels:
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r

anaconda | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

可以在清华源中查看帮助,添加conda清华源

1
2
3
4
5
6
7
8
9
10
11
❯ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
❯ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
❯ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
❯ conda config --show channels
channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://repo.anaconda.com/pkgs/main
- https://repo.anaconda.com/pkgs/r
❯ conda config --remove channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ ##这是删除其中一个清华源

添加第三方源

1
❯ conda config --set custom_channels.auto https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

设置搜索时显示通道地址

1
❯ conda config --set show_channel_urls yes

或者直接修改vim ~/.condarc文件

尝试创建一个新的虚拟环境,python版本可以通过上面search查找

1
2
3
4
5
6
7
8
9
10
11
12
13
❯ conda create --name python2 python=2.7.18  ##我这边环境命名为python2,同时版本也是2.7.18
❯ conda env list ##也可以替换conda info --envs
# conda environments:
#
base * /home/ctf/anaconda3 #这是我当前环境
python2 /home/ctf/anaconda3/envs/python2
❯ python --version
Python 3.12.7 #版本为python3
❯ conda activate python2 ##使用conda切换环境
❯ python --version
Python 2.7.18 :: Anaconda, Inc. ##目前为2.7.18
❯ conda deactivate ##退出当前环境
❯ conda remove --name python2 --all ##删除指定环境

尝试在python2环境中安装opencv

先安装相同版本的pip

1
2
3
4
5
6
7
8
9
10
11
12
❯ python get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. ##这里的版本安全提示不用理
Collecting pip<21.0
Using cached pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.3.4
Uninstalling pip-20.3.4:
Successfully uninstalled pip-20.3.4
Successfully installed pip-20.3.4
❯ pip --version
pip 20.3.4 from /home/ctf/anaconda3/envs/python2/lib/python2.7/site-packages/pip (python 2.7) ##这里可以看到安装成功了

先安装基础依赖

1
2
3
4
5
6
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff-dev libdc1394-22-dev
[sudo] password for ctf:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libdc1394-22-dev ##没有这个包也能照常装opencv

然后执行pip安装就行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
❯ pip install opencv-python
Collecting opencv-python
Using cached opencv-python-4.3.0.38.tar.gz (88.0 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
ERROR: Command errored out with exit status 1:
command: /home/ctf/anaconda3/envs/python2/bin/python /home/ctf/anaconda3/envs/python2/lib/python2.7/site-packages/pip/_vendor/pep517/_in_process.py get_requires_for_build_wheel /tmp/tmpdbouGZ ##这里可能会报错Getting requirements to build wheel ..,因为默认安装最新版本的opnecv
❯ pip install opencv-python==4.1.1.26 ##安装其他版本的就可以,pyhton2.7不兼容高版本
Collecting opencv-python==4.1.1.26
Using cached opencv_python-4.1.1.26-cp27-cp27mu-manylinux1_x86_64.whl (28.7 MB)
Collecting numpy>=1.11.1
Using cached numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
Installing collected packages: numpy, opencv-python
Successfully installed numpy-1.16.6 opencv-python-4.1.1.26

不同版本的opencv可以在清华源上找到,逐个尝试即可

Links for opencv-python

结束了

由 Hexo 驱动 & 主题 Keep
本站由 提供部署服务
总字数 258.9k