0

I have installed tensorflow for the GPU from a whl file I found. It is version 1.5.0.

I also installed keras and matplotlib. I think numpy was installed from one of the modules.

Almost nothing works when I try to run python from within spyder or jupyter, but everything works running python from console.

When importing tensorflow spyder doesn't know what is this module.

runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')
Traceback (most recent call last):

  File "<ipython-input-1-ecb61dbb011d>", line 1, in <module>
    runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/LearnANN/untitled2.py", line 8, in <module>
    import tensorflow

ModuleNotFoundError: No module named 'tensorflow'

When importing numpy or keras or matplotlib

runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')
Traceback (most recent call last):

  File "<ipython-input-2-ecb61dbb011d>", line 1, in <module>
    runfile('D:/LearnANN/untitled2.py', wdir='D:/LearnANN')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/LearnANN/untitled2.py", line 8, in <module>
    import numpy

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import add_newdocs

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\__init__.py", line 8, in <module>
    from .type_check import *

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\lib\type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx

  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 26, in <module>
    raise ImportError(msg)

ImportError: 
Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control).  Otherwise reinstall numpy.

Original error was: DLL load failed: The specified module could not be found.

All these modules are available and working when just running python scriptName.py on the console.

I am on windows.

How do I fix this for jupyter/spyder?

  • Try the import statement on the IPython console in Spyder and check if you're able to import – Vijay Apr 18 '18 at 09:47
  • By that you mean to type the import numpy in the the console in spyder? If so it happen there too – ofer rubinstein Apr 18 '18 at 09:56
  • Yes.Have a look here. https://stackoverflow.com/a/10741803/5212057 – Vijay Apr 18 '18 at 10:42
  • Hi thanks. I am using anaconda though, so I tried to add the path of numpy inside Lib/sitepackages for my env but when booting spyder again I am getting errors on boot. Also not sure if it needs to be done like this since I am using an env. – ofer rubinstein Apr 18 '18 at 11:01
  • Oh! You can do one thing. You can point the Python interpreter to the virtual env python. This should definitely work. Make sure you've everything installed inside the virtual env and not in the global Python – Vijay Apr 18 '18 at 11:08

2 Answers2

0

You should invoke Jupyter/Spyder after activating the virtualenv and from inside the virtualenv. Only then will the local installation of the libraries will be referred. Oncy you activate the virtualenv by running

actiavte

then install tensorflow using

pip install tensorflow

Once TensorFlow is installed, run spyder/jupyter notebook from inside the virtualenv like below

enter image description here

Create a new .py file with below lines to check which TensorFlow is being referred to

import tensorflow
print(tensorflow.__file__)
Vijay
  • 1,030
  • 11
  • 34
  • Same error, it didn't help. I set it to the python.exe inside env/tf and then quit spyder and started t again – ofer rubinstein Apr 18 '18 at 11:21
  • Did you try my answer.. Invoking Spyder from virtual env?? – Vijay Apr 21 '18 at 10:28
  • Eventually I reinstalled anaconda. Then spyder's consoled didn't wprk at all, but I installed it two modules which it complained it didn't have with these style of installaion https://anaconda.org/anaconda/cloudpickle and it worked after that – ofer rubinstein Apr 24 '18 at 12:14
0

Incase you are using Jupyter notebook on windows, try the following:

  1. Using anaconda prompt/command prompt, create a virtual environment using conda create -n YOUR_ENV_NAME python=3.6
  2. source activate YOUR_ENV_NAME
  3. conda install ipykernel
  4. ipython kernel install --name YOUR_ENV_NAME --user

Once this is done, launch your python code from Jupyter notebook Select Kernel -> Change Kernel ->YOUR_ENV_NAME

You can install tensorflow and other packages within this environment,