ヴェズルフェルニルの研究ノート

座右の銘「ただ一人犀の角のように歩め」的な研究活動ノート

asdfことはじめ(anyenvから乗り換え)

前記事にanyenv + pyenv + PoetryによるPython仮想環境の構築方法を書いたが、最近言語バージョン管理ツールとしてasdfというものが存在することを知った。

blog.ketus-ix.work

それで、新しい開発環境ではanyenvの代わりにasdfを使い始めた。

asdf-vm.com

asdfの良いところは現存のプログラミング言語を網羅的に対応していることだ。anyenvはPythonやNode.jsなどの人気のある言語には対応しているが、Java、Kotlin、MavenJava系言語)やFlutter/Dartには対応していない。それで、いままでanyenv、SDKMAN、FVM(Flutter Version Manager)を併用していた。asdfに代えてから、Python, Node.js/TypeScript, Java, Kotlin, Maven, Flutter/Dart、そしてSwift, Go, Lua, Rust, R, Erlang, Elixirなど私が使うすべてのプログラミング言語をこれだけでカバーできるようになった。また、JSON, Docker, Terraformなどの定義記述系言語にも対応していて、asdfだけでこれらも利用できる。

自分の備忘録として、本記事にasdfによるPythonのインストール手順と使い方の要点を書いておく。

asdfのインストール

$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.12.0
% brew install asdf

asdfのコマンドパスを設定

Ubuntu

$ vi ~/.bashrc
. "$HOME/.asdf/asdf.sh"
$ source ~/.bashrc
% vi ~/.zshrc
. "$HOME/.asdf/asdf.sh"
% source ~/.zshrc

Mac

$ echo -e "\n. \"$(brew --prefix asdf)/libexec/asdf.sh\"" >> ~/.bashrc
$ source ~/.bashrc
% echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc
% source ~/.zshrc

asdfによるPythonのインストール

