k2-fsa / k2

FSA/FST algorithms, differentiable, with PyTorch compatibility.
https://k2-fsa.github.io/k2
Apache License 2.0
1.1k stars 214 forks source link

ModuleNotFoundError: No module named '_k2' #1197

Closed OswaldoBornemann closed 1 year ago

OswaldoBornemann commented 1 year ago

I have created a new environment and installed k2 with conda, then when i ran python -m k2.version, the error happened ModuleNotFoundError: No module named '_k2'.

csukuangfj commented 1 year ago

Could you please describe in detail how you installed k2.

The information you posted is too limited and we cannot figure out what goes wrong.

csukuangfj commented 1 year ago

Also, please read the installation logs carefully and check that you are using only one Python version.

OswaldoBornemann commented 1 year ago

The installation command i used is conda install -c k2-fsa -c pytorch -c conda-forge k2 python=3.8 cudatoolkit=10.2 pytorch=1.12.0, it was successfully installed.

Then i ran python -m k2.version, it output /home/anaconda3/envs/k2/bin/python: No module named k2.version

csukuangfj commented 1 year ago

conda install -c k2-fsa -c pytorch -c conda-forge k2 python=3.8 cudatoolkit=10.2 pytorch=1.12.0

could you show the installation logs and what is the output of python --version?

OswaldoBornemann commented 1 year ago

The installation logs is below

conda install -c k2-fsa -c pytorch -c conda-forge k2 python=3.8 cudatoolkit=10.2 pytorch=1.12.0
Collecting package metadata (current_repodata.json): done
Solving environment: done

# All requested packages already installed.

The output of python --version is below:

Python 3.8.16

csukuangfj commented 1 year ago

All requested packages already installed.

please provide the logs (you can first uninstall k2 and then re-install it again or you can create a new env to install again).

OswaldoBornemann commented 1 year ago
(k2) [home] $ conda install -c k2-fsa -c pytorch -c conda-forge k2 python=3.8 cudatoolkit=10.2 pytorch=1.12.0
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/anaconda3/envs/k2

  added / updated specs:
    - cudatoolkit=10.2
    - k2
    - python=3.8
    - pytorch=1.12.0

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    mkl-2023.1.0               |   h6d00ec8_46342       171.5 MB  defaults
    ------------------------------------------------------------
                                           Total:       171.5 MB

The following NEW packages will be INSTALLED:

  blas               pkgs/main/linux-64::blas-1.0-mkl
  cpuonly            pytorch/noarch::cpuonly-2.0-0
  cudatoolkit        conda-forge/linux-64::cudatoolkit-10.2.89-h713d32c_11
  icu                conda-forge/linux-64::icu-72.1-hcb278e6_0
  intel-openmp       pkgs/main/linux-64::intel-openmp-2023.1.0-hdb19cb5_46305
  k2                 k2-fsa/linux-64::k2-1.23.4.dev20230131-cpu_py3.8_torch1.12.0
  libhwloc           conda-forge/linux-64::libhwloc-2.9.1-hd6dc26d_0
  libiconv           conda-forge/linux-64::libiconv-1.17-h166bdaf_0
  libstdcxx-ng       conda-forge/linux-64::libstdcxx-ng-12.2.0-h46fd767_19
  libxml2            conda-forge/linux-64::libxml2-2.10.4-hfdac1af_0
  mkl                pkgs/main/linux-64::mkl-2023.1.0-h6d00ec8_46342
  pytorch            pytorch/linux-64::pytorch-1.12.0-py3.8_cpu_0
  pytorch-mutex      pytorch/noarch::pytorch-mutex-1.0-cpu
  tbb                conda-forge/linux-64::tbb-2021.9.0-hf52228f_0
  typing_extensions  conda-forge/noarch::typing_extensions-4.5.0-pyha770c72_0
  zlib               conda-forge/linux-64::zlib-1.2.13-h166bdaf_4

Proceed ([y]/n)? y

Downloading and Extracting Packages
mkl-2023.1.0         | 171.5 MB  | ###################################################################################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: - By downloading and using the CUDA Toolkit conda packages, you accept the terms and conditions of the CUDA End User License Agreement (EULA): https://docs.nvidia.com/cuda/eula/index.html

done
OswaldoBornemann commented 1 year ago

Then when i ran python -m k2.version, the output is below:

Traceback (most recent call last):
  File "/home/anaconda3/envs/k2/lib/python3.8/runpy.py", line 185, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/home/anaconda3/envs/k2/lib/python3.8/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/anaconda3/envs/k2/lib/python3.8/site-packages/k2/__init__.py", line 23, in <module>
    from _k2 import DeterminizeWeightPushingType
ImportError: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /home/anaconda3/envs/k2/lib/python3.8/site-packages/_k2.cpython-38-x86_64-linux-gnu.so)
csukuangfj commented 1 year ago

You see it is a different error.

The conda packages are built using Ubuntu 18.04. If you are using an old system, please consider installing k2 from source.

Please see https://k2-fsa.github.io/k2/installation/from_source.html or https://k2-fsa.github.io/k2/installation/for_developers.html

OswaldoBornemann commented 1 year ago

Ubuntu

Oh i see. My system is Centos 7. Thanks a lot.

OswaldoBornemann commented 1 year ago

When i installed k2 from source, the below error happened:

-- K2_TORCH_VERSION: 1.12
-- PyTorch version: 1.12.0
-- PyTorch cuda version: None
CMake Error at cmake/torch.cmake:55 (message):
  PyTorch 1.12.0 is compiled with CUDA None.

  But you are using CUDA 10.2 to compile k2.

  Please try to use the same CUDA version for PyTorch and k2.

  **You can remove this check if you are sure this will not cause problems**

The cuda version is 10.2.

csukuangfj commented 1 year ago

Please follow https://k2-fsa.github.io/k2/installation/cuda-cudnn.html to install cudatoolkit and cuDNN.

The first step is to install cudatoolkit and cudnn.

The next step is to install a python version that is compatible with your currently installed cudatoolkit.

csukuangfj commented 1 year ago

Also, please install pytorch using the following command

pip install https://download.pytorch.org/whl/cu102/torch-1.10.0%2Bcu102-cp38-cp38-linux_x86_64.whl
OswaldoBornemann commented 1 year ago

Finally it worked. Thanks a lot.!