#14 k2 installed but (ModuleNotFoundError: No module named 'k2')

Used https://k2-fsa.github.io/k2/installation/conda.html instructions to install k2.

$ conda install -c k2-fsa -c pytorch -c conda-forge k2 python=3.8 cudatoolkit=11.1 pytorch=1.8.1

After installing k2, python couldn’t find it. Had to fix it by adding the alias to .bashrc to find it. It works if called from anaconda python.

np@np-INTEL:~$ python3 -m k2.version
/usr/bin/python3: Error while finding module specification for 'k2.version' (ModuleNotFoundError: No module named 'k2')

fix add this line to .bashrc

alias python3='/home/np/anaconda3/bin/python'

Open .bashrc

np@np-INTEL:~$ nano .bashrc

Add alias to .bashrc


# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias python3='/home/np/anaconda3/bin/python'

It work now. As per instructions I used conda to install k2, and looks like need python from anaconda to run k2.

np@np-INTEL:~$ . ~/.bashrc 
np@np-INTEL:~$ python3 -m k2.version
Collecting environment information...

k2 version: 1.15.1
Build type: Release
Git SHA1: b173c11ba379e2da0056281fe6b2d56f081419be
Git date: Mon Apr 18 16:10:45 2022
Cuda used to build k2: 11.1
cuDNN used to build k2: 8.0.4
Python version used to build k2: 3.8
OS used to build k2: Ubuntu 18.04.6 LTS
CMake version: 3.18.4
GCC version: 7.5.0
CMAKE_CUDA_FLAGS:  -Wno-deprecated-gpu-targets  --expt-extended-lambda -gencode arch=compute_35,code=sm_35 --expt-extended-lambda -gencode arch=compute_50,code=sm_50 --expt-extended-lambda -gencode arch=compute_60,code=sm_60 --expt-extended-lambda -gencode arch=compute_61,code=sm_61 --expt-extended-lambda -gencode arch=compute_70,code=sm_70 --expt-extended-lambda -gencode arch=compute_75,code=sm_75 --expt-extended-lambda -gencode arch=compute_80,code=sm_80 --expt-extended-lambda -gencode arch=compute_86,code=sm_86 -D_GLIBCXX_USE_CXX11_ABI=0 --compiler-options -Wall  --compiler-options -Wno-strict-overflow  --compiler-options -Wno-unknown-pragmas 
CMAKE_CXX_FLAGS:  -D_GLIBCXX_USE_CXX11_ABI=0 -Wno-unused-variable  -Wno-strict-overflow 
PyTorch version used to build k2: 1.8.1
PyTorch is using Cuda: 11.1
NVTX enabled: True
With CUDA: True
Disable debug: True
Sync kernels : False
Disable checks: False
Max cpu memory allocate: 214748364800
    
np@np-INTEL:~$