$ asdf plugin list all
initializing plugin repository...Cloning into '/Users/LOGNAME/.asdf/repository'...
....    ....
....    ....
1password-cli                 https://github.com/NeoHsu/asdf-1password-cli.git
R                             https://github.com/asdf-community/asdf-r.git
act                           https://github.com/grimoh/asdf-act.git
action-validator              https://github.com/mpalmer/action-validator.git
actionlint                    https://github.com/crazy-matt/asdf-actionlint.git
adr-tools                     https://gitlab.com/td7x/asdf/adr-tools.git
ag                            https://github.com/koketani/asdf-ag.git
age                           https://github.com/threkk/asdf-age
age-plugin-yubikey            https://github.com/joke/asdf-age-plugin-yubikey
agebox                        https://github.com/slok/asdf-agebox.git
air                           https://github.com/pdemagny/asdf-air
aks-engine                    https://github.com/robsonpeixoto/asdf-aks-engine.git
alias                         https://github.com/andrewthauer/asdf-alias.git
allure                        https://github.com/comdotlinux/asdf-allure.git
alp                           https://github.com/asdf-community/asdf-alp.git
amass                         https://github.com/dhoeric/asdf-amass.git
amazon-ecr-credential-helper  https://github.com/dex4er/asdf-amazon-ecr-credential-helper.git
ambient                       https://github.com/jtakakura/asdf-ambient.git
ansible-base                  https://github.com/amrox/asdf-pyapp.git
ant                           https://github.com/jackboespflug/asdf-ant.git
apollo-router                 https://github.com/safx/asdf-apollo-router.git
arc                           https://github.com/ORCID/asdf-arc.git
argo                          https://github.com/sudermanjr/asdf-argo.git
argo-rollouts                 https://github.com/abatilo/asdf-argo-rollouts.git
argocd                        https://github.com/beardix/asdf-argocd.git
aria2                         https://github.com/asdf-community/asdf-aria2.git
asciidoctorj                  https://github.com/gliwka/asdf-asciidoctorj.git
assh                          https://github.com/zekker6/asdf-assh.git
aws-amplify-cli               https://github.com/LozanoMatheus/asdf-aws-amplify-cli.git
aws-copilot                   https://github.com/NeoHsu/asdf-copilot
aws-iam-authenticator         https://github.com/zekker6/asdf-aws-iam-authenticator
aws-nuke                      https://github.com/bersalazar/asdf-aws-nuke.git
aws-sam-cli                   https://github.com/amrox/asdf-pyapp.git
aws-sso-cli                   https://github.com/adamcrews/asdf-aws-sso-cli.git
aws-vault                     https://github.com/karancode/asdf-aws-vault.git
awscli                        https://github.com/MetricMike/asdf-awscli.git
awscli-local                  https://github.com/paulo-ferraz-oliveira/asdf-awscli-local
awsebcli                      https://github.com/amrox/asdf-pyapp.git
awsls                         https://github.com/chessmango/asdf-awsls.git
awsrm                         https://github.com/chessmango/asdf-awsrm.git
awsweeper                     https://github.com/chessmango/asdf-awsweeper.git
azure-cli                     https://github.com/EcoMind/asdf-azure-cli.git
azure-functions-core-tools    https://github.com/daveneeley/asdf-azure-functions-core-tools.git
babashka                      https://github.com/pitch-io/asdf-babashka.git
balena-cli                    https://github.com/boatkit-io/asdf-balena-cli
bashbot                       https://github.com/mathew-fleisch/asdf-bashbot.git
bat                           https://gitlab.com/wt0f/asdf-bat.git
batect                        https://github.com/johnlayton/asdf-batect.git
bats                          https://github.com/timgluz/asdf-bats.git
bazel                         https://github.com/rajatvig/asdf-bazel.git
bbr                           https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
bbr-s3-config-validator       https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
benthos                       https://github.com/benthosdev/benthos-asdf.git
bin                           https://github.com/joe733/asdf-bin.git
binnacle                      https://github.com/Traackr/asdf-binnacle.git
bitwarden                     https://github.com/vixus0/asdf-bitwarden.git
bombardier                    https://github.com/NeoHsu/asdf-bombardier.git
borg                          https://github.com/lwiechec/asdf-borg
bosh                          https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
bottom                        https://github.com/carbonteq/asdf-btm.git
boundary                      https://github.com/asdf-community/asdf-hashicorp.git
bpkg                          https://github.com/bpkg/asdf-bpkg.git
brig                          https://github.com/Ibotta/asdf-brig.git
btrace                        https://github.com/joschi/asdf-btrace.git
buf                           https://github.com/truepay/asdf-buf.git
buildpack                     https://github.com/johnlayton/asdf-buildpack.git
bun                           https://github.com/cometkim/asdf-bun.git
bundler                       https://github.com/jonathanmorley/asdf-bundler.git
caddy                         https://github.com/salasrod/asdf-caddy.git
calicoctl                     https://github.com/TheCubicleJockey/asdf-calicoctl.git
camunda-modeler               https://github.com/barmac/asdf-camunda-modeler.git
cargo-make                    https://github.com/kachick/asdf-cargo-make.git
carp                          https://github.com/susurri/asdf-carp.git
carthage                      https://github.com/younke/asdf-carthage.git
ccache                        https://github.com/asdf-community/asdf-ccache.git
certstrap                     https://github.com/carnei-ro/asdf-certstrap.git
cf                            https://github.com/mattysweeps/asdf-cf.git
cfssl                         https://github.com/mathew-fleisch/asdf-cfssl.git
chamber                       https://github.com/mintel/asdf-chamber
cheat                         https://github.com/jmoratilla/asdf-cheat-plugin
checkov                       https://github.com/bosmak/asdf-checkov.git
chezmoi                       https://github.com/joke/asdf-chezmoi.git
chezscheme                    https://github.com/asdf-community/asdf-chezscheme.git
chicken                       https://github.com/evhan/asdf-chicken.git
choose                        https://github.com/carbonteq/asdf-choose.git
chromedriver                  https://github.com/schinckel/asdf-chromedriver.git
cidr-merger                   https://github.com/ORCID/asdf-cidr-merger.git
cidrchk                       https://github.com/ORCID/asdf-cidrchk.git
cilium-cli                    https://github.com/carnei-ro/asdf-cilium-cli.git
cilium-hubble                 https://github.com/NitriKx/asdf-cilium-hubble.git
circleci-cli                  https://github.com/ucpr/asdf-circleci-cli.git
clojure                       https://github.com/asdf-community/asdf-clojure.git
cloud-sql-proxy               https://github.com/pbr0ck3r/asdf-cloud-sql-proxy.git
cloudflared                   https://github.com/threkk/asdf-cloudflared
clusterawsadm                 https://github.com/kahun/asdf-clusterawsadm.git
clusterctl                    https://github.com/pfnet-research/asdf-clusterctl.git
cmake                         https://github.com/asdf-community/asdf-cmake.git
cmctl                         https://github.com/asdf-community/asdf-cmctl.git
cockroach                     https://github.com/salasrod/asdf-cockroach.git
cocoapods                     https://github.com/ronnnnn/asdf-cocoapods.git
codefresh                     https://github.com/gurukulkarni/asdf-codefresh.git
codeql                        https://github.com/bored-engineer/asdf-codeql.git
colima                        https://github.com/CrouchingMuppet/asdf-colima.git
conan                         https://github.com/amrox/asdf-pyapp.git
concourse                     https://github.com/mattysweeps/asdf-concourse.git
conduit                       https://github.com/gmcabrita/asdf-conduit.git
conform                       https://github.com/skyzyx/asdf-conform.git
conftest                      https://github.com/looztra/asdf-conftest.git
consul                        https://github.com/asdf-community/asdf-hashicorp.git
container-diff                https://github.com/cgroschupp/asdf-container-diff.git
container-structure-test      https://github.com/jonathanmorley/asdf-container-structure-test.git
cookiecutter                  https://github.com/shawon-crosen/asdf-cookiecutter.git
copper                        https://github.com/vladlosev/asdf-copper.git
coq                           https://github.com/gingerhot/asdf-coq.git
cosign                        https://gitlab.com/wt0f/asdf-cosign.git
coursier                      https://github.com/jiahuili430/asdf-coursier.git
crane                         https://github.com/dmpe/asdf-crane
crc                           https://github.com/sqtran/asdf-crc.git
credhub                       https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
crictl                        https://github.com/FairwindsOps/asdf-crictl.git
crossplane-cli                https://github.com/joke/asdf-crossplane-cli.git
crystal                       https://github.com/asdf-community/asdf-crystal.git
ctlptl                        https://github.com/ezcater/asdf-ctlptl.git
ctop                          https://github.com/NeoHsu/asdf-ctop.git
cue                           https://github.com/asdf-community/asdf-cue.git
cyclonedx                     https://github.com/xeedio/asdf-cyclonedx.git
dagger                        https://github.com/virtualstaticvoid/asdf-dagger.git
dart                          https://github.com/PatOConnor43/asdf-dart.git
dasel                         https://github.com/asdf-community/asdf-dasel.git
datree                        https://github.com/lukeab/asdf-datree.git
dbmate                        https://github.com/juusujanar/asdf-dbmate.git
deck                          https://github.com/nutellinoit/asdf-deck.git
delta                         https://github.com/andweeb/asdf-delta.git
deno                          https://github.com/asdf-community/asdf-deno.git
dep                           https://github.com/paxosglobal/asdf-dep.git
depot                         https://github.com/depot/asdf-depot.git
desk                          https://github.com/endorama/asdf-desk.git
devspace                      https://github.com/NeoHsu/asdf-devspace.git
dhall                         https://github.com/aaaaninja/asdf-dhall.git
difftastic                    https://github.com/volf52/asdf-difftastic.git
digdag                        https://github.com/jtakakura/asdf-digdag.git
direnv                        https://github.com/asdf-community/asdf-direnv.git
dive                          https://github.com/looztra/asdf-dive.git
djinni                        https://github.com/cross-language-cpp/asdf-djinni.git
dmd                           https://github.com/sylph01/asdf-dmd.git
docker-compose-v1             https://github.com/yilas/asdf-docker-compose-v1
docker-slim                   https://github.com/xataz/asdf-docker-slim.git
dockle                        https://github.com/mathew-fleisch/asdf-dockle.git
doctl                         https://github.com/maristgeek/asdf-doctl.git
doctoolchain                  https://github.com/joschi/asdf-doctoolchain
docuum                        https://github.com/bradym/asdf-docuum.git
dome                          https://github.com/jtakakura/asdf-dome.git
doppler                       https://github.com/takutakahashi/asdf-doppler.git
dotenv-linter                 https://github.com/wesleimp/asdf-dotenv-linter.git
dotnet                        https://github.com/hensou/asdf-dotnet
dotnet-core                   https://github.com/emersonsoares/asdf-dotnet-core.git
dotty                         https://github.com/asdf-community/asdf-dotty.git
dprint                        https://github.com/asdf-community/asdf-dprint
draft                         https://github.com/kristoflemmens/asdf-draft.git
driftctl                      https://github.com/nlamirault/asdf-driftctl.git
drone                         https://github.com/virtualstaticvoid/asdf-drone.git
dtm                           https://github.com/zhenyuanlau/asdf-dtm.git
duf                           https://github.com/NeoHsu/asdf-duf.git
dust                          https://github.com/looztra/asdf-dust.git
dvc                           https://github.com/fwfurtado/asdf-dvc.git
dyff                          https://gitlab.com/wt0f/asdf-dyff.git
ecspresso                     https://github.com/kayac/asdf-ecspresso.git
editorconfig-checker          https://github.com/gabitchov/asdf-editorconfig-checker.git
ejson                         https://github.com/cipherstash/asdf-ejson.git
eksctl                        https://github.com/elementalvoid/asdf-eksctl.git
elasticsearch                 https://github.com/asdf-community/asdf-elasticsearch.git
elixir                        https://github.com/asdf-vm/asdf-elixir.git
elm                           https://github.com/asdf-community/asdf-elm.git
embulk                        https://github.com/yuokada/asdf-embulk.git
emsdk                         https://github.com/RobLoach/asdf-emsdk.git
envcli                        https://github.com/zekker6/asdf-envcli.git
ephemeral-postgres            https://github.com/smashedtoatoms/asdf-ephemeral-postgres.git
erlang                        https://github.com/asdf-vm/asdf-erlang.git
esy                           https://github.com/asdf-community/asdf-esy.git
etcd                          https://github.com/particledecay/asdf-etcd.git
evans                         https://github.com/goki90210/asdf-evans.git
exa                           https://github.com/nyrst/asdf-exa.git
fd                            https://gitlab.com/wt0f/asdf-fd.git
ffmpeg                        https://github.com/acj/asdf-ffmpeg
figma-export                  https://github.com/younke/asdf-figma-export.git
fillin                        https://github.com/ouest/asdf-fillin
firebase                      https://github.com/jthegedus/asdf-firebase.git
fission                       https://github.com/virtualstaticvoid/asdf-fission.git
flarectl                      https://github.com/ORCID/asdf-flarectl.git
flatc                         https://github.com/TheOpenDictionary/asdf-flatc.git
flutter                       https://github.com/oae/asdf-flutter.git
flux2                         https://github.com/tablexi/asdf-flux2.git
fluxctl                       https://github.com/stefansedich/asdf-fluxctl.git
fly                           https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
flyctl                        https://github.com/chessmango/asdf-flyctl.git
flyway                        https://github.com/junminahn/asdf-flyway.git
func-e                        https://github.com/carnei-ro/asdf-func-e.git
furyctl                       https://github.com/sighupio/asdf-furyctl.git
fx                            https://gitlab.com/wt0f/asdf-fx.git
fzf                           https://github.com/kompiro/asdf-fzf.git
gallery-dl                    https://github.com/iul1an/asdf-gallery-dl
gam                           https://github.com/offbyone/asdf-gam.git
gator                         https://github.com/MxNxPx/asdf-gator.git
gauche                        https://github.com/sakuro/asdf-gauche.git
gcc-arm-none-eabi             https://github.com/dlech/asdf-gcc-arm-none-eabi.git
gcloud                        https://github.com/jthegedus/asdf-gcloud.git
getenvoy                      https://github.com/asdf-community/asdf-getenvoy.git
ghidra                        https://github.com/Honeypot95/asdf-ghidra.git
ghorg                         https://github.com/gbloquel/asdf-ghorg.git
ghq                           https://github.com/kajisha/asdf-ghq.git
ginkgo                        https://github.com/jimmidyson/asdf-ginkgo.git
git                           https://gitlab.com/jcaigitlab/asdf-git.git
git-chglog                    https://github.com/GoodwayGroup/asdf-git-chglog.git
gitconfig                     https://github.com/0ghny/asdf-gitconfig.git
github-cli                    https://github.com/bartlomiejdanek/asdf-github-cli.git
github-markdown-toc           https://github.com/skyzyx/asdf-github-markdown-toc.git
gitleaks                      https://github.com/jmcvetta/asdf-gitleaks.git
gitsign                       https://github.com/spencergilbert/asdf-gitsign.git
gitui                         https://github.com/looztra/asdf-gitui.git
glab                          https://github.com/particledecay/asdf-glab.git
gleam                         https://github.com/vic/asdf-gleam.git
glen                          https://github.com/bradym/asdf-glen
glooctl                       https://github.com/halilkaya/asdf-glooctl.git
glow                          https://github.com/chessmango/asdf-glow.git
go-containerregistry          https://github.com/dex4er/asdf-go-containerregistry.git
go-getter                     https://github.com/ryodocx/asdf-go-getter.git
go-jira                       https://github.com/dguihal/asdf-go-jira.git
go-jsonnet                    https://gitlab.com/craigfurman/asdf-go-jsonnet.git
go-junit-report               https://github.com/jwillker/asdf-go-junit-report.git
go-sdk                        https://github.com/yacchi/asdf-go-sdk.git
go-swagger                    https://github.com/jfreeland/asdf-go-swagger.git
goconvey                      https://github.com/therounds-contrib/asdf-goconvey.git
gofumpt                       https://github.com/looztra/asdf-gofumpt.git
gohugo                        https://github.com/nklmilojevic/asdf-hugo.git
gojq                          https://github.com/jimmidyson/asdf-gojq.git
golang                        https://github.com/asdf-community/asdf-golang.git
golangci-lint                 https://github.com/hypnoglow/asdf-golangci-lint.git
gomigrate                     https://github.com/joschi/asdf-gomigrate.git
gomplate                      https://github.com/sneakybeaky/asdf-gomplate.git
gopass                        https://github.com/trallnag/asdf-gopass.git
goreleaser                    https://github.com/kforsthoevel/asdf-goreleaser.git
goss                          https://github.com/raimon49/asdf-goss.git
graalvm                       https://github.com/asdf-community/asdf-graalvm.git
gradle                        https://github.com/rfrancis/asdf-gradle.git
gradle-profiler               https://github.com/joschi/asdf-gradle-profiler.git
grails                        https://github.com/weibemoura/asdf-grails.git
grain                         https://github.com/cometkim/asdf-grain.git
granted                       https://github.com/dex4er/asdf-granted.git
grex                          https://github.com/ouest/asdf-grex
groovy                        https://github.com/weibemoura/asdf-groovy.git
grpc-health-probe             https://github.com/zufardhiyaulhaq/asdf-grpc-health-probe.git
grpcurl                       https://github.com/asdf-community/asdf-grpcurl.git
grype                         https://github.com/poikilotherm/asdf-grype.git
guile                         https://github.com/indiebrain/asdf-guile.git
gum                           https://github.com/lwiechec/asdf-gum
gwvault                       https://github.com/GoodwayGroup/asdf-gwvault.git
hadolint                      https://github.com/devlincashman/asdf-hadolint.git
hamler                        https://github.com/scudelletti/asdf-hamler.git
has                           https://github.com/sylvainmetayer/asdf-has
haskell                       https://github.com/asdf-community/asdf-haskell.git
hasura-cli                    https://github.com/gurukulkarni/asdf-hasura.git
haxe                          https://github.com/asdf-community/asdf-haxe.git
hcl2json                      https://github.com/dex4er/asdf-hcl2json.git
hcloud                        https://github.com/chessmango/asdf-hcloud.git
helm                          https://github.com/Antiarchitect/asdf-helm.git
helm-cr                       https://github.com/Antiarchitect/asdf-helm-cr.git
helm-ct                       https://github.com/tablexi/asdf-helm-ct.git
helm-diff                     https://github.com/dex4er/asdf-helm-diff.git
helm-docs                     https://github.com/sudermanjr/asdf-helm-docs.git
helmfile                      https://github.com/feniix/asdf-helmfile.git
helmsman                      https://github.com/luisdavim/asdf-helmsman
heroku-cli                    https://github.com/treilly94/asdf-heroku-cli.git
hey                           https://github.com/raimon49/asdf-hey.git
httpie-go                     https://github.com/abatilo/asdf-httpie-go.git
hub                           https://github.com/vixus0/asdf-hub.git
hugo                          https://github.com/NeoHsu/asdf-hugo.git
hurl                          https://github.com/raimon49/asdf-hurl.git
hwatch                        https://github.com/chessmango/asdf-hwatch.git
hygen                         https://github.com/brentjanderson/asdf-hygen.git
hyperfine                     https://github.com/volf52/asdf-hyperfine.git
iam-policy-json-to-terraform  https://github.com/carlduevel/asdf-iam-policy-json-to-terraform.git
iamlive                       https://github.com/chessmango/asdf-iamlive.git
ibmcloud                      https://github.com/triangletodd/asdf-ibmcloud.git
idris                         https://github.com/asdf-community/asdf-idris.git
idris2                        https://github.com/asdf-community/asdf-idris2.git
imagemagick                   https://github.com/mangalakader/asdf-imagemagick.git
imgpkg                        https://github.com/vmware-tanzu/asdf-carvel.git
infracost                     https://github.com/dex4er/asdf-infracost.git
inlets                        https://github.com/nlamirault/asdf-inlets.git
io                            https://github.com/mracos/asdf-io.git
istioctl                      https://github.com/virtualstaticvoid/asdf-istioctl.git
janet                         https://github.com/Jakski/asdf-janet.git
java                          https://github.com/halcyon/asdf-java.git
jb                            https://github.com/beardix/asdf-jb.git
jbang                         https://github.com/joschi/asdf-jbang.git
jib                           https://github.com/joschi/asdf-jib.git
jiq                           https://github.com/chessmango/asdf-jiq.git
jless                         https://github.com/jc00ke/asdf-jless.git
jmespath                      https://github.com/skyzyx/asdf-jmespath.git
jmeter                        https://github.com/comdotlinux/asdf-jmeter
jq                            https://github.com/lsanwick/asdf-jq.git
jqp                           https://gitlab.com/wt0f/asdf-jqp.git
jreleaser                     https://github.com/joschi/asdf-jreleaser.git
jsonnet                       https://github.com/Banno/asdf-jsonnet.git
julia                         https://github.com/rkyleg/asdf-julia.git
just                          https://github.com/olofvndrhr/asdf-just.git
jx                            https://github.com/vbehar/asdf-jx.git
k0sctl                        https://github.com/Its-Alex/asdf-plugin-k0sctl.git
k14s                          https://github.com/k14s/asdf-k14s.git
k2tf                          https://github.com/carlduevel/asdf-k2tf.git
k3d                           https://github.com/spencergilbert/asdf-k3d.git
k3sup                         https://github.com/cgroschupp/asdf-k3sup.git
k6                            https://github.com/grimoh/asdf-k6.git
k9s                           https://github.com/looztra/asdf-k9s.git
kafka                         https://github.com/ueisele/asdf-kafka.git
kafkactl                      https://github.com/anweber/asdf-kafkactl.git
kapp                          https://github.com/vmware-tanzu/asdf-carvel.git
kbld                          https://github.com/vmware-tanzu/asdf-carvel.git
kcat                          https://github.com/douglasdgoulart/asdf-kcat.git
kcctl                         https://github.com/joschi/asdf-kcctl.git
kconf                         https://github.com/particledecay/asdf-kconf.git
ki                            https://github.com/comdotlinux/asdf-ki
kind                          https://github.com/johnlayton/asdf-kind.git
kiota                         https://github.com/asdf-community/asdf-kiota.git
kn                            https://github.com/joke/asdf-kn.git
ko                            https://github.com/zasdaym/asdf-ko.git
koka                          https://github.com/susurri/asdf-koka.git
kompose                       https://github.com/technikhil314/asdf-kompose.git
kops                          https://github.com/Antiarchitect/asdf-kops.git
kotlin                        https://github.com/asdf-community/asdf-kotlin.git
kp                            https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
kpt                           https://github.com/nlamirault/asdf-kpt.git
krab                          https://github.com/ohkrab/asdf-krab.git
krew                          https://github.com/bjw-s/asdf-krew.git
kscript                       https://github.com/edgelevel/asdf-kscript.git
ksonnet                       https://github.com/Banno/asdf-ksonnet.git
ktlint                        https://github.com/esensar/asdf-ktlint.git
kube-capacity                 https://github.com/looztra/asdf-kube-capacity.git
kube-code-generator           https://github.com/jimmidyson/asdf-kube-code-generator.git
kube-controller-tools         https://github.com/jimmidyson/asdf-kube-controller-tools.git
kube-credential-cache         https://github.com/ryodocx/kube-credential-cache.git
kube-linter                   https://github.com/devlincashman/asdf-kube-linter.git
kube-score                    https://github.com/bageljp/asdf-kube-score.git
kubebuilder                   https://github.com/virtualstaticvoid/asdf-kubebuilder.git
kubecm                        https://github.com/samhvw8/asdf-kubecm
kubecolor                     https://github.com/dex4er/asdf-kubecolor.git
kubeconform                   https://github.com/lirlia/asdf-kubeconform.git
kubectl                       https://github.com/asdf-community/asdf-kubectl.git
kubectl-bindrole              https://github.com/looztra/asdf-kubectl-bindrole.git
kubectl-buildkit              https://github.com/ezcater/asdf-kubectl-buildkit.git
kubectl-convert               https://github.com/iul1an/asdf-kubectl-convert.git
kubectl-kots                  https://github.com/ganta/asdf-kubectl-kots.git
kubectx                       https://gitlab.com/wt0f/asdf-kubectx.git
kubefedctl                    https://github.com/kvokka/asdf-kubefedctl.git
kubefirst                     https://github.com/Claywd/asdf-kubefirst
kubelogin                     https://github.com/sechmann/asdf-kubelogin.git
kubemqctl                     https://github.com/johnlayton/asdf-kubemqctl.git
kubent                        https://github.com/virtualstaticvoid/asdf-kubent.git
kubergrunt                    https://github.com/NeoHsu/asdf-kubergrunt.git
kubeseal                      https://github.com/stefansedich/asdf-kubeseal.git
kubesec                       https://github.com/vitalis/asdf-kubesec.git
kubeshark                     https://github.com/carnei-ro/asdf-kubeshark.git
kubespy                       https://github.com/jfreeland/asdf-kubespy.git
kubeval                       https://github.com/stefansedich/asdf-kubeval.git
kubevela                      https://github.com/gustavclausen/asdf-kubevela.git
kubie                         https://github.com/johnhamelink/asdf-kubie.git
kustomize                     https://github.com/Banno/asdf-kustomize.git
kuttl                         https://github.com/jimmidyson/asdf-kuttl.git
kwt                           https://github.com/vmware-tanzu/asdf-carvel.git
lab                           https://github.com/particledecay/asdf-lab.git
lazygit                       https://github.com/nklmilojevic/asdf-lazygit.git
lean                          https://github.com/asdf-community/asdf-lean.git
lefthook                      https://github.com/jtzero/asdf-lefthook.git
leiningen                     https://github.com/miorimmax/asdf-lein.git
levant                        https://github.com/asdf-community/asdf-hashicorp.git
lfe                           https://github.com/asdf-community/asdf-lfe.git
lima                          https://github.com/CrouchingMuppet/asdf-lima.git
link                          https://github.com/asdf-community/asdf-link.git
linkerd                       https://github.com/kforsthoevel/asdf-linkerd.git
liqoctl                       https://github.com/pdemagny/asdf-liqoctl
litestream                    https://github.com/threkk/asdf-litestream
logtalk                       https://github.com/LogtalkDotOrg/asdf-logtalk.git
loki-logcli                   https://github.com/comdotlinux/asdf-loki-logcli.git
lua                           https://github.com/Stratus3D/asdf-lua.git
lua-language-server           https://github.com/bellini666/asdf-lua-language-server
luaJIT                        https://github.com/smashedtoatoms/asdf-luaJIT.git
lucy                          https://github.com/cometkim/asdf-lucy.git
maestro                       https://github.com/dotanuki-labs/asdf-maestro.git
mage                          https://github.com/mathew-fleisch/asdf-mage.git
make                          https://github.com/yacchi/asdf-make.git
mani                          https://github.com/anweber/asdf-mani.git
mark                          https://github.com/jfreeland/asdf-mark.git
markdownlint-cli2             https://github.com/paulo-ferraz-oliveira/asdf-markdownlint-cli2
marp-cli                      https://github.com/xataz/asdf-marp-cli
mask                          https://github.com/aaaaninja/asdf-mask.git
maven                         https://github.com/halcyon/asdf-maven.git
mc                            https://github.com/penpyt/asdf-mc.git
mdbook                        https://github.com/cipherstash/asdf-mdbook.git
mdbook-linkcheck              https://github.com/cipherstash/asdf-mdbook-linkcheck.git
melt                          https://github.com/chessmango/asdf-melt.git
memcached                     https://github.com/furkanural/asdf-memcached
mercury                       https://github.com/susurri/asdf-mercury.git
meson                         https://github.com/asdf-community/asdf-meson.git
micronaut                     https://github.com/weibemoura/asdf-micronaut.git
mill                          https://github.com/asdf-community/asdf-mill.git
minify                        https://github.com/axilleas/asdf-minify
minikube                      https://github.com/alvarobp/asdf-minikube.git
minio                         https://github.com/aeons/asdf-minio.git
minishift                     https://github.com/sqtran/asdf-minishift.git
mint                          https://github.com/mint-lang/asdf-mint
mitmproxy                     https://github.com/NeoHsu/asdf-mitmproxy.git
mkcert                        https://github.com/salasrod/asdf-mkcert.git
mlton                         https://github.com/asdf-community/asdf-mlton.git
mockery                       https://github.com/cabify/asdf-mockery.git
mongo-tools                   https://github.com/itspngu/asdf-mongo-tools.git
mongodb                       https://github.com/sylph01/asdf-mongodb.git
mongosh                       https://github.com/itspngu/asdf-mongosh.git
mutanus                       https://github.com/SoriUR/asdf-mutanus.git
mvnd                          https://github.com/joschi/asdf-mvnd.git
mysql                         https://github.com/iroddis/asdf-mysql.git
nancy                         https://github.com/iilyak/asdf-nancy.git
nano                          https://github.com/mfakane/asdf-nano.git
nasm                          https://github.com/Dpbm/asdf-nasm.git
neko                          https://github.com/asdf-community/asdf-neko.git
neovim                        https://github.com/richin13/asdf-neovim.git
nerdctl                       https://github.com/dmpe/asdf-nerdctl
newrelic-cli                  https://github.com/NeoHsu/asdf-newrelic-cli.git
nfpm                          https://github.com/ORCID/asdf-nfpm
nim                           https://github.com/asdf-community/asdf-nim.git
ninja                         https://github.com/asdf-community/asdf-ninja.git
nodejs                       *https://github.com/asdf-vm/asdf-nodejs.git
nomad                         https://github.com/asdf-community/asdf-hashicorp.git
nova                          https://github.com/elementalvoid/asdf-nova.git
nsc                           https://github.com/dex4er/asdf-nsc.git
oapi-codegen                  https://github.com/dylanrayboss/asdf-oapi-codegen.git
oc                            https://github.com/sqtran/asdf-oc.git
ocaml                         https://github.com/asdf-community/asdf-ocaml.git
oci                           https://github.com/yasn77/asdf-oci.git
odin                          https://github.com/jtakakura/asdf-odin
odo                           https://github.com/rm3l/asdf-odo.git
okta-aws-cli                  https://github.com/bennythejudge/asdf-plugin-okta-aws-cli.git
okteto                        https://github.com/BradenM/asdf-okteto
om                            https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
opa                           https://github.com/tochukwuvictor/asdf-opa.git
opam                          https://github.com/asdf-community/asdf-opam.git
openfaas-faas-cli             https://github.com/zekker6/asdf-faas-cli.git
openresty                     https://github.com/smashedtoatoms/asdf-openresty.git
opensearch                    https://github.com/randikabanura/asdf-opensearch.git
opensearch-cli                https://github.com/iul1an/asdf-opensearch-cli.git
openshift-install             https://github.com/hhemied/asdf-openshift-install.git
operator-sdk                  https://github.com/Medium/asdf-operator-sdk.git
opsgenie-lamp                 https://github.com/ORCID/asdf-opsgenie-lamp
osm                           https://github.com/nlamirault/asdf-osm.git
osqueryi                      https://github.com/davidecavestro/asdf-osqueryi.git
pachctl                       https://github.com/abatilo/asdf-pachctl.git
packer                        https://github.com/asdf-community/asdf-hashicorp.git
patat                         https://github.com/airtonix/asdf-patat.git
pdm                           https://github.com/1oglop1/asdf-pdm
peco                          https://github.com/asdf-community/asdf-peco.git
perl                          https://github.com/ouest/asdf-perl.git
php                           https://github.com/asdf-community/asdf-php.git
pint                          https://github.com/sam-burrell/asdf-pint.git
pipectl                       https://github.com/pipe-cd/asdf-pipectl.git
pipx                          https://github.com/joe733/asdf-pipx.git
pivnet                        https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
please                        https://github.com/asdf-community/asdf-please.git
pluto                         https://github.com/FairwindsOps/asdf-pluto.git
pnpm                          https://github.com/jonathanmorley/asdf-pnpm.git
poetry                        https://github.com/asdf-community/asdf-poetry.git
polaris                       https://github.com/particledecay/asdf-polaris.git
popeye                        https://github.com/nlamirault/asdf-popeye.git
postgres                      https://github.com/smashedtoatoms/asdf-postgres.git
powerline-go                  https://github.com/dex4er/asdf-powerline-go.git
powershell-core               https://github.com/daveneeley/asdf-powershell-core.git
pre-commit                    https://github.com/jonathanmorley/asdf-pre-commit.git
protoc                        https://github.com/paxosglobal/asdf-protoc.git
protoc-gen-go                 https://github.com/pbr0ck3r/asdf-protoc-gen-go.git
protoc-gen-go-grpc            https://github.com/pbr0ck3r/asdf-protoc-gen-go-grpc.git
protoc-gen-grpc-web           https://github.com/pbr0ck3r/asdf-protoc-gen-grpc-web.git
protoc-gen-js                 https://github.com/pbr0ck3r/asdf-protoc-gen-js.git
protolint                     https://github.com/spencergilbert/asdf-protolint.git
protonge                      https://github.com/augustobmoura/asdf-protonge.git
psc-package                   https://github.com/nsaunders/asdf-psc-package.git
pulumi                        https://github.com/canha/asdf-pulumi.git
purerl                        https://github.com/GoNZooo/asdf-purerl.git
purescript                    https://github.com/nsaunders/asdf-purescript.git
purty                         https://github.com/nsaunders/asdf-purty.git
python                       *https://github.com/danhper/asdf-python.git
qdns                          https://github.com/moritz-makandra/asdf-plugin-qdns.git
quarkus                       https://github.com/asdf-community/asdf-quarkus.git
rabbitmq                      https://github.com/w-sanches/asdf-rabbitmq.git
racket                        https://github.com/asdf-community/asdf-racket.git
raku                          https://github.com/m-dango/asdf-raku.git
rancher                       https://github.com/abinet/asdf-rancher.git
rbac-lookup                   https://github.com/looztra/asdf-rbac-lookup.git
rclone                        https://github.com/johnlayton/asdf-rclone.git
rebar                         https://github.com/Stratus3D/asdf-rebar.git
reckoner                      https://github.com/FairwindsOps/asdf-reckoner.git
redis                         https://github.com/smashedtoatoms/asdf-redis.git
redis-cli                     https://github.com/NeoHsu/asdf-redis-cli.git
redo                          https://github.com/chessmango/asdf-redo.git
redskyctl                     https://github.com/sudermanjr/asdf-redskyctl.git
reg                           https://github.com/looztra/asdf-reg.git
regctl                        https://github.com/ORCID/asdf-regctl.git
restic                        https://github.com/xataz/asdf-restic
revive                        https://github.com/bjw-s/asdf-revive.git
richgo                        https://github.com/paxosglobal/asdf-richgo.git
riff                          https://github.com/abinet/asdf-riff.git
ripgrep                       https://gitlab.com/wt0f/asdf-ripgrep.git
rke                           https://github.com/particledecay/asdf-rke.git
rlwrap                        https://github.com/asdf-community/asdf-rlwrap.git
rome                          https://github.com/kichiemon/asdf-rome.git
rstash                        https://github.com/carlduevel/asdf-rstash.git
ruby                          https://github.com/asdf-vm/asdf-ruby.git
rust                          https://github.com/code-lever/asdf-rust.git
rust-analyzer                 https://github.com/Xyven1/asdf-rust-analyzer
rye                           https://github.com/Azuki-bar/asdf-rye
saml2aws                      https://github.com/elementalvoid/asdf-saml2aws.git
sbcl                          https://github.com/smashedtoatoms/asdf-sbcl.git
sbt                           https://github.com/bram2000/asdf-sbt.git
scala                         https://github.com/asdf-community/asdf-scala.git
scaleway-cli                  https://github.com/albarralnunez/asdf-plugin-scaleway-cli
scalingo-cli                  https://github.com/brandon-welsch/asdf-scalingo-cli.git
scarb                         https://github.com/software-mansion/asdf-scarb.git
sccache                       https://github.com/emersonmx/asdf-sccache.git
scenery                       https://github.com/skyzyx/asdf-scenery.git
schemacrawler                 https://github.com/davidecavestro/asdf-schemacrawler.git
seed7                         https://github.com/susurri/asdf-seed7.git
semgrep                       https://github.com/brentjanderson/asdf-semgrep.git
semtag                        https://github.com/junminahn/asdf-semtag
semver                        https://github.com/mathew-fleisch/asdf-semver.git
sentinel                      https://github.com/asdf-community/asdf-hashicorp.git
serf                          https://github.com/asdf-community/asdf-hashicorp.git
serverless                    https://github.com/pdemagny/asdf-serverless.git
shell2http                    https://github.com/ORCID/asdf-shell2http.git
shellcheck                    https://github.com/luizm/asdf-shellcheck.git
shellspec                     https://github.com/poikilotherm/asdf-shellspec.git
shfmt                         https://github.com/luizm/asdf-shfmt.git
sinker                        https://github.com/elementalvoid/asdf-sinker.git
skaffold                      https://github.com/nklmilojevic/asdf-skaffold.git
skate                         https://github.com/chessmango/asdf-skate.git
sloth                         https://github.com/slok/asdf-sloth.git
smithy                        https://github.com/aws/asdf-smithy.git
smlnj                         https://github.com/samontea/asdf-smlnj.git
snyk                          https://github.com/nirfuchs/asdf-snyk.git
soft-serve                    https://github.com/chessmango/asdf-soft-serve.git
solidity                      https://github.com/diegodorado/asdf-solidity.git
sops                          https://github.com/feniix/asdf-sops.git
sopstool                      https://github.com/elementalvoid/asdf-sopstool.git
soracom                       https://github.com/grimoh/asdf-soracom.git
sourcery                      https://github.com/younke/asdf-sourcery.git
spacectl                      https://github.com/bodgit/asdf-spacectl.git
spago                         https://github.com/nsaunders/asdf-spago.git
spark                         https://github.com/joshuaballoch/asdf-spark.git
spectral                      https://github.com/vbyrd/asdf-spectral.git
spin                          https://github.com/pavloos/asdf-spin.git
spring-boot                   https://github.com/joschi/asdf-spring-boot.git
spruce                        https://github.com/woneill/asdf-spruce.git
sqldef                        https://github.com/cometkim/asdf-sqldef.git
sqlite                        https://github.com/cLupus/asdf-sqlite.git
sshuttle                      https://github.com/xanmanning/asdf-sshuttle.git
stack                         https://github.com/sestrella/asdf-ghcup.git
starboard                     https://github.com/zufardhiyaulhaq/asdf-starboard.git
starport                      https://github.com/nikever/asdf-starport.git
starship                      https://github.com/grimoh/asdf-starship.git
steampipe                     https://github.com/carnei-ro/asdf-steampipe.git
step                          https://github.com/log2/asdf-step.git
stern                         https://github.com/looztra/asdf-stern.git
stripe-cli                    https://github.com/offbyone/asdf-stripe.git
stylua                        https://github.com/jc00ke/asdf-stylua.git
svu                           https://github.com/asdf-community/asdf-svu
swag                          https://github.com/behoof4mind/asdf-swag.git
swift                         https://github.com/fcrespo82/asdf-swift.git
swiftformat                   https://github.com/younke/asdf-swiftformat.git
swiftgen                      https://github.com/younke/asdf-swiftgen.git
swiftlint                     https://github.com/klundberg/asdf-swiftlint.git
swiprolog                     https://github.com/mracos/asdf-swiprolog.git
syft                          https://github.com/davidgp1701/asdf-syft.git
syncher                       https://github.com/nwillc/syncher.git
talhelper                     https://github.com/bjw-s/asdf-talhelper
talos                         https://github.com/particledecay/asdf-talos.git
talosctl                      https://github.com/bjw-s/asdf-talosctl
tanka                         https://github.com/trotttrotttrott/asdf-tanka.git
task                          https://github.com/particledecay/asdf-task.git
tctl                          https://github.com/eko/asdf-tctl.git
tekton-cli                    https://github.com/johnhamelink/asdf-tekton-cli.git
teleport-community            https://github.com/MaloPolese/asdf-teleport-community
teleport-ent                  https://github.com/highb/asdf-teleport-ent
telepresence                  https://github.com/pirackr/asdf-telepresence.git
teller                        https://github.com/pdemagny/asdf-teller
temporalite                   https://github.com/eko/asdf-temporalite.git
terradozer                    https://github.com/chessmango/asdf-terradozer.git
terraform                     https://github.com/asdf-community/asdf-hashicorp.git
terraform-docs                https://github.com/looztra/asdf-terraform-docs.git
terraform-ls                  https://github.com/asdf-community/asdf-hashicorp.git
terraform-lsp                 https://github.com/bartlomiejdanek/asdf-terraform-lsp.git
terraform-validator           https://github.com/looztra/asdf-terraform-validator.git
terraformer                   https://github.com/grimoh/asdf-terraformer.git
terragrunt                    https://github.com/ohmer/asdf-terragrunt.git
terramate                     https://github.com/martinlindner/asdf-terramate.git
terrascan                     https://github.com/hpdobrica/asdf-terrascan.git
tf-summarize                  https://github.com/adamcrews/asdf-tf-summarize.git
tfc-agent                     https://github.com/asdf-community/asdf-hashicorp.git
tfctl                         https://github.com/deas/asdf-tfctl
tfenv                         https://github.com/carlduevel/asdf-tfenv.git
tflint                        https://github.com/skyzyx/asdf-tflint.git
tfmigrate                     https://github.com/dex4er/asdf-tfmigrate.git
tfnotify                      https://github.com/jnavarrof/asdf-tfnotify.git
tfsec                         https://github.com/woneill/asdf-tfsec.git
tfstate-lookup                https://github.com/carnei-ro/asdf-tfstate-lookup.git
tfswitch                      https://github.com/iul1an/asdf-tfswitch.git
tfupdate                      https://github.com/yuokada/asdf-tfupdate.git
thrift                        https://github.com/alisaifee/asdf-thrift.git
tilt                          https://github.com/eaceaser/asdf-tilt.git
timoni                        https://github.com/Smana/asdf-timoni.git
titan                         https://github.com/gabitchov/asdf-titan.git
tlsg-cli                      https://github.com/0ghny/asdf-tlsgcli.git
tmux                          https://github.com/aphecetche/asdf-tmux.git
tokei                         https://github.com/gasuketsu/asdf-tokei.git
tomcat                        https://github.com/mbutov/asdf-tomcat
tonnage                       https://github.com/elementalvoid/asdf-tonnage.git
tool-versions-to-env          https://github.com/smartcontractkit/tool-versions-to-env-action.git
trdsql                        https://github.com/johnlayton/asdf-trdsql.git
tree-sitter                   https://github.com/ivanvc/asdf-tree-sitter.git
tridentctl                    https://github.com/asdf-community/asdf-tridentctl.git
trivy                         https://github.com/zufardhiyaulhaq/asdf-trivy.git
tsuru                         https://github.com/virtualstaticvoid/asdf-tsuru.git
ttyd                          https://github.com/ivanvc/asdf-ttyd.git
tuist                         https://github.com/cprecioso/asdf-tuist.git
tx                            https://github.com/ORCID/asdf-transifex.git
typos                         https://github.com/aschiavon91/asdf-typos.git
uaa-cli                       https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf.git
unison                        https://github.com/susurri/asdf-unison.git
upt                           https://github.com/ORCID/asdf-upt.git
upx                           https://github.com/jimmidyson/asdf-upx.git
usql                          https://github.com/itspngu/asdf-usql.git
v                             https://github.com/jthegedus/asdf-v.git
vale                          https://github.com/pdemagny/asdf-vale
vals                          https://github.com/dex4er/asdf-vals.git
vault                         https://github.com/asdf-community/asdf-hashicorp.git
vcluster                      https://gitlab.com/wt0f/asdf-vcluster.git
vela                          https://github.com/pdemagny/asdf-vela
velad                         https://github.com/pdemagny/asdf-velad
velero                        https://github.com/looztra/asdf-velero.git
vendir                        https://github.com/vmware-tanzu/asdf-carvel.git
venom                         https://github.com/aabouzaid/asdf-venom.git
vhs                           https://github.com/chessmango/asdf-vhs.git
viddy                         https://github.com/ryodocx/asdf-viddy.git
vim                           https://github.com/tsuyoshicho/asdf-vim.git
vultr-cli                     https://github.com/ikuradon/asdf-vultr-cli.git
wasi-sdk                      https://github.com/coolreader18/asdf-wasi-sdk.git
wasm3                         https://github.com/tachyonicbytes/asdf-wasm3
wasm4                         https://github.com/jtakakura/asdf-wasm4
wasmer                        https://github.com/tachyonicbytes/asdf-wasmer
wasmtime                      https://github.com/tachyonicbytes/asdf-wasmtime
watchexec                     https://github.com/nyrst/asdf-watchexec.git
waypoint                      https://github.com/asdf-community/asdf-hashicorp.git
weave-gitops                  https://github.com/deas/asdf-weave-gitops
websocat                      https://github.com/bdellegrazie/asdf-websocat.git
wren-cli                      https://github.com/jtakakura/asdf-wren-cli.git
wrk                           https://github.com/ivanvc/asdf-wrk.git
wtfutil                       https://github.com/NeoHsu/asdf-wtfutil.git
xc                            https://github.com/airtonix/asdf-xc
xchtmlreport                  https://github.com/younke/asdf-xchtmlreport.git
xcodegen                      https://github.com/younke/asdf-xcodegen.git
xcodes                        https://github.com/younke/asdf-xcodes.git
xh                            https://github.com/NeoHsu/asdf-xh
yadm                          https://github.com/particledecay/asdf-yadm.git
yamlfmt                       https://github.com/kachick/asdf-yamlfmt.git
yamllint                      https://github.com/ericcornelissen/asdf-yamllint.git
yarn                          https://github.com/twuni/asdf-yarn.git
yay                           https://github.com/aaaaninja/asdf-yay.git
yj                            https://github.com/ryodocx/asdf-yj.git
yor                           https://github.com/ordinaryexperts/asdf-yor
youtube-dl                    https://github.com/iul1an/asdf-youtube-dl
yq                            https://github.com/sudermanjr/asdf-yq.git
ytt                           https://github.com/vmware-tanzu/asdf-carvel.git
zbctl                         https://github.com/camunda-community-hub/asdf-zbctl.git
zellij                        https://github.com/chessmango/asdf-zellij.git
zephyr                        https://github.com/nsaunders/asdf-zephyr.git
zig                           https://github.com/cheetah/asdf-zig.git
zigmod                        https://github.com/kachick/asdf-zigmod.git
zola                          https://github.com/salasrod/asdf-zola.git
zoxide                        https://github.com/nyrst/asdf-zoxide
zprint                        https://github.com/carlduevel/asdf-zprint.git
$ asdf plugin add python
$ asdf list all python
2.1.3
2.2.3
2.3.7
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
2.5.5
2.5.6
2.6.0
2.6.1
2.6.2
2.6.3
2.6.4
2.6.5
2.6.6
2.6.7
2.6.8
2.6.9
2.7.0
2.7-dev
2.7.1
2.7.2
2.7.3
2.7.4
2.7.5
2.7.6
2.7.7
2.7.8
2.7.9
2.7.10
2.7.11
2.7.12
2.7.13
2.7.14
2.7.15
2.7.16
2.7.17
2.7.18
3.0.1
3.1.0
3.1.1
3.1.2
3.1.3
3.1.4
3.1.5
3.2.0
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.2.6
3.3.0
3.3.1
3.3.2
3.3.3
3.3.4
3.3.5
3.3.6
3.3.7
3.4.0
3.4-dev
3.4.1
3.4.2
3.4.3
3.4.4
3.4.5
3.4.6
3.4.7
3.4.8
3.4.9
3.4.10
3.5.0
3.5-dev
3.5.1
3.5.2
3.5.3
3.5.4
3.5.5
3.5.6
3.5.7
3.5.8
3.5.9
3.5.10
3.6.0
3.6-dev
3.6.1
3.6.2
3.6.3
3.6.4
3.6.5
3.6.6
3.6.7
3.6.8
3.6.9
3.6.10
3.6.11
3.6.12
3.6.13
3.6.14
3.6.15
3.7.0
3.7-dev
3.7.1
3.7.2
3.7.3
3.7.4
3.7.5
3.7.6
3.7.7
3.7.8
3.7.9
3.7.10
3.7.11
3.7.12
3.7.13
3.7.14
3.7.15
3.7.16
3.7.17
3.8.0
3.8-dev
3.8.1
3.8.2
3.8.3
3.8.4
3.8.5
3.8.6
3.8.7
3.8.8
3.8.9
3.8.10
3.8.11
3.8.12
3.8.13
3.8.14
3.8.15
3.8.16
3.8.17
3.9.0
3.9-dev
3.9.1
3.9.2
3.9.4
3.9.5
3.9.6
3.9.7
3.9.8
3.9.9
3.9.10
3.9.11
3.9.12
3.9.13
3.9.14
3.9.15
3.9.16
3.9.17
3.10.0
3.10-dev
3.10.1
3.10.2
3.10.3
3.10.4
3.10.5
3.10.6
3.10.7
3.10.8
3.10.9
3.10.10
3.10.11
3.10.12
3.11.0
3.11-dev
3.11.1
3.11.2
3.11.3
3.11.4
3.12.0b4
3.12-dev
3.13-dev
....    ....
....    ....
....    ....
....    ....
....    ....
....    ....
....    ....
....    ....

