Cntk: Still the "No module named 'cntk._cntk_py' " problem, under ubuntu

Created on 5 Jul 2018  路  8Comments  路  Source: microsoft/CNTK

I already read the issue https://github.com/Microsoft/CNTK/issues/1553, but still feel confused. I just want to ask, is there any offical, systematic steps to check out the problem and solve it?
I checked out some of the terms in that link, but some of the terms are not that explicit to understand. For my own case, ubuntu 16.04, and anaconda activate my python to 3.6 environment, what else steps should i check? Thanks.
---------------------update line-----------------------------------
I'm using utuntu 16.04 LTS, cntk2.5.1, cpu-only, https://cntk.ai/PythonWheel/CPU-Only/cntk-2.5.1-cp36-cp36m-linux_x86_64.whl. Actually, I also tried the PyPI way, the result is the same.After the install, the info gives:

Collecting cntk==2.5.1 from https://cntk.ai/PythonWheel/CPU-Only/cntk-2.5.1-cp36-cp36m-linux_x86_64.whl
Using cached https://cntk.ai/PythonWheel/CPU-Only/cntk-2.5.1-cp36-cp36m-linux_x86_64.whl
Requirement already satisfied: numpy>=1.11 in ./anaconda3/envs/python3_6/lib/python3.6/site-packages (from cntk==2.5.1) (1.14.3)
Requirement already satisfied: scipy>=0.17 in ./anaconda3/envs/python3_6/lib/python3.6/site-packages (from cntk==2.5.1) (1.1.0)
Installing collected packages: cntk
Successfully installed cntk-2.5.1

then I go into python to import cntk, then followed by:

Traceback (most recent call last):
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/site-packages/cntk/cntk_py.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'cntk._cntk_py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 1, in
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/site-packages/cntk/__init__.py", line 17, in
from . import cntk_py
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/site-packages/cntk/cntk_py.py", line 21, in
_cntk_py = swig_import_helper()
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/site-packages/cntk/cntk_py.py", line 20, in swig_import_helper
return importlib.import_module('_cntk_py')
File "/home/n_li/anaconda3/envs/python3_6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: libpython3.6m.so.1.0: cannot open shared object file: No such file or directory

(python3_6) n_li@nli:~$ echo $PATH
/home/n_li/anaconda3/envs/python3_6/bin:/home/n_li/anaconda3/bin:/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin

(python3_6) n_li@nli:~$ echo $PYTHONPATH
/opt/ros/indigo/lib/python2.7/dist-packages

(python3_6) n_li@nli:~$ echo $LD_LIBRARY_PATH
/opt/ros/indigo/lib

Most helpful comment

@vinbo just out curiosity, try creating a python 3.5 environment and import CNTK (remeber toinstall the right whl). For some reason, some anaconda versions seems not to install libpython3.6 in the new environment or fail to update the environment variables to point to the folder where libpython3.6m.so.1.0 is stored. However, as a workaround, anaconda environment with python 2.7 or 3.5 seems to work fine for these users. If that is the case, you could report this to Anaconda. It would be an awesome help for us. If you do, please refer that bug here so we can track it :)

If you are not building CNTK from source, you don't need to set PYTHONPATH.

Go to the root of your anaconda installation and look for libpython3.6m.so.1.0 (find /home/n_li/anaconda3/ -name "libpython3.6m.so.1.0"). Check if libpython3.6m.so.1.0 exists inside /home/n_li/anaconda3/lib and /home/n_li/anaconda3/envs/python3_6/lib. If it doesn't exist, anaconda failed to install it. If it does, anaconda failed to add this path to the lib search path. Maybe updating LD_LIBRARY_PATH so that it points to the path where libpython3.6m.so.1.0 is stored can help you. Something like export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/n_li/anaconda3/envs/python3_6/lib

All 8 comments

For me i resolved it by initialising my path to my environment's directory before importing cntk. Perhaps you can try appending to os.environ['path'] += ";YOURPATH"

