【环境搭建】depthai + micromamba
一、 下载并安装
推荐使用 micromamba
安装 python
Micromamba
是mamba
软件包管理器的一个微小版本。它是一个纯C++
包,有一个独立的命令行界面。它非常小,不需要基础环境,也不附带Python
的默认版本。它是完全静态链接的,这使得你可以把它放在某个地方并直接执行。它可以用来引导环境(作为miniconda
的替代品)。
注意:micromamba
目前是实验性的,建议只在容器和CI中使用它。
1. 安装 Micromamba
Homebrew
在 macOS 上,您可以从 Homebrew
中安装 Micromamba
:
brew install --cask micromamba
安装脚本
如果你使用 macOS 或 Linux,有一个简单的方法来安装 micromamba
。只需在你喜欢的 shell
中执行安装脚本。
对于 Linux,默认的 shell
是 bash
:
curl micro.mamba.pm/install.sh | bash
对于 macOS,默认的 shell
是 zsh
:
curl micro.mamba.pm/install.sh | zsh
手动安装
Linux 和 macOS
下载并解压可执行文件(来自官方的 conda-forge
软件包):
确保基本的实用程序已经安装。我们需要 wget
和支持 bzip2
的 tar
。你还需要一个基于 glibc
的系统,如 Ubuntu
、Fedora
或 Centos
(Alpine Linux
不能原生工作)。
以下神奇的 URL
总是返回 micromamba
的最新可用版本,bin/micromamba
部分会自动用 tar
提取。
# Linux Intel (x86_64):
curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba
# Linux ARM64:
curl -Ls https://micro.mamba.pm/api/micromamba/linux-aarch64/latest | tar -xvj bin/micromamba
# Linux Power:
curl -Ls https://micro.mamba.pm/api/micromamba/linux-ppc64le/latest | tar -xvj bin/micromamba
# macOS Intel (x86_64):
curl -Ls https://micro.mamba.pm/api/micromamba/osx-64/latest | tar -xvj bin/micromamba
# macOS Silicon/M1 (ARM64):
curl -Ls https://micro.mamba.pm/api/micromamba/osx-arm64/latest | tar -xvj bin/micromamba
提取完成后,我们可以使用 micromamba
的二进制文件。
如果你想使用 micromamba
则可以运行(这也允许你选择一个自定义的 MAMBA_ROOT_ENVIRONMENT
,这就是软件包和 repodata
缓存的位置):
# Linux/bash:
./bin/micromamba shell init -s bash -p ~/micromamba # 这将写入你的.bashrc文件
# source bashrc 文件,将这些变化纳入运行会话中,或者重新启动你的终端!
source ~/.bashrc
# macOS/zsh:
./micromamba shell init -s zsh -p ~/micromamba
source ~/.zshrc
现在你可以激活基本环境并安装新的软件包,或者创建其他环境。
micromamba activate # 这将激活基本环境 micromamba install python=3.6 jupyter -c conda-forge # 或者 micromamba create -n env_name xtensor -c conda-forge micromamba activate env_name
Windows
micromamba
也支持 Windows ! 对于Windows,我们推荐使用 PowerShell
。
下面是在 PowerShell
中安装 micromamba
的命令。
Invoke-Webrequest -URI https://micro.mamba.pm/api/micromamba/win-64/latest -OutFile micromamba.tar.bz2
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar.bz2 -aoa
C:\PROGRA~1\7-Zip\7z.exe x micromamba.tar -ttar -aoa -r Librarybin\micromamba.exe
MOVE -Force Library\bin/micromamba.exe micromamba.exe
.\micromamba.exe --help
# 你可以使用例如 $HOME\micromambaenv 作为你的基本前缀
$Env:MAMBA_ROOT_PREFIX="C:\Your\Root\Prefix"
# 调用钩子
.\micromamba.exe shell hook -s powershell | Out-String | Invok-Expression
# ... 或者初始化shell
.\micromamba.exe shell init -s powershell -p C:\Your\Root\Prefix
# 并直接使用 micromamba
# micromamba create -f ./test/env_win.yaml -y
# micromamba activate yourenv
2. 配置
micromamba config prepend channels conda-forge
配置国内加速
获取配置文件
micromamba config sources
# Configuration files (by precedence order):
# ~/.condarc
国内加速配置
channels:
- conda-forge
# - 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
将国内加速配置写入配置文件 .condarc
中
windows
notepad ~/.condarc
Linux/macOS
vi ~/.condarc
# or
nano ~/.condarc
二、 配置环境
可使用
depthai.yml
创建虚拟环境或使用下面的分步骤
micromamba create -f depthai.yaml -y
name: depthai channels: - conda-forge dependencies: - python=3.8 - pip - setuptools - tk - wheel - pip: - depthai-sdk - blobconverter - depthai - numpy - --extra-index-url https://www.piwheels.org/simple - opencv-python==4.5.4.58 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version == "3.10" - opencv-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version != "3.10" - opencv-contrib-python==4.5.4.58 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version == "3.10" - opencv-contrib-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version != "3.10" - opencv-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l" - opencv-contrib-python==4.4.0.46 ; platform_machine == "armv6l" or platform_machine == "armv7l" - pyyaml - requests==2.26.0 - pyrebase4==4.5 - argcomplete==1.12.1 - pyqt5>5,<5.15.6 ; platform_machine != "armv6l" and platform_machine != "armv7l" and platform_machine != "aarch64"
1. 创建 python 虚拟环境
micromamba create -n depthai python=3.8 -y
### 2. 激活环境
micromamba activate depthai
3. 设置 pip 国内镜像加速
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
4. 安装 git
git for windows
下载连接 https://mirrors.tuna.tsinghua.edu.cn/github-release/git-for-windows/git/LatestRelease/
在 Linux 上安装
如果你想在 Linux 上用二进制安装程序来安装基本的 Git 工具,可以使用发行版包含的基础软件包管理工具来安装。 以 Fedora 为例,如果你在使用它(或与之紧密相关的基于 RPM 的发行版,如 RHEL 或 CentOS),你可以使用 dnf
:
sudo dnf install git
如果你在基于 Debian 的发行版上,如 Ubuntu,请使用 apt
:
sudo apt install git
要了解更多选择,Git 官方网站上有在各种 Unix 发行版的系统上安装步骤,网址为 https://git-scm.com/download/linux。
5. 安装环境依赖
depthai
depthai
仓库含有版本检测脚本 ,若安装depthai
版本不符会阻止程序运行。推荐为本仓库单独设置一个环境:
micromamba create -n depthai_demo python=3.8
也可添加
--skipVersionCheck
跳过跳过检测
- 克隆仓库
git clone --depth=1 https://github.com/luxonis/depthai.git
-
安装依赖
micromamba activate depthai_demo pip install -r requirements.txt -r requirements-optional.txt
-
运行测试
python depthai_demo.py [-gt cv]
depthai-python
- 克隆仓库
git clone --depth=1 https://github.com/luxonis/depthai-python.git
-
安装依赖
运行以下命令后,根据提示按需下载安装
micromamba activate depthai python examples/install_requirements.py --dry_run
例如:
pip 21.3.1 from <path>/site-packages/pip (python 3.8) python -m pip install -U pip python -m pip install -U --prefer-binary pyyaml requests numpy opencv-python!=4.5.4.58 python -m pip install -U --prefer-binary -U --force-reinstall depthai python <path>/depthai-python/examples/downloader/downloader.py --all --cache_dir <path>/depthai-python/examples/downloader/ --num_attempts 5 -o <path>/depthai-python/examples/models