Pythonの依存バッケージをインストールする。

$ sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
% brew install openssl readline sqlite3 xz zlib tcl-tk

使用する予定のバージョンをインストールする。

$ asdf install python 3.8.17
$ asdf install python 3.9.17
$ asdf install python 3.10.12
$ asdf install python 3.11.4
$ asdf reshim
$ asdf list python
  3.10.12
  3.11.4
  3.8.17
  3.9.17

Pythonバージョンの設定

グローバルなバージョンを設定

$ asdf global python 3.8.17
$ cd
$ python --version
Python 3.8.17

プロジェクトのローカルバージョンを設定

$ cd PROJECT_DIR
$ asdf local python 3.8.17
$ python --version
Python 3.8.17

asdf + PoetryによるPython仮想環境構築

$ mkdir PROJECT_DIR
$ cd PROJECT_DIR
$ asdf local python 3.10.12
$ poetry init
Configuration file exists at /Users/LOGNAME/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/LOGNAME/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.

This command will guide you through creating your pyproject.toml config.

Package name [project_dir]:
Version [0.1.0]:
Description []:
Author [vedfolnir-k9 <vedfolnir@ketus-ix.work>, n to skip]:
License []:
Compatible Python versions [^3.11]:  >=3.8,<3.11

Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file

[tool.poetry]
name = "project-dir"
version = "0.1.0"
description = ""
authors = ["vedfolnir-k9 <vedfolnir@ketus-ix.work>"]
readme = "README.md"
packages = [{include = "project_dir"}]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes]
$ poetry install
Configuration file exists at /Users/LOGNAME/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/LOGNAME/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
The currently activated Python version 3.11.4 is not supported by the project (>=3.8,<3.11).
Trying to find and use a compatible version.
Using python3 (3.10.12)
Creating virtualenv project-dir2 in /Users/LOGNAME/PROJECT_DIR/.venv
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file
/Users/LOGNAME/PROJECT_DIR/project_dir does not contain any element

【補足情報】anyenvのアンイストール

anyenvを無効にする

Ubuntu

$ vi ~/.bashrc
-export PATH="$HOME/.anyenv/bin:$PATH"
-eval "$(anyenv init -)"
$ source ~/.bashrc
$ vi ~/.zshrc
-export PATH="$HOME/.anyenv/bin:$PATH"
-eval "$(anyenv init -)"
$ source ~/.zshrc

Mac

$ vi ~/.bashrc
-eval "$(anyenv init -)"
$ source ~/.bashrc
% vi ~/.zshrc
-eval "$(anyenv init -)"
% source ~/.zshrc

anyenvをアンイストールする

$ rm -rf ~/.anyenv
% brew uninstall anyenv
% rm -rf ~/.anyenv

【追記】〔2024-04-25〕

備忘録を兼ねて、asdfの使いそうなコマンドを書いておく。

プロジェクトの言語バージョン確認

cd PROJECT_DIR
asdf current

インストール済み言語バージョンの削除

asdf uninstall python 3.8.17

インストール済みプラグインの削除

asdf plugin remove python

インストール済みプラグインの一覧表示

asdf plugin list

インストール済み全プラグイン情報の更新

asdf plugin update --all

特定のインストール済みプラグイン情報の更新

asdf plugin update python

特定の言語バージョンを使ってシェルを起動する

asdf shell python 3.9.17

asdfの更新

asdf update
brew upgrade asdf

【Python】anyenv + pyenv + Poetryによる仮想環境構築

日常的にPythonでプログラミングしているが、開発対象のプログラムやプロジェクトによって使用するPythonのバージョンを変えなればならないケースが多いので、ほとんどの人がそうしているだろうが、私もPythonでの開発は仮想環境でしかやらない。

Pythonの仮想環境ツールとして、最初の頃はpipenvを利用していたがいまはPoetryを利用している。また、複数の言語を使ってプログラミングするので、言語バージョン管理ツールとしてanyenvとpyenvも併用している。

python-poetry.org

github.com

github.com

自分の備忘録を兼ねて、anyenv + pyenv + Poetryを利用してPython仮想環境を構築する手順を要点だけに絞って本記事に書いておく。いずれのツールもリファレンス的記事はたくさん存在するので、各ツールの詳しい使い方はそれらの記事に譲る。

anyenvのインストール

$ git clone https://github.com/anyenv/anyenv ~/.anyenv
% brew install anyenv

anyenvのコマンドパスを設定

Ubuntu

$ echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(anyenv init -)"' >> ~/.bashrc
% echo 'export PATH="$HOME/.anyenv/bin:$PATH"' >> ~/.zshrc
% echo 'eval "$(anyenv init -)"' >> ~/.zshrc

Mac

$ echo 'eval "$(anyenv init -)"' >> ~/.bashrc
% echo 'eval "$(anyenv init -)"' >> ~/.zshrc

anyenvの初期化とプラグインの追加

$ exec $SHELL -l
$ anyenv --version
$ anyenv install --init
Manifest directory doesn't exist: /home/LOGNAME/.config/anyenv/anyenv-install
Do you want to checkout https://github.com/anyenv/anyenv-install.git? [y/N]: y
Cloning https://github.com/anyenv/anyenv-install.git master to /home/LOGNAME/.config/anyenv/anyenv-install...
Cloning into '/home/USERNAME/.config/anyenv/anyenv-install'...
....    ....
....    ....

Completed!
$ mkdir -p $(anyenv root)/plugins
$ git clone https://github.com/znz/anyenv-update.git $(anyenv root)/plugins/anyenv-update
$ git clone https://github.com/znz/anyenv-git.git $(anyenv root)/plugins/anyenv-git
$ anyenv commands
commands
completions
envs
git
global
help
init
install
local
root
uninstall
update
--version
version
versions

anyenvによるpyenvのインストール

$ anyenv install --list
  Renv
  crenv
  denv
  erlenv
  exenv
  goenv
  hsenv
  jenv
  jlenv
  kubectlenv
  luaenv
  nodenv
  phpenv
  plenv
  pyenv
  rbenv
  sbtenv
  scalaenv
  swiftenv
  tfenv
$ anyenv install pyenv
$ exec $SHELL -l
$ pyenv --version

pyenvによるPythonのインストール

% pyenv install --list
Available versions:
  2.1.3
  2.2.3
  2.3.7
  2.4.0
  2.4.1
  2.4.2
  2.4.3
  2.4.4
  2.4.5
  2.4.6
  2.5.0
  2.5.1
  2.5.2
  2.5.3
  2.5.4
  2.5.5
  2.5.6
  2.6.0
  2.6.1
  2.6.2
  2.6.3
  2.6.4
  2.6.5
  2.6.6
  2.6.7
  2.6.8
  2.6.9
  2.7.0
  2.7-dev
  2.7.1
  2.7.2
  2.7.3
  2.7.4
  2.7.5
  2.7.6
  2.7.7
  2.7.8
  2.7.9
  2.7.10
  2.7.11
  2.7.12
  2.7.13
  2.7.14
  2.7.15
  2.7.16
  2.7.17
  2.7.18
  3.0.1
  3.1.0
  3.1.1
  3.1.2
  3.1.3
  3.1.4
  3.1.5
  3.2.0
  3.2.1
  3.2.2
  3.2.3
  3.2.4
  3.2.5
  3.2.6
  3.3.0
  3.3.1
  3.3.2
  3.3.3
  3.3.4
  3.3.5
  3.3.6
  3.3.7
  3.4.0
  3.4-dev
  3.4.1
  3.4.2
  3.4.3
  3.4.4
  3.4.5
  3.4.6
  3.4.7
  3.4.8
  3.4.9
  3.4.10
  3.5.0
  3.5-dev
  3.5.1
  3.5.2
  3.5.3
  3.5.4
  3.5.5
  3.5.6
  3.5.7
  3.5.8
  3.5.9
  3.5.10
  3.6.0
  3.6-dev
  3.6.1
  3.6.2
  3.6.3
  3.6.4
  3.6.5
  3.6.6
  3.6.7
  3.6.8
  3.6.9
  3.6.10
  3.6.11
  3.6.12
  3.6.13
  3.6.14
  3.6.15
  3.7.0
  3.7-dev
  3.7.1
  3.7.2
  3.7.3
  3.7.4
  3.7.5
  3.7.6
  3.7.7
  3.7.8
  3.7.9
  3.7.10
  3.7.11
  3.7.12
  3.7.13
  3.7.14
  3.7.15
  3.7.16
  3.7.17
  3.8.0
  3.8-dev
  3.8.1
  3.8.2
  3.8.3
  3.8.4
  3.8.5
  3.8.6
  3.8.7
  3.8.8
  3.8.9
  3.8.10
  3.8.11
  3.8.12
  3.8.13
  3.8.14
  3.8.15
  3.8.16
  3.8.17
  3.9.0
  3.9-dev
  3.9.1
  3.9.2
  3.9.4
  3.9.5
  3.9.6
  3.9.7
  3.9.8
  3.9.9
  3.9.10
  3.9.11
  3.9.12
  3.9.13
  3.9.14
  3.9.15
  3.9.16
  3.9.17
  3.10.0
  3.10-dev
  3.10.1
  3.10.2
  3.10.3
  3.10.4
  3.10.5
  3.10.6
  3.10.7
  3.10.8
  3.10.9
  3.10.10
  3.10.11
  3.10.12
  3.11.0
  3.11-dev
  3.11.1
  3.11.2
  3.11.3
  3.11.4
  3.12.0b4
  3.12-dev
  3.13-dev
  ....    ....
  ....    ....
  ....    ....
  ....    ....
  ....    ....
  ....    ....
  ....    ....
  ....    ....

使用する予定のバージョンをインストールしておく。

$ pyenv install 3.8.17
$ pyenv install 3.9.17
$ pyenv install 3.10.12
$ pyenv install 3.11.4
$ pyenv rehash
$ pyenv versions
* system (set by /home/USERNAME/.anyenv/envs/pyenv/version)
  3.8.17
  3.9.17
  3.10.12
  3.11.4

pyenvによるPythonインストール時の補足情報

Ubuntuで、anyenvによってPythonをインストールするときに、以下のようなエラーが表示されることがある。

$ pyenv install 3.8.17
....    ....
....    ....
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'readline'
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
....    ....
....    ....

その場合は、以下のコマンドを実行すれば解決できる。

$ sudo apt install -y libbz2-dev libreadline-dev libssl-dev
$ pyenv install 3.8.17

Ubuntuで、anyenvによってPythonをインストールするときに、以下のような警告が表示されることがある。

$ pyenv install 3.8.17
....    ....
....    ....
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/home/USERNAME/anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.8.17 to /home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17

その場合は、以下のコマンドを実行すれば解決できる。

$ pyenv uninstall 3.8.17
$ sudo apt install -y libsqlite3-dev
$ pyenv install 3.8.17

UbuntuまたはMacで、anyenvによってPythonをインストールするときに、以下のような警告が表示されることがある。

$ pyenv install 3.8.17
....    ....
....    ....
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/tkinter/__init__.py", line 36, in <module>
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
WARNING: The Python tkinter extension was not compiled and GUI subsystem has been detected. Missing the Tk toolkit?
Installed Python-3.8.17 to /home/USERNAME/.ayenv/envs/pyenv/versions/3.8.17

その場合は、以下のコマンドを実行すれば解決できる。

$ pyenv uninstall 3.8.17
$ sudo apt install -y python3-tk tk-dev
$ pyenv install 3.8.17
% pyenv uninstall 3.8.17
% brew install python-tk
% pyenv install 3.8.17

UbuntuまたはMacでanyenvによってPythonをインストールするときに、下のような警告が表示されることがある。

$ pyenv install 3.8.17
....    ....
....    ....
python-build: use zlib from xcode sdk
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17/lib/python3.8/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Installed Python-3.8.17 to /home/USERNAME/.anyenv/envs/pyenv/versions/3.8.17

その場合は、以下のコマンドを実行すれば解決できる。

$ pyenv uninstall 3.8.17
$ sudo apt install -y liblzma-dev
$ pyenv install 3.8.17
% pyenv uninstall 3.8.17
% brew install xz
% pyenv install 3.8.17

Pythonバージョンの設定

グローバルなバージョンを設定

$ pyenv global 3.8.17
$ cd
$ python --version
Python 3.8.17

プロジェクトのローカルバージョンを設定

$ cd PROJECT_DIR
$ pyenv local 3.8.17
$ python --version
Python 3.8.17

Poetryのインストール

$ curl -sSL https://install.python-poetry.org | python3 -
$ echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
$ source ~/.bashrc
$ poetry --version
Poetry (version 1.5.1)
% brew install poetry
% poetry --version
Poetry (version 1.5.1)

プロジェクトディレクトリ内に仮想環境を構築するように設定

$ poetry config virtualenvs.in-project true
$ poetry config --list
....    ....
virtualenvs.in-project = true
....    ....

pyenv + PoetryによるPython仮想環境構築

プロジェクトの作成・初期化

$ mkdir PROJECT_DIR
$ cd PROJECT_DIR
$ pyenv local 3.10.12
$ python --vresion
Python 3.10.12
$ poetry init
Configuration file exists at /Users/LOGNAME/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/LOGNAME/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.

This command will guide you through creating your pyproject.toml config.

Package name [project_dir]:
Version [0.1.0]:
Description []:
Author [vedfolnir-k9 <vedfolnir@ketus-ix.work>, n to skip]:
License []:
Compatible Python versions [^3.11]:  >=3.8,<3.11

Would you like to define your main dependencies interactively? (yes/no) [yes] no
Would you like to define your development dependencies interactively? (yes/no) [yes] no
Generated file

[tool.poetry]
name = "project-dir"
version = "0.1.0"
description = ""
authors = ["vedfolnir-k9 <vedfolnir@ketus-ix.work>"]
readme = "README.md"
packages = [{include = "project_dir"}]

[tool.poetry.dependencies]
python = ">=3.8,<3.11"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


Do you confirm generation? (yes/no) [yes]

プロンプトCompatible Python versions [^3.11]:に対する入力は、以下のような意味になる。

  • ^3.11

3.11 ≦ プログラムのPython依存バージョン < 4.0

  • >=3.8,<3.11

3.8 ≦ プログラムのPython依存バージョン ≦ 3.10

仮想環境の初期化

$ poetry install
Configuration file exists at /Users/LOGNAME/Library/Preferences/pypoetry, reusing this directory.

Consider moving TOML configuration files to /Users/LOGNAME/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
The currently activated Python version 3.11.4 is not supported by the project (>=3.8,<3.11).
Trying to find and use a compatible version.
Using python3 (3.10.12)
Creating virtualenv project-dir2 in /Users/LOGNAME/PROJECT_DIR/.venv
Updating dependencies
Resolving dependencies... (0.1s)

Writing lock file
/Users/LOGNAME/PROJECT_DIR/project_dir does not contain any element

Poetryでのパッケージ管理

パッケージの追加

$ poerty add PACKAGE_NAME

パッケージの削除

$ poerty remove PACKAGE_NAME

開発用パッケージの追加

$ poerty add --dev PACKAGE_NAME

開発用パッケージの削除

$ poerty remove --dev PACKAGE_NAME

PoetryによるPythonプログラム実行

仮想環境によって直接プログラムを実行

$ poetry run python PROGRAM.py

仮想環境を起動して、プログラムを実行

$ poetry shell
$ python PROGRAM.py

補足情報

requirements.txtが存在する既存のPythonプログラムを利用する場合、Poetryによるプロジェクトディレクトリの作成・初期化後に以下のコマンドを実行するとすべての依存パッケージをインストールできる。

$ cat requirements.txt | xargs poetry add

【追記】〔2023-08-19〕

上には、pyenvによるPythonのインストール時に遭遇するエラーや警告の対処方法について個別に書いたが、これを一括で回避する方法がpyenvのサイトに掲載されていた。

コマンドpyenv install PYTHON_VERSIONを実行する前に、以下のコマンドによってPythonの依存バッケージをインストールしておけば良い。

$ sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
% brew install openssl readline sqlite3 xz zlib tcl-tk

【参照リンク】

github.com

DockerクラウドサービスPortainerを使い始めた

ググっているうちにたまたま見つけたのだが、Portainerというクラウドサービスが素晴らしかったので紹介したい。

PortainerはDockerコンテナをクラウド上で稼働運用できるサービスだ。

www.portainer.io

私もサーバーを使う開発ではDockerを利用することが多いが、実際ところ、ローカルPC上でDockerを使うのは結構面倒だったりする。いくつもコンテナを作るとディスク容量が圧迫されるし、コンテナを起動したまま停止し忘れると、PCのバッテリーの持ちが悪くなる。コンテナだけでなくDockerデーモンも停止しておかないと、 同様にバッテリーの減りが加速してしまう(Docker導入済みのPCでなんだか動作が遅いなぁとかバッテリーの減りが速いなぁと感じたら、最初にDockerを疑った方が良い)。

GCPやAzureなどのクラウドコンピューティングVPSサービスなどを利用してDockerサーバーを設置するという手もあるが、OSの導入から始めないといけないのが面倒だ。それに、これらの利用料はそこそこ高いし。Dockerコンテナをそのままクラウド上で稼働できる低額のサービスがあれば良いのにと思っていたが、Portainerがまさにそれだった。

ちなみに、PortainerにはPortainer-CE(Community Edition)というフリー版が存在する。これはローカルPC上でDockerコンテナを運用できるものだ。機能的には公式のDocker Desktopと同様のものだが、これよりずっと使いやすくてブラウザから操作できるのが良い。Docker Desktopを一定規模以上の企業で利用する場合有料サブスクリプションが必要になるが、Portainer-CEは無償で使い続けることができる。

以降では、このPortainer-CEのインストール方法と使い方を説明していく。

Portainerのインストール

最初に、Portainer用のデータ・ディレクトリを作成しておく。このディレクトリには、Portainerのログイン情報やコンテナのデータベース情報などが格納される。

% mkdir portainer_data

Portainer-CEをインストールするには、下のコマンドを実行すれば良い。

% docker run -d -p 8000:8000 -p 9000:9000 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

このコマンドは、Docker Hub上に存在するportainer-ceというコンテナを取得してDockerコンテナを生成・起動している。

hub.docker.com

なお、上記のコマンドを実行したときに、下のようなエラーが表示されることがある。

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

これはDockerデーモンが起動していないという意味なので、その場合は、Docker Desktopを起動した上で再度上記のコマンドを実行すれば良い。

Portainerコンテナの起動後、ブラウザからhttp://localhost:9000にアクセスすると、下のような画面が表示される。

[Username]と[Password]に適当な値を入力すると(Portainer-CEはローカル稼働なので、これらはどんな値でも問題ない)、下のような画面になる。

ここで[Get Started]を選択すると、Portainerの管理画面が表示される。

この画面で、Portainer自身がコンテナとして起動していることが判る。

Portainerの使い方

コンテナの作成は、上の画面の[ + Add container ]ボタンからできる。ただし、dockerコマンドに慣れているなら、そちらを使った方が楽だろう。例えば、下のようにコマンドを実行すれば、nginxによるWebサーバーのコンテナを作成できる。

% docker run -d -it -p 8080:80 --name nginx nginx

新しいコンテナが作成されると、Portainerの管理画面に反映される。

この画面から [nginx] > [Console] と辿って、[Connect] を押すと、起動中のコンテナのコンソール画面に入れる。

Portainerには、下のようなApp Templatesという名前のコンテナ・テンプレートが在って、これらを利用してコンテナを作成することもできる。

上で紹介したのはローカルPC上でコンテナを運用するPortainer-CEだが、同じ使い勝手でPortainerのクラウド上にコンテナを作成運用できるPortainer-BE(Business Edition)もある。このサービスの最低プランなら$149/年で15個のコンテナを作成できる(本記事執筆時点のプラン内容)。メジャーなクラウドコンピューティングVPSサービスと比べると、この価格は安いと思う。

Dockerを多用してバックエンド開発をするエンジニアにとって、Portainerは福音とも言えるクラウドコンピューティング・サービスではないだろうか。

【参照サイト】

qiita.com

stella_vslamのUbuntu 22.04でのビルド

前記事にstella_vslamのUbuntu 20.04でのビルド手順を書いたが、Ubutu 22.04でのビルドもやってみた。

blog.ketus-ix.work

Ubuntu 20.04の場合との相違点は一点だけなので、それを以下に書いておく。

stella_vslamのビルド依存パッケージの導入

OpenCVの依存パッケージ

$ sudo apt install -y libgtk-3-dev ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libtbb-dev

libavresample-devを削除した。このパッケージはUbuntu 22.04では利用できなくなっている。

stella_vslamとリンクされるライブラリのビルドとインストール

OpenCV

$ cd Depended_Builds
$ wget -q https://github.com/opencv/opencv/archive/4.8.0.zip
$ unzip -q 4.8.0.zip
# Download aruco module (optional)
$ wget -q https://github.com/opencv/opencv_contrib/archive/refs/tags/4.8.0.zip -O opencv_contrib-4.8.0.zip
$ unzip -q opencv_contrib-4.8.0.zip
$ mkdir opencv_extra && cd opencv_extra
$ ln -s ../opencv_contrib-4.8.0/modules/aruco .
$ cd ../opencv-4.8.0
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_DOCS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_OPENEXR=OFF \
    -DBUILD_PERF_TESTS=OFF \
    -DBUILD_TESTS=OFF \
    -DBUILD_PROTOBUF=OFF \
    -DBUILD_opencv_apps=OFF \
    -DBUILD_opencv_dnn=OFF \
    -DBUILD_opencv_ml=OFF \
    -DBUILD_opencv_python_bindings_generator=OFF \
    -DENABLE_CXX11=ON \
    -DENABLE_FAST_MATH=ON \
    -DWITH_EIGEN=ON \
    -DWITH_FFMPEG=ON \
    -DWITH_TBB=ON \
    -DWITH_OPENMP=ON \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_extra \
    ..
$ make -j4
$ sudo make install
$ sudo ldconfig

本記事執筆時点で最新バージョンのOpenCV 4.8.0で試してみた。こちらでもstella_vslamは問題なく動くことが確認できた。

なお、NVIDIA GPU搭載PCでCUDAが導入済みの場合、CUDA利用を有効にしてOpenCVをビルドすると、stella_vslamの実行速度が速くなる。以下にその方法を紹介しておく。

CUDA有効OpenCVのビルド(stella_vslam用)

gccのバージョンを確認して、バージョン10より大きければ、 gcc 10をインストールする。

$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ sudo apt install -y gcc-10 g++-10

OpenCVのcmakeオプションを下のように変える。

$ mkdir build2 && cd build2
$ cmake \
    -DCMAKE_C_COMPILER=/usr/bin/gcc-10 \
    -DCMAKE_CXX_COMPILER=/usr/bin/g++-10 \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_DOCS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_OPENEXR=OFF \
    -DBUILD_PERF_TESTS=OFF \
    -DBUILD_TESTS=OFF \
    -DBUILD_PROTOBUF=OFF \
    -DBUILD_opencv_apps=OFF \
    -DBUILD_opencv_dnn=OFF \
    -DBUILD_opencv_ml=OFF \
    -DBUILD_opencv_python_bindings_generator=OFF \
    -DENABLE_CXX11=ON \
    -DENABLE_FAST_MATH=ON \
    -DWITH_EIGEN=ON \
    -DWITH_FFMPEG=ON \
    -DWITH_TBB=ON \
    -DWITH_OPENMP=ON \
    -DWITH_CUDA=ON \
    -DWITH_NVCUID=ON \
    -DWITH_CUBLAS=ON \
    -DWITH_OPENCL=OFF \
    -DWITH_OPENGL=ON \
    -DCUDA_ARCH_BIN="8.6" \
    -DCUDA_ARCH_PTX="" \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.8.0/modules \
    ..
$ make -j4

オプションCUDA_ARCH_BINに指定する数値はGPUアーキテクチャ番号だが、これは下のサイトを参照して決める。

developer.nvidia.com

上記はあくまでOpenCV 4.8.0をUbuntu 22.04上でビルドする場合なので、他では違ってくるかもしれない。

【追記】〔2023-08-21〕

OpenCVのCUDA利用を有効にする場合、g2oも以下のように変更してビルドすることを薦める。

$ mkdir build2 && cd build2
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_UNITTESTS=OFF \
    -DG2O_USE_CHOLMOD=OFF \
    -DG2O_USE_CSPARSE=ON \
    -DG2O_USE_OPENGL=ON \
    -DG2O_USE_OPENMP=ON \
    -DG2O_BUILD_APPS=OFF \
    -DG2O_BUILD_EXAMPLES=OFF \
    -DG2O_BUILD_LINKED_APPS=OFF \
    ..
$ make -j4

stella_vslamのUbuntu 20.04でのビルド

本ブログの最初の記事でstella_vslam = OpenVSLAMのビルドについて書いたが、あれから1年経って、現在のstella_vslamの状況がどうなっているのか知りたくなった。

blog.ketus-ix.work

github.com

stella_vslamは産業技術総合研究所のOpenVSLAMのコミュニティフォークだが、いまではこちらの方が活動が活発で、OpenVSLAMと言えば、現在ではstella_vslamのことを指すと言っても良い。stella_vslamはオリジナルのOpenVSLAMに追加されている機能があったり変更されている部分も多く、いまも更新が続いている。自己位置推定(SLAM)を始めるなら、このstella_vslamの研究から取りかかるのがベストな選択だと言える。

以前の記事ではUbuntu 18.04でビルドを行ったが、stella_vslamドキュメントサイトの情報が更新されており、いまの最新版ではUbuntu 20.04でのビルド手順が記載されている。それで、stella_vslamのビルドと動作確認をもう一度やりなおしてみることにした。

stella-cv.readthedocs.io

以降はstella_vslamドキュメントサイトに記載されている内容とほとんど同じだが、一部変更や追加部分もある。

stella_vslamのビルド依存パッケージの導入

共通の依存パッケージ

$ sudo apt install -y build-essential pkg-config cmake git wget curl unzip

g2oの依存パッケージ

$ sudo apt install -y libatlas-base-dev libsuitesparse-dev

OpenCVの依存パッケージ

$ sudo apt install -y libgtk-3-dev ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libavresample-dev libtbb-dev

Eigenの依存パッケージ

$ sudo apt install -y gfortran

backward-cppの依存パッケージ

$ sudo apt install -y binutils-dev

その他の依存パッケージ

$ sudo apt install -y libyaml-cpp-dev libgflags-dev sqlite3 libsqlite3-dev

PangolinViewerの依存パッケージ

$ sudo apt install -y libglew-dev

stella_vslamとリンクされるライブラリのビルドとインストール

Eigen

$ mkdir -p ~/VSLAM/Depended_Builds
$ cd ~/VSLAM/Depended_Builds
$ wget -q https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.bz2
$ tar xjf eigen-3.3.7.tar.bz2
$ cd eigen-3.3.7
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    ..
$ make -j
$ sudo make install

OpenCV

$ cd ~/VSLAM/Depended_Builds
$ wget -q https://github.com/opencv/opencv/archive/4.6.0.zip
$ unzip -q 4.6.0.zip
# Download aruco module (optional)
$ wget -q https://github.com/opencv/opencv_contrib/archive/refs/tags/4.6.0.zip -O opencv_contrib-4.6.0.zip
$ unzip -q opencv_contrib-4.6.0.zip
$ mkdir opencv_extra && cd opencv_extra
$ ln -s ../opencv_contrib-4.6.0/modules/aruco .
$ cd ../opencv-4.6.0
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_DOCS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_JASPER=OFF \
    -DBUILD_OPENEXR=OFF \
    -DBUILD_PERF_TESTS=OFF \
    -DBUILD_TESTS=OFF \
    -DBUILD_PROTOBUF=OFF \
    -DBUILD_opencv_apps=OFF \
    -DBUILD_opencv_dnn=OFF \
    -DBUILD_opencv_ml=OFF \
    -DBUILD_opencv_python_bindings_generator=OFF \
    -DENABLE_CXX11=ON \
    -DENABLE_FAST_MATH=ON \
    -DWITH_EIGEN=ON \
    -DWITH_FFMPEG=ON \
    -DWITH_TBB=ON \
    -DWITH_OPENMP=ON \
    -DOPENCV_EXTRA_MODULES_PATH=../../opencv_extra \
    ..
$ make -j4
$ sudo make install
$ sudo ldconfig

stella_vslamドキュメントサイトではOpenCV 4.5.5を利用しているが、これを4.6.0に変えた。

また、コマンドsudo ldconfigを追加した。これを実行しておかないと、サンプルプログラムの起動時に下のようなエラーになる場合がある。

$ ./run_kitti_slam -h
./run_kitti_slam: error while loading shared libraries: libopencv_highgui.so.405: cannot open shared object file: No such file or directory

FBoW

$ cd ~/VSLAM/Depended_Builds
$ git clone https://github.com/stella-cv/FBoW.git
$ cd FBoW
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    ..
$ make -j4
$ sudo make install

g2o

$ cd ~/VSLAM/Depended_Builds
$ git clone https://github.com/RainerKuemmerle/g2o.git
$ cd g2o
$ git checkout 20230223_git
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_UNITTESTS=OFF \
    -DG2O_USE_CHOLMOD=OFF \
    -DG2O_USE_CSPARSE=ON \
    -DG2O_USE_OPENGL=OFF \
    -DG2O_USE_OPENMP=OFF \
    -DG2O_BUILD_APPS=OFF \
    -DG2O_BUILD_EXAMPLES=OFF \
    -DG2O_BUILD_LINKED_APPS=OFF \
    ..
$ make -j4
$ sudo make install

backward-cpp

$ cd  ~/VSLAM/Depended_Builds
$ git clone https://github.com/bombela/backward-cpp.git
$ cd backward-cpp
$ git checkout 5ffb2c879ebdbea3bdb8477c671e32b1c984beaa
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    ..
$ make -j4
$ sudo make install

PangolinViewer

$ cd ~/VSLAM/Depended_Builds
$ git clone https://github.com/stevenlovegrove/Pangolin.git
$ cd Pangolin
$ git checkout eab3d3449a33a042b1ee7225e1b8b593b1b21e3e
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_PANGOLIN_DEPTHSENSE=OFF \
    -DBUILD_PANGOLIN_FFMPEG=OFF \
    -DBUILD_PANGOLIN_LIBDC1394=OFF \
    -DBUILD_PANGOLIN_LIBJPEG=OFF \
    -DBUILD_PANGOLIN_LIBOPENEXR=OFF \
    -DBUILD_PANGOLIN_LIBPNG=OFF \
    -DBUILD_PANGOLIN_LIBTIFF=OFF \
    -DBUILD_PANGOLIN_LIBUVC=OFF \
    -DBUILD_PANGOLIN_LZ4=OFF \
    -DBUILD_PANGOLIN_OPENNI=OFF \
    -DBUILD_PANGOLIN_OPENNI2=OFF \
    -DBUILD_PANGOLIN_PLEORA=OFF \
    -DBUILD_PANGOLIN_PYTHON=OFF \
    -DBUILD_PANGOLIN_TELICAM=OFF \
    -DBUILD_PANGOLIN_UVC_MEDIAFOUNDATION=OFF \
    -DBUILD_PANGOLIN_V4L=OFF \
    -DBUILD_PANGOLIN_ZSTD=OFF \
    ..
$ make -j4
$ sudo make install

stella_vslamのビルド

stella_vslam本体

$ mkdir -p ~/VSLAM/Builds
$ cd ~/VSLAM/Builds
$ git clone --recursive https://github.com/stella-cv/stella_vslam.git
$ cd stella_vslam
$ mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
$ make -j4
$ sudo make install

PangolinViewer対応部

$ cd ~/VSLAM/Builds
$ git clone -b 0.0.1 --recursive https://github.com/stella-cv/pangolin_viewer.git
$ cd pangolin_viewer
$ mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
$ make -j4
$ sudo make install

SocketViewer対応部〔使用する場合のみビルド〕

$ cd ~/VSLAM/Builds
$ git clone https://github.com/shinsumicco/socket.io-client-cpp.git
$ cd socket.io-client-cpp
$ git submodule init
$ git submodule update
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DBUILD_UNIT_TESTS=OFF \
    ..
$ make -j4
$ sudo make install
$ sudo apt install -y libprotobuf-dev protobuf-compiler
$ cd ~/VSLAM/Builds
$ git clone -b 0.0.1 --recursive https://github.com/stella-cv/socket_publisher.git
$ cd socket_publisher
$ mkdir build && cd build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
$ make -j4
$ sudo make install

サンプルプログラム

$ cd ~/VSLAM/Builds
$ git clone -b 0.0.1 --recursive https://github.com/stella-cv/stella_vslam_examples.git
$ cd stella_vslam_examples
$ mkdir build && cd build
$ cmake \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DUSE_STACK_TRACE_LOGGER=ON \
    ..
$ make -j

stella_vslamの動作確認

サンプルデータセットの入手

下のサイトにstella_vslam用のサンプルデータセットが置いてあるので、ここから入手できる。

stella-cv.readthedocs.io

上に置いてあるのは、元は産総研(AIST)のOpenVSLAMサイトに在ったものではないだろうか。産総研の許可を得てstella_vslam側へ移したのだろう。

以前の記事を書いたときは上のリンクサイトは存在していなくて、産総研のオリジナルのデータセットを入手する方法が判らなかった。

公開データセットの入手

公開データセットを利用してstella_vslamの動作確認を行うこともできる。各データセットの配布元は以下のサイトになる。

KITTI Odometry Dataset

www.cvlibs.net

EuRoC MAV dataset

http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/

projects.asl.ethz.ch

TUM RGBD Dataset

https://vision.in.tum.de/rgbd/dataset/freiburg3/rgbd_dataset_freiburg3_calibration_rgb_depth.tgz

vision.in.tum.de

以前の記事では、これらの中からKITTI Odometry Datasetを利用したが、このデータセットKITTIのサイトでアカウント登録をしないとダウンロードできない。

サンプルデータセットによる動作確認

stella-cv.readthedocs.io

# at the build directory of stella_vslam_examples
$ pwd
~/VSLAM/Builds/stella_vslam_examples/build
$ ls ../..
pangolin_viewer  socket_publisher  socket_viewer  stella_vslam  stella_vslam_examples

# ORB vocabulary ファイルのダウンロード
$ curl -sL "https://github.com/stella-cv/FBoW_orb_vocab/raw/main/orb_vocab.fbow" -o orb_vocab.fbow

# dataset ディレクトリの作成
$ mkdir ../dataset

# 1つ目のサンプルデータセットのダウンロード
$ FILE_ID="1d8kADKWBptEqTF7jEVhKatBEdN7g0ikY"
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=${FILE_ID}" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -sLb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=${FILE_ID}" -o ../dataset/aist_living_lab_1.zip
$ unzip ../dataset/aist_living_lab_1.zip -d ../dataset

# 2つ目のサンプルデータセットのダウンロード
$ FILE_ID="1TVf2D2QvMZPHsFoTb7HNxbXclPoFMGLX"
$ curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=${FILE_ID}" > /dev/null
$ CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
$ curl -sLb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=${FILE_ID}" -o ../dataset/aist_living_lab_2.zip
$ unzip ../dataset/aist_living_lab_2.zip -d ../dataset

# tracking and mapping実行指定でvslamを起動
$ ./run_video_slam \
    -v ./orb_vocab.fbow \
    -m ../dataset/aist_living_lab_1/video.mp4 \
    -c ../../stella_vslam/example/aist/equirectangular.yaml \
    --frame-skip 3 \
    --no-sleep \
    --map-db-out map.msg
# [Terminate] ボタン押下でビューア終了
# カレントディレクトリに map.msg が生成されている

# localization実行指定でvslamを起動
$ ./run_video_slam \
    --disable-mapping \
    -v ./orb_vocab.fbow \
    -m ../dataset/aist_living_lab_2/video.mp4 \
    -c ../../stella_vslam/example/aist/equirectangular.yaml \
    --frame-skip 3 \
    --no-sleep \
    --map-db-in map.msg
# localization with temporal mapping based odometry実行指定でvslamを起動
$ ./run_video_slam \
    --temporal-mapping \
    -v ./orb_vocab.fbow \
    -m ../dataset/aist_living_lab_2/video.mp4 \
    -c ../../stella_vslam/example/aist/equirectangular.yaml \
    --frame-skip 3 \
    --no-sleep \
    --map-db-in map.msg

下がサンプルデータセットを使ってstella_vslamの動作確認を行っている様子。

www.youtube.com

公開データセットによる動作確認

stella-cv.readthedocs.io

KITTI Odometry Dataset

# at the build directory of stella_vslam_examples
$ pwd
~/VSLAM/Builds/stella_vslam_examples/build
$ ls ../..
pangolin_viewer  socket_publisher  socket_viewer  stella_vslam  stella_vslam_examples

# KITTI Odometry dataset (grayscale, 22 GB) のダウンロード
$ wget -q URL_HTTPS_KITTI_DATASET/data_odometry_gray.zip -P ../dataset
$ unzip -q data_odometry_gray.zip -d ../dataset

# monocular SLAM with sequence 00
$ ./run_kitti_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/dataset/sequences/00/ \
    -c ../../stella_vslam/example/kitti/KITTI_mono_00-02.yaml
# stereo SLAM with sequence 05
$ ./run_kitti_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/dataset/sequences/05/ \
    -c ../../stella_vslam/example/kitti/KITTI_stereo_04-12.yaml

EuRoC MAV Dataset

# at the build directory of stella_vslam_example
$ pwd
~/VSLAM/Builds/stella_vslam_examples/build
$ ls ../..
pangolin_viewer  socket_publisher  socket_viewer  stella_vslam  stella_vslam_examples

# EuRoC MAV dataset のダウンロード
$ wget -q \
    http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_03_medium/MH_03_medium.zip \
    -P ../dataset
$ unzip -q ../dataset/MH_03_medium.zip -d ../dataset

# monocular SLAM with any EuRoC sequence
$ ./run_euroc_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/mav0/ \
    -c ../../stella_vslam/example/euroc/EuRoC_mono.yaml
# stereo SLAM with any EuRoC sequence
$ ./run_euroc_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/mav0/ \
    -c ../../stella_vslam/example/euroc/EuRoC_stereo.yaml

TUM RGBD Dataset

# at the build directory of stella_vslam_examples
$ pwd
~/VSLAM/Builds/stella_vslam_examples/build
$ ls ../..
pangolin_viewer  socket_publisher  socket_viewer  stella_vslam  stella_vslam_examples

# TUM RGBD dataset のダウンロード
$ wget -q \
    https://vision.in.tum.de/rgbd/dataset/freiburg3/rgbd_dataset_freiburg3_calibration_rgb_depth.tgz \
    -P ../dataset
$ tar xzf ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth.tgz.zip \
    -C ../dataset

# TUM RGBD dataset の前処理
$ cd ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth
$ wget -q \
    https://svncvpr.in.tum.de/cvpr-ros-pkg/trunk/rgbd_benchmark/rgbd_benchmark_tools/src/rgbd_benchmark_tools/associate.py
$ python associate.py rgb.txt depth.txt
$ cd ../../build

# Tracking and Mapping

# monocular SLAM with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_mono_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-out fr3_slam_mono.msg

# RGBD SLAM with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_rgbd_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-out fr3_slam_rgbd.msg

# Localization

# monocular localization with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam --disable-mapping \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_mono_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-in fr3_slam_mono.msg

# RGBD SLAM with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam --disable-mapping \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_rgbd_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-in fr3_slam_rgbd.msg

# Localization with temporal mapping based odometry

# monocular localization with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam --temporal-mapping \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_mono_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-in fr3_slam_mono.msg

# RGBD SLAM with rgbd_dataset_freiburg3_calibration_rgb_depth
$ ./run_tum_rgbd_slam --temporal-mapping \
    -v ./orb_vocab.fbow \
    -d ../dataset/rgbd_dataset_freiburg3_calibration_rgb_depth/ \
    -c ../../stella_vslam/example/tum_rgbd/TUM_RGBD_rgbd_3.yaml \
    --no-sleep \
    --auto-term \
    --map-db-in fr3_slam_rgbd.msg

公開データセットを使ってstella_vslamの動作確認を行っている様子。

www.youtube.com

www.youtube.com

www.youtube.com

SocketViewerによる動作確認

$ git clone --recursive https://github.com/stella-cv/socket_viewer.git
$ cd socket_viewer
$ ls
app.js  Dockerfile  LICENSE  package.json  public  README.md  views
$ nodenv install 12.22.12
$ nodenv local 12.22.12
$ node -v
v12.22.12
$ npm install
....    ....
added 96 packages from 61 contributors and audited 96 packages in 4.292s

8 packages are looking for funding
  run `npm fund` for details

found 1 critical severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
$ ls
app.js  Dockerfile  LICENSE  node_modules  package.json  package-lock.json  public  README.md  views
$ node app.js
WebSocket: listening on *:3000
HTTP server: listening on *:3001
  

※上記は、Node.js環境としてnodenvを用いることを前提としている。

# at the build directory of stella_vslam_examples
$ pwd
~/VSLAM/Builds/stella_vslam_examples/build
$ ls ../..
pangolin_viewer  socket_publisher  socket_viewer  stella_vslam  stella_vslam_examples

$ ./run_kitti_slam \
    -v ./orb_vocab.fbow \
    -d ../dataset/dataset/sequences/00/ \
    -c ../../stella_vslam/example/kitti/KITTI_mono_00-02.yaml \
    --viewer socket_publisher

ここで、Webブラウザを起動してhttp://localhost:3001/へアクセスすると下のような画面になる。

前回stella_vslamを扱ったときは、パラメータを調整していくつかの動画への適応具合を観たり、ソースコードを眺めてプログラム実装の概要を理解することなどを行った。

改めて自己位置推定の研究を再開するにあって、stella_vslamの動作原理、プログラムソース実装、深い利用方法、改造方法の調査などを行っていくことになるだろう。また、stella_vslam以外にもSLAM実装は存在しているので、他のプログラムの調査も始めるつもりだ。

【Python】Open3Dの試しインストール

OpenCVやML/DLで物体認識をやっているときに、認識した物体の形状をポリゴンや3D点群データとして扱うことがある。そのためPoint Cloud LibraryやOpen3Dの存在は知っていたが、あるきっかけで、Open3Dについてもっと深く知りたいという欲求が生まれたので、最近Open3Dを研究対象テーマに加えた。

github.com

本格的な研究開発を始める前の取りかかりとして、Open3Dのインストールと動作確認をやってみた。

Open3Dのインストール

まずは、Open3D用のPython仮想環境を作った。

% mkdir open3d_test
% cd open3d_test
% pyenv local 3.7
% poetry init
....    ....
Compatible Python versions [^3.11]:  >=3.7,<3.11
% poetry install
% poetry shell
% python -V
Python 3.10.9

私のPython環境はanyenv + pyenv + Poetryだが、pyenvによって3.6〜3.11のPythonを使い分けている。Open3Dのサイトで対象のPythonバージョンを調べてみると3.7〜3.10だったので、poetryで作る仮想環境のPythonバージョンは上のようにした。

そして、その仮想環境にOpen3Dをインストールした。

% poetry add open3d

初回のインストール時は少し時間がかかる。Open3Dは多くのパッケージに依存しているようだ。Open3Dと一緒に追加されたパッケージを確認してみると、下のようになっていた。

% pip list
Package              Version
-------------------- --------
ansi2html            1.8.0
attrs                23.1.0
certifi              2023.5.7
charset-normalizer   3.2.0
click                8.1.4
ConfigArgParse       1.5.5
dash                 2.11.1
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0
fastjsonschema       2.17.1
Flask                2.2.5
idna                 3.4
itsdangerous         2.1.2
Jinja2               3.1.2
jsonschema           4.17.3
jupyter_core         4.12.0
MarkupSafe           2.1.3
nbformat             5.7.0
nest-asyncio         1.5.6
numpy                1.21.6
open3d               0.17.0
packaging            23.1
pip                  23.1.2
plotly               5.15.0
pyrsistent           0.19.3
requests             2.31.0
retrying             1.3.4
setuptools           67.8.0
six                  1.16.0
tenacity             8.2.2
traitlets            5.9.0
typing_extensions    4.7.1
urllib3              2.0.3
Werkzeug             2.2.3
wheel                0.40.0

続いて、Open3Dの動作環境の確認を行った。

% python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'sklearn'
$ poetry add scikit-learn
Configuration file exists at /Users/yuhri/Library/Preferences/pypoetry, reusing this directory.

[tool.poetry]
Consider moving TOML configuration files to /Users/yuhri/Library/Application Support/pypoetry, as support for the legacy directory will be removed in an upcoming release.
Using version ^1.3.0 for scikit-learn

Updating dependencies
Resolving dependencies... (0.2s)

The current project's Python requirement (>=3.7,<3.11) is not compatible with some of the required packages Python requirement:
  - scikit-learn requires Python >=3.8, so it will not be satisfied for Python >=3.7,<3.8

Because no versions of scikit-learn match >1.3.0,<2.0.0
 and scikit-learn (1.3.0) requires Python >=3.8, scikit-learn is forbidden.
So, because open3d-test depends on scikit-learn (^1.3.0), version solving failed.

  • Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties

    For scikit-learn, a possible solution would be to set the `python` property to ">=3.8,<3.11"

    https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
    https://python-poetry.org/docs/dependency-specification/#using-environment-markers

% vi pyproject.toml
....    ....
[tool.poetry.dependencies]
- python = ">=3.7,<3.11"
+ python = ">=3.8,<3.11"
$ poetry add scikit-learn

最初にモジュールsklearnが足りないと言ってくるが、これはscikit-learnのことなので、それをインストールしようとすると、上のような警告が表示される。現時点で最新版のscikit-learnPython 3.8〜3.10でしか使えないらしい。

それで、pyproject.toml内の依存Pythonバージョン定義を上のように書き換えて、scikit-learnをインストールした。

さらに続けて、Open3Dの依存パッケージを追加していった。

% python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'yaml'
% poetry add pyyaml
$ python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'addict'
% poetry add addict
% python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'PIL'
% poetry add pillow
% python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'pandas'
% poetry add pandas
% python -c "import open3d as o3d"
....    ....
ModuleNotFoundError: No module named 'tqdm'
% poetry add tqdm
% python -c "import open3d as o3d"

コマンドpython -c "import open3d as o3d"で警告が表示されなければ、依存パッケージはすべて追加できて動作環境が整ったことになるようだ。Open3Dは上記のパッケージにも依存しているらしいが、それならインストール時に一緒に追加してくれれば良いのに思うのだが。

Open3Dの動作確認

これでやっと動作環境が整ったようだ。最後に、GitHubからOpen3Dのソースを取得して、その中のPythonサンプルプログラムを動かしてみた。

% git clone https://github.com/isl-org/Open3D.git
% python Open3D/examples/python/visualization/demo_scene.py

上の画像をマウスでドラッグすると3次元方向に動かせる。こういうのを見ると、やっぱり3Dは面白いなぁと思う。

じつは、コンピュータグラフィックスにすごく興味が湧いてきて、いまUnityも使い始めている。Open3Dの研究を始めたのは、これをiOSAndroidで動かしてみたいと思ったからだ。

Open3D-iOSというパッケージが存在しており、すでにiOSではOpen3Dが使えるらしい。それなら、これのAndroid版を作ってみたい。さらに、UnityでもOpen3Dを使えるようにしたい。iOSAndroid両方でUnity上でOpen3Dが使えるようにすることをこの研究の最終目的としている。

【参照リンク】

self-development.info

libuvcをMacでビルドしてみる

仕事上の事情から、いまUVCカメラ(USB接続のいわゆるWebカメラ)の仕様と制御方法について研究している。その一環として、libusbとlibuvcというライブラリにフォーカスして調査を行っている。

普段使っているMacでlibuvcをビルドして動かすことをやってみた。

libuvcのビルド

プラットフォームはmacOS Ventura、ビルド環境はHomebrewを使っている。

最初にlibuvcのビルドに必要な依存パッケージをインストールした。

% brew install cmake pkg-config
% brew install libusb jpeg-turbo

実際の操作順は逆で、最初にlibuvcのソースを取得して、それをビルドしながら上のパッケージが必要なことが判ったのだが。

続いて、libuvcのソースを取得した。

% git clone https://github.com/libuvc/libuvc.git

そして、ビルドを行う。

% cd libuvc
% mkdir build
% cd build
% cmake ..
-- libusb-1.0 found using pkgconfig
-- Found JPEG: /usr/local/lib/libjpeg.dylib (found version "80")
-- Found JPEG library using standard module
CMake Warning (dev) at /usr/local/Cellar/cmake/3.26.4/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
  The package name passed to `find_package_handle_standard_args` (JPEG) does
  not match the name of the calling package (JpegPkg).  This can lead to
  problems in calling code that expects `find_package` result variables
  (e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
  cmake/FindJpegPkg.cmake:58 (find_package_handle_standard_args)
  CMakeLists.txt:45 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found JPEG: /usr/local/lib/libjpeg.dylib
-- Building libuvc with JPEG support.
-- Configuring done (0.7s)
-- Generating done (0.1s)
-- Build files have been written to: /Users/LOGIN_USER/Builds/libuvc/build
% make
[  4%] Building C object CMakeFiles/uvc.dir/src/ctrl.c.o
[  9%] Building C object CMakeFiles/uvc.dir/src/ctrl-gen.c.o
[ 13%] Building C object CMakeFiles/uvc.dir/src/device.c.o
[ 18%] Building C object CMakeFiles/uvc.dir/src/diag.c.o
[ 22%] Building C object CMakeFiles/uvc.dir/src/frame.c.o
[ 27%] Building C object CMakeFiles/uvc.dir/src/init.c.o
[ 31%] Building C object CMakeFiles/uvc.dir/src/stream.c.o
[ 36%] Building C object CMakeFiles/uvc.dir/src/misc.c.o
[ 40%] Building C object CMakeFiles/uvc.dir/src/frame-mjpeg.c.o
[ 45%] Linking C shared library libuvc.dylib
[ 45%] Built target uvc
[ 50%] Building C object CMakeFiles/uvc_static.dir/src/ctrl.c.o
[ 54%] Building C object CMakeFiles/uvc_static.dir/src/ctrl-gen.c.o
[ 59%] Building C object CMakeFiles/uvc_static.dir/src/device.c.o
[ 63%] Building C object CMakeFiles/uvc_static.dir/src/diag.c.o
[ 68%] Building C object CMakeFiles/uvc_static.dir/src/frame.c.o
[ 72%] Building C object CMakeFiles/uvc_static.dir/src/init.c.o
[ 77%] Building C object CMakeFiles/uvc_static.dir/src/stream.c.o
[ 81%] Building C object CMakeFiles/uvc_static.dir/src/misc.c.o
[ 86%] Building C object CMakeFiles/uvc_static.dir/src/frame-mjpeg.c.o
[ 90%] Linking C static library libuvc.a
[ 90%] Built target uvc_static
[ 95%] Building C object CMakeFiles/example.dir/src/example.c.o
[100%] Linking C executable example
[100%] Built target example

libuvcの動作確認

ビルドしたlibuvcの動作確認として、UVCカメラを接続した状態で以下のコマンドを実行してみた。

% ./example
UVC initialized
Device found
uvc_open: Access denied (-3)
UVC exited

どうもrootユーザでやらないとダメみたいなので、sudo付きで実行してみたら下のような出力になって、これで動いているようだ。

% sudo ./example
Password:
UVC initialized
Device found
Device opened
DEVICE CONFIGURATION (1d6c:0103/AN20200825001) ---
Status: idle
VideoControl:
    bcdUVC: 0x0100
VideoStreaming(1):
    bEndpointAddress: 131
    Formats:
    MJPEGFormat(1)
          bits per pixel: 0
          GUID: 4d4a5047000000000000000000000000 (MJPG)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 7372800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 18432000-55296000
              max frame size: 153600
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(4)
              capabilities: 00
              size: 640x360
              bit rate: 18432000-55296000
              max frame size: 460800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(5)
              capabilities: 00
              size: 800x600
              bit rate: 18432000-55296000
              max frame size: 960000
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(6)
              capabilities: 00
              size: 960x720
              bit rate: 18432000-55296000
              max frame size: 1382400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(7)
              capabilities: 00
              size: 1024x576
              bit rate: 18432000-55296000
              max frame size: 1179648
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(8)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 614400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(9)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 1843200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(10)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(11)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 7372800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(12)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
    FrameFormat(2)
          bits per pixel: 0
          GUID: 4832363400001000800000aa00389b71 (H264)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(4)
              capabilities: 00
              size: 640x360
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(5)
              capabilities: 00
              size: 800x600
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(6)
              capabilities: 00
              size: 960x720
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(7)
              capabilities: 00
              size: 1024x576
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(8)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(9)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(10)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(11)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(12)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
    UncompressedFormat(3)
          bits per pixel: 16
          GUID: 5955593200001000800000aa00389b71 (YUY2)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 614400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 1843200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
END DEVICE CONFIGURATION

First format: (MJPG) 1920x1080 30fps
bmHint: 0001
bFormatIndex: 1
bFrameIndex: 1
dwFrameInterval: 333333
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 4147200
dwMaxPayloadTransferSize: 3060
bInterfaceNumber: 1
Streaming...
Enabling auto exposure ...
 ... enabled auto exposure
callback! frame_format = 7, width = 1920, height = 1080, length = 197981, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 219087, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 242720, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 263191, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 293221, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 341212, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 356177, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 352805, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 350672, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 350672, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 331834, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 330931, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 330550, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 329433, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 329433, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 308818, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 309529, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310410, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 311284, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 311284, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310782, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310160, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310327, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 309760, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310405, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310493, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 311158, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 310334, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 309190, ptr = 0x3039
callback! frame_format = 7, width = 1920, height = 1080, length = 308535, ptr = 0x3039

examplesrc/example.cというソースからビルドされる実行ファイルだが、src/test.cというサンプルプログラム・ソースもあって、こちらはOpenCVを利用してカメラ映像の表示を行っている。

以下のコマンドを実行すると、このsrc/test.cも一緒にビルドできる。

% brew install opencv@3
% cmake .. -DBUILD_TEST=true -DOpenCV_DIR=/usr/local/opt/opencv@3/share/OpenCV
% make

uvc_testというのがsrc/test.cからビルドされた実行ファイルだが、これを起動すると以下のようなメッセージが出力されてプログラムが停止してしまう。

% sudo ./uvc_test
UVC initialized
Device found
Device opened
DEVICE CONFIGURATION (1d6c:0103/AN20200825001) ---
Status: idle
VideoControl:
    bcdUVC: 0x0100
VideoStreaming(1):
    bEndpointAddress: 131
    Formats:
    MJPEGFormat(1)
          bits per pixel: 0
          GUID: 4d4a5047000000000000000000000000 (MJPG)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 7372800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 18432000-55296000
              max frame size: 153600
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(4)
              capabilities: 00
              size: 640x360
              bit rate: 18432000-55296000
              max frame size: 460800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(5)
              capabilities: 00
              size: 800x600
              bit rate: 18432000-55296000
              max frame size: 960000
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(6)
              capabilities: 00
              size: 960x720
              bit rate: 18432000-55296000
              max frame size: 1382400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(7)
              capabilities: 00
              size: 1024x576
              bit rate: 18432000-55296000
              max frame size: 1179648
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(8)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 614400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(9)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 1843200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(10)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(11)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 7372800
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(12)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 4147200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
    FrameFormat(2)
          bits per pixel: 0
          GUID: 4832363400001000800000aa00389b71 (H264)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(3)
              capabilities: 00
              size: 320x240
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(4)
              capabilities: 00
              size: 640x360
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(5)
              capabilities: 00
              size: 800x600
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(6)
              capabilities: 00
              size: 960x720
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(7)
              capabilities: 00
              size: 1024x576
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(8)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(9)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(10)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(11)
              capabilities: 00
              size: 2560x1440
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(12)
              capabilities: 00
              size: 1920x1080
              bit rate: 18432000-55296000
              max frame size: 0
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
    UncompressedFormat(3)
          bits per pixel: 16
          GUID: 5955593200001000800000aa00389b71 (YUY2)
          default frame: 1
          aspect ratio: 0x0
          interlace flags: 00
          copy protect: 00
            FrameDescriptor(1)
              capabilities: 00
              size: 640x480
              bit rate: 18432000-55296000
              max frame size: 614400
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
            FrameDescriptor(2)
              capabilities: 00
              size: 1280x720
              bit rate: 18432000-55296000
              max frame size: 1843200
              default interval: 1/30
              interval[0]: 1/30
              interval[1]: 1/25
END DEVICE CONFIGURATION
bmHint: 0001
bFormatIndex: 3
bFrameIndex: 1
dwFrameInterval: 333333
wKeyFrameRate: 0
wPFrameRate: 0
wCompQuality: 0
wCompWindowSize: 0
wDelay: 0
dwMaxVideoFrameSize: 614400
dwMaxPayloadTransferSize: 3060
bInterfaceNumber: 1
Streaming for 10 seconds...
set_ae_mode: Pipe (-9)
set_exp_abs: Pipe (-9)
callback! length = 3048, ptr = 12345
2023-07-10 10:40:13.082 uvc_test[62190:4733991] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007ff816f7043b __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff816abfe25 objc_exception_throw + 48
    2   CoreFoundation                      0x00007ff816f985d6 _CFBundleGetValueForInfoKey + 0
    3   AppKit                              0x00007ff81a03f161 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 307
    4   AppKit                              0x00007ff81a02bf4f -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1247
    5   AppKit                              0x00007ff81a02ba69 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
    6   AppKit                              0x00007ff81a2f9ea2 -[NSWindow initWithContentRect:styleMask:backing:defer:screen:] + 50
    7   libopencv_highgui.3.4.16.dylib      0x0000000107384261 cvNamedWindow + 344
    8   uvc_test                            0x00000001072b7ac0 cb + 192
    9   libuvc.0.0.7.dylib                  0x000000010736b59f _uvc_user_caller + 127
    10  libsystem_pthread.dylib             0x00007ff816e1d259 _pthread_start + 125
    11  libsystem_pthread.dylib             0x00007ff816e18c7b thread_start + 15
)
libc++abi: terminating with uncaught exception of type NSException
zsh: abort      sudo ./uvc_test

この例外エラーは、メインスレッドの外からUIを叩こうとすると起きるものらしい。

src/test.cのソース内に以下のような記述があって、cvShowImageというOpenCVの関数を呼び出したときに起きているようだ。

void cb(uvc_frame_t *frame, void *ptr) {
  ....    ....

  printf("callback! length = %u, ptr = %d\n", frame->data_bytes, (int) ptr);

  ....    ....
  ....    ....

  cvImg = cvCreateImageHeader(
      cvSize(bgr->width, bgr->height),
      IPL_DEPTH_8U,
      3);

  cvSetData(cvImg, bgr->data, bgr->width * 3); 

  cvNamedWindow("Test", CV_WINDOW_AUTOSIZE);
  cvShowImage("Test", cvImg);
  cvWaitKey(10);

  cvReleaseImageHeader(&cvImg);

  uvc_free_frame(bgr);
}

int main(int argc, char **argv) {
  ....    ....
  ....    ....

  res = uvc_init(&ctx, NULL);

  if (res < 0) {
    uvc_perror(res, "uvc_init");
    return res;
  }

  puts("UVC initialized");

  ....    ....
  ....    ....
  ....    ....
  ....    ....

        res = uvc_start_streaming(devh, &ctrl, cb, 12345, 0);

        if (res < 0) {
          uvc_perror(res, "start_streaming");
        } else {
          puts("Streaming for 10 seconds...");
          ....    ....
          }
          sleep(10);
          uvc_stop_streaming(devh);
          puts("Done streaming.");
        }

  ....    ....
  ....    ....

  uvc_exit(ctx);
  puts("UVC exited");

  return 0;
}

Ubuntuでもlibuvcのビルドをやってみたが、Ubuntuではuvc_testは問題なく動作してカメラ映像が表示されることが確認できている。つまり、上記の現象はmacOS固有の障害ということになる。

SwiftだとDispatchQueue.main.syncという関数があって、これを使ってメインスレッド側でUI処理を行うようにすれば解決できるらしい。src/test.cC言語記述でpthreadを使っているが、この場合、同じ方法をどうやって実現すれば良いのか判らなかった。

じつは、上記と同じ内容の作業を大分前にHigh Sierra上で実施済みだったのだが、今回MacのOSをVenturaにアップグレードしたので、それで本作業をもう一度やりなおして記事にした。

ちなみに、この研究の目的は、UVCカメラの映像取得・制御をネットワーク経由でできる環境を作ることだ。このような環境をLinuxMacWindowsのすべてで(欲を言えば、AndroidiOSでも)実現することを最終目標として取り組んでいる。