Provide more information regarding your environment. Are you installing which version of CNTK (include URL) ? which operating system you are using ? are you using cpu or gpu version ? after acxtivating your conda env, what is the value of PATH, PYTHONPATH and LD_LIBRARY_PAH ? What is the complete output error you are getting (include back trace and/or warning messages, if any)

I would simply check the path of your python.exe. It should be something similar.
C:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py35

Otherwise, it will not know about the cntk module.

@thiagocrepaldi thanks, already updated all the question you ask in the main post. I think I can see the problem is the value of PYTHONPATH, AND LD_LIBRARY_PATH. but I'm new to the tool of anaconda environment, will you tell me what to do next, please? (forget about the ros thing, it's been installed when i was in ubuntu 14.04, i think the operating system has already uninstalled the ros automatically when I upgrade from ubuntu 14 to 16)
You know the thing I cannot understand is here:

(python3_6) n_li@nli:~$ python --version
Python 3.6.5 :: Anaconda, Inc.
(python3_6) n_li@nli:~$ conda deactivate
n_li@nli:~$ python --version
Python 3.6.5 :: Anaconda, Inc.

then why the value of PYTHONPATH is that thing?

@vinbo just out curiosity, try creating a python 3.5 environment and import CNTK (remeber toinstall the right whl). For some reason, some anaconda versions seems not to install libpython3.6 in the new environment or fail to update the environment variables to point to the folder where libpython3.6m.so.1.0 is stored. However, as a workaround, anaconda environment with python 2.7 or 3.5 seems to work fine for these users. If that is the case, you could report this to Anaconda. It would be an awesome help for us. If you do, please refer that bug here so we can track it :)

If you are not building CNTK from source, you don't need to set PYTHONPATH.

Go to the root of your anaconda installation and look for libpython3.6m.so.1.0 (find /home/n_li/anaconda3/ -name "libpython3.6m.so.1.0"). Check if libpython3.6m.so.1.0 exists inside /home/n_li/anaconda3/lib and /home/n_li/anaconda3/envs/python3_6/lib. If it doesn't exist, anaconda failed to install it. If it does, anaconda failed to add this path to the lib search path. Maybe updating LD_LIBRARY_PATH so that it points to the path where libpython3.6m.so.1.0 is stored can help you. Something like export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/n_li/anaconda3/envs/python3_6/lib

@thiagocrepaldi thanks so much. problem solved.

n_li@nli:~$ find /home/n_li/anaconda3/ -name "libpython3.6m.so.1.0"
/home/n_li/anaconda3/lib/libpython3.6m.so.1.0
/home/n_li/anaconda3/envs/python3_6/lib/libpython3.6m.so.1.0
/home/n_li/anaconda3/pkgs/python-3.6.6-hc3d631a_0/lib/libpython3.6m.so.1.0
/home/n_li/anaconda3/pkgs/python-3.6.5-hc3d631a_2/lib/libpython3.6m.so.1.0
n_li@nli:~$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/n_li/anaconda3/envs/python3_6/lib
n_li@nli:~$ echo $LD_LIBRARY_PATH
/opt/ros/indigo/lib:/home/n_li/anaconda3/envs/python3_6/lib
n_li@nli:~$ source activate python3_6
(python3_6) n_li@nli:~$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

import cntk

There are people saying python3.6 really has bug. maybe next time I have a problem, i want to go back to python3.5.
Thanks again.

@thiagocrepaldi I am using Google colab. For reasons which are unknown to me,
!LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0
doesn't change the LD_LIBRARY_PATH
Could you please suggest an alternative or a remedy for the above?
P.S. I have also tried exporting the variable.

@aadarshsingh191198 If LD_LIBRARY_PATH doesnt work for you, create a file such as /etc/ld.so.conf.d/cntk.conf and add the path on it. then, run sudo ldconfig to update the cache. You can view if the new path is recognized by running ldconfig -p

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jykim picture jykim  路  18Comments

kasungayan picture kasungayan  路  20Comments

JohnCraigPublic picture JohnCraigPublic  路  16Comments

robinhad picture robinhad  路  61Comments

shyamalschandra picture shyamalschandra  路  17Comments