CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

importing cntk

Open gurusura opened this issue 10 years ago • 12 comments

I have installed cntk and all the dependencies in my Windows 7 (64 bit ) machine without any error. Every time I try to import cntk in python in the cntk-py34 envrionment, I am getting the following error:

"Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.

E:\GitHub>activate CNTK-py34

(CNTK-py34) E:\GitHub>python Python 3.4.3 |Continuum Analytics, Inc.| (default, Dec 1 2015, 11:39:45) [MSC v .1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information.

import cntk Traceback (most recent call last): File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\cntk_py.py", line 18, in swig_import_helper return importlib.import_module(mname) File "E:\Anaconda2\envs\CNTK-py34\lib\importlib__init__.py", line 109, in imp ort_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 2254, in _gcd_import File "", line 2237, in _find_and_load File "", line 2224, in _find_and_load_unlocked ImportError: 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 "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk__init__.py", line 11 , in from . import ops File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\ops__init__.py", lin e 7, in from . import sequence File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\ops\sequence__init__ .py", line 6, in from ...utils import sanitize_input, sanitize_shape, get_data_type, typemap File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\utils__init__.py", l ine 11, in from .. import cntk_py File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\cntk_py.py", line 21, in cntk_py = swig_import_helper() File "E:\Anaconda2\envs\CNTK-py34\lib\site-packages\cntk\cntk_py.py", line 20, in swig_import_helper return importlib.import_module('cntk_py') File "E:\Anaconda2\envs\CNTK-py34\lib\importlib__init.py", line 109, in imp ort_module return _bootstrap._gcd_import(name[level:], package, level) ImportError: DLL load failed: The specified module could not be found.

"

I have set path as specified in the binary CPU CNTK 64 bit installation, and I am unable to run the FeedForwardNet.py file too with similar error. Please let me know if I have missed anything. Thanks

gurusura avatar Oct 28 '16 16:10 gurusura

@ Gurusura, Could you please share the PYTHONPATH environment variable.

sayanpa avatar Oct 30 '16 01:10 sayanpa

the same issue here. PS C:\repos\cntk\bindings\python\examples> python NumpyInterop/FeedForwardNet.py Traceback (most recent call last): File "NumpyInterop/FeedForwardNet.py", line 10, in from cntk.device import cpu, set_default_device ImportError: No module named 'cntk'

PYTHONPATH C:\local\Anaconda3-4.1.1-Windows-x86_64

nootfly avatar Oct 30 '16 02:10 nootfly

@nootfly - could you let us know which installation path you chose? I.e., binary automatic, binary manual, or source? Did you set PYTHONPATH yourself? It should not be needed for binary installs, however, for source setup, it can be convenient.

@gurusura - could you share you PYTHONPATH environment variable? Also, which Anaconda version are you using? Also, as you're using Windows 7, please be aware of #959. Right now our recommended Windows version would be Windows 8.1 upwards, cf. https://github.com/Microsoft/CNTK/wiki/Test-Configurations.

Thanks, Mark

mahilleb-msft avatar Oct 31 '16 08:10 mahilleb-msft

My Windows 7 machine started crashing a few minutes after startup after installing CNTK. It has now crashed several times and I am trying to repair my machine. I may have to reinstall again. I set the PYTHONPATH in command prompt with the directory paths changed, but using the same instructions given in (c) https://github.com/Microsoft/CNTK/wiki/Setup-CNTK-on-Windows

Thanks R

gurusura avatar Oct 31 '16 10:10 gurusura

Hi, I also got the following error: steeve@steeve-X550VC:~/repos/cntk/bindings/python/examples$ python NumpyInterop/FeedForwardNet.py Traceback (most recent call last): File "NumpyInterop/FeedForwardNet.py", line 10, in <module> from cntk.device import cpu, set_default_device ImportError: No module named cntk.device

I was wondering which version of python should I use? And the following is my pythonpath variable: For python2: `>>> import sys

print(sys.path) ['', '/home/steeve/anaconda2/lib/python27.zip', '/home/steeve/anaconda2/lib/python2.7', '/home/steeve/anaconda2/lib/python2.7/plat-linux2', '/home/steeve/anaconda2/lib/python2.7/lib-tk', '/home/steeve/anaconda2/lib/python2.7/lib-old', '/home/steeve/anaconda2/lib/python2.7/lib-dynload', '/home/steeve/anaconda2/lib/python2.7/site-packages', '/home/steeve/anaconda2/lib/python2.7/site-packages/Sphinx-1.4.1-py2.7.egg', '/home/steeve/anaconda2/lib/python2.7/site-packages/setuptools-23.0.0-py2.7.egg'] For Python3:['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']` Hope you can give me some advice on how to solve it!

khuangaf avatar Nov 03 '16 15:11 khuangaf

We do not support Python 2 yet. Depending on how you installed the cntk python bindings you might have to activate the correct Python environment.

n17s avatar Nov 04 '16 00:11 n17s

@gurusura My Fri, did you solved your problem ? I meet the same problem with you. I find that "NumpyInterop/FeedForwardNet.py" will crash at its first time to import class from "cntk" package when I debug in pycharm.

shiqin8217 avatar Nov 08 '16 15:11 shiqin8217

Hi, I had a similar error when trying to run a cntk python script. It worked when calling the python interpreter in a shell directly (using the command below), but not in Pycharm even with the same interpreter: c:\local\Anaconda3-4.1.1-Windows-x86_64\envs\cntk-py34\python.exe myScript.py

To make it work in Pycharm I had to add "C:/local/cntk/cntk/" to my PATH variable, similar to cntkpy34.bat, and restart PyCharm. Strangely, doing a sys.path.append("C:/local/cntk/cntk/") in code was not enough.

PatrickBue avatar Nov 09 '16 18:11 PatrickBue

This looks exactly as my error, which I have reported as an issue here. I'm attempting to use with VS Code https://github.com/Microsoft/CNTK/issues/1106

drcrook1 avatar Nov 29 '16 16:11 drcrook1

@gurusura, @PatrickBue - how did you solve this problem. were you able to get it to run after activating cntk-py34 environment?

muditjai avatar Jan 13 '17 00:01 muditjai

This may come from mismatched _cntk_py.pyd and CNTKLibrary-2.0.dll. If you are building _cntk_py.pyd from source, please make sure to unset PYTHONPATH and uninstall previous cntk wheels in pip before using your build:

  1. set PYTHONPATH=
  2. pip uninstall cntk
  3. set PYTHONPATH=your path of _cntk_py.pyd
  4. set PATH=%PATH%;your path of CNTKLibrary-2.0.dll

For detailed diagnose, please install windbg and debug python, then check debug outputs when import cntk to find out which pyd/dll are being loaded.

ke1337 avatar Jan 13 '17 22:01 ke1337

Same issue also occurred in Python 3.6, so I will share it. Http://qiita.com/T_Umezaki/items/06c2e7ad1d9c2abab7f0

T-Umezaki avatar Aug 15 '17 03:08 T-Umezaki