天天看点

Raspberry Pi 3B 安装Miniconda

Raspberry Pi 4B 安装 Miniconda

        • 查看内存信息
        • 查看系统信息
        • 查看树莓派的Linux版本
        • 下载 miniconda
        • 安装 Miniconda3
        • 更新配置文件
        • 查看安装的 conda 版本:
        • 查看已安装依赖
        • 创建虚拟环境
        • 激活刚创建的虚拟环境
        • 安装依赖
        • 卸载miniconda
        • 遇到的问题
          • 如果需要安装64位Linux

组件:

  • Raspberry Pi 3B 1G

环境:

  • Linux raspbian 5.4.83
  • 指令集:aarch64
  • Miniconda 4.9.2
  • Python 3.8.11
  • Raspberry Pi 4B系统:
    • 2021-01-04-OPENFANS-Debian-Buster-Desktop-Aarch64-ext4-v2021-2.0-U6-Release.img

注意

:仅支持Raspberry Pi 4B 64位系统安装 Miniconda

查看内存信息

[email protected]:~/Software/vvcat_bot$ free
              total        used        free      shared  buff/cache   available
Mem:         929804      370128      273192        4832      286484      481116
Swap:       1048572      245248      803324
           

查看系统信息

lsb_release  -a
           

[email protected]:~$ lsb_release -a

No LSB modules are available.

Distributor ID: Debian

Description: Debian GNU/Linux 10 (buster)

Release: 10

Codename: buster

查看树莓派的Linux版本

uname -a
           

[email protected]:~/Software$ uname -a

Linux raspbian 5.4.83-OPENFANS+20210102-v8 #1 SMP Sat Jan 2 21:52:54 CST 2021 aarch64 GNU/Linux

注意:如果你的Linux操作系统为32位的 请下载armv7结尾的.sh文件,但是Miniconda对armv7的支持版本已经很古老了,在创建虚拟环境Python3.7以上貌似都会出现问题,勉强支持到Python3.4版本左右,而且官方的作者对armv7结尾的.sh文件已经停更很久了,不建议安装使用,推荐树莓派安装64位的Linux。

Miniconda对armv7的支持参考:https://github.com/jjhelmus/berryconda

下载 miniconda

miniconda官方下载地址:https://repo.anaconda.com/miniconda/

miniconda清华镜像下载地址:https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/

因为我树莓派的Linux指令集为

aarch64

,所在miniconda官方仓库中选择了 Linux-aarch64 版本的,根据自己树莓派Linux的版本选择对应的版本,否则安装或在使用中会出错。

wget https://repo.continuum.io/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh
           

[email protected]:~/Software$ wget https://repo.continuum.io/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh

–2021-09-01 15:22:21-- https://repo.continuum.io/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh

Resolving repo.continuum.io (repo.continuum.io)… 104.18.201.79, 104.18.200.79, 2606:4700::6812:c84f, …

Connecting to repo.continuum.io (repo.continuum.io)|104.18.201.79|:443… connected.

HTTP request sent, awaiting response… 301 Moved Permanently

Location: https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh [following]

–2021-09-01 15:22:24-- https://repo.anaconda.com/miniconda/Miniconda3-py39_4.9.2-Linux-aarch64.sh

Resolving repo.anaconda.com (repo.anaconda.com)… 104.16.131.3, 104.16.130.3, 2606:4700::6810:8203, …

Connecting to repo.anaconda.com (repo.anaconda.com)|104.16.131.3|:443… connected.

HTTP request sent, awaiting response… 200 OK

Length: 79911973 (76M) [application/x-sh]

Saving to: ‘Miniconda3-py39_4.9.2-Linux-aarch64.sh’

Miniconda3-py39_4.9.2-Linu 100%[=======================================>] 76.21M 7.14MB/s in 15s

2021-09-01 15:22:39 (5.17 MB/s) - ‘Miniconda3-py39_4.9.2-Linux-aarch64.sh’ saved [79911973/79911973]

安装 Miniconda3

/bin/bash Miniconda3-py39_4.9.2-Linux-aarch64.sh
           

Last updated September 28, 2020

Do you accept the license terms? [yes|no]

[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] >>>

PREFIX=/root/miniconda3

Unpacking payload …

Collecting package metadata (current_repodata.json): done

Solving environment: done

Preparing transaction: done

Executing transaction: done

installation finished.

Do you wish the installer to initialize Miniconda3

by running conda init? [yes|no]

[no] >>> yes

no change /home/pi/miniconda3/condabin/conda

no change /home/pi/miniconda3/bin/conda

no change /home/pi/miniconda3/bin/conda-env

no change /home/pi/miniconda3/bin/activate

no change /home/pi/miniconda3/bin/deactivate

no change /home/pi/miniconda3/etc/profile.d/conda.sh

no change /home/pi/miniconda3/etc/fish/conf.d/conda.fish

no change /home/pi/miniconda3/shell/condabin/Conda.psm1

no change /home/pi/miniconda3/shell/condabin/conda-hook.ps1

no change /home/pi/miniconda3/lib/python3.9/site-packages/xontrib/conda.xsh

no change /home/pi/miniconda3/etc/profile.d/conda.csh

modified /home/pi/.bashrc

==>For changes to take effect, close and re-open your current shell. <==

If you’d prefer that conda’s base environment not be activated on startup,

set the auto_activate_base parameter to false:

conda config --set auto_activate_base false

Thank you for installing Miniconda3!

使用 cat 查看是否配置了Miniconda3 的环境变量,如果没有需要在.bashrc文件末尾自己手动添加

cat ~/.bashrc
           
Raspberry Pi 3B 安装Miniconda

根据 miniconda3 安装的路径,添加对应的环境变量

Raspberry Pi 3B 安装Miniconda
vim ~/.bashrc
           

更新配置文件

如果不更新配置文件会找不到 conda 命令

source ~/.bashrc
           

例如:

[email protected]:~$ conda -V

conda: command not found

查看安装的 conda 版本:

conda -V
           

(base)[email protected]:~/Software$ conda -V

conda 4.9.2

查看已安装依赖

conda list
           

(base) [email protected]:~/Software$ conda list

# packages in environment at /home/pi/miniconda3/envs/qqbot:

#

# Name Version Build Channel

_libgcc_mutex 0.1 main

_openmp_mutex 5.1 51_gnu

ca-certificates 2021.7.5 hd43f75c_1

certifi 2021.5.30 py38hd43f75c_0

ld_impl_linux-aarch64 2.36.1 h0ab8de2_3

libffi 3.3 h7c1a80f_2

libgcc-ng 10.2.0 h1234567_51

libgomp 10.2.0 h1234567_51

libstdcxx-ng 10.2.0 h1234567_51

ncurses 6.2 hfd63f10_0

openssl 1.1.1k hfd63f10_1

pip 21.2.4 py38hd43f75c_0

python 3.8.11 hc137634_1

readline 8.1 hfd63f10_0

setuptools 52.0.0 py38hd43f75c_0

sqlite 3.36.0 h6632b73_0

tk 8.6.10 h8ea0f78_0

wheel 0.37.0 pyhd3eb1b0_0

xz 5.2.5 hfd63f10_1

zlib 1.2.11 hfd63f10_5

创建虚拟环境

格式如下:

conda create -n [虚拟环境名称] python=[版本号]
           

示例:

激活刚创建的虚拟环境

格式如下:

source activate [虚拟环境名称]
           

示例:

source activate qqbot 
           

查看虚拟环境中的Python版本

python --version
           

(qqbot) [email protected]:~/Software$ python --version

Python 3.8.11

安装依赖

卸载miniconda

找到miniconda3的文件夹,使用rm命令将它删除:

sudo rm -rf miniconda3/
           

然后,用vim命令进入.bashrc文件,将conda的语句用#注释掉

vim ~/.bashrc
           

最后,重新更新一下.bashrc文件就可以了。

source ~/.bashrc
           

遇到的问题

在安装 miniconda 4.10.1 遇到了以下问题,采用了降版本的方式解决了问题。

conda list Illegal instruction
           

注:目前大于4.9版本的miniconda不适配树莓派arm64架构操作系统,安装后无法正常使用!

参考:https://stackoverflow.com/questions/68099000/conda-init-illegal-instruction-core-dumped

如果需要安装64位Linux

(推荐)树莓派爱好者基地:https://github.com/openfans-community-offical/Debian-Pi-Aarch64