6

I'm using the PySpin api for a Point Grey camera in Anaconda. The api is a Python wrapper for a C++ library called Spinnaker (https://www.ptgrey.com/spinnaker-sdk).

When I import within Spyder (import PySpin), things work fine (note I start Spyder from the Conda prompt in the environment where everything is installed). Unfortunately running the import from the conda prompt instead of Spyder (python foo.py where foo.py contains import PySpin) yields:

Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.

The ordinal 242 could not be located in the dynamic link library C:\Anaconda3\Library\bin\mkl_intel_thread.dll

Note I installed Spinnaker (PySpin) from a wheel at the anaconda prompt:

pip install spinnaker_python-1.20.0.15-cp36-cp36m-win_amd64.whl

A bunch of places online it says to find the following files in C:\Windows\System32 and rename them or delete them:

mkl_core.dll
mkl_def.dll
mkl_intel_thread.dll

Those files are not present on my machine, so that seems to not be the problem in my case.

For instance here they mention that solution:
The ordinal 242 could not be located in the dynamic link library Anaconda3\Library\bin\mkl_intel_thread.dll

eric
  • 7,142
  • 12
  • 72
  • 138
  • 1
    You said `Note I installed Spinnaker (PySpin) from a wheel at the anaconda prompt`. That's most probably what introduced the error because pip and conda packages are not compatible if they have binary dependencies. However, I think this problem is solved if you update Python with `conda update python`. – Carlos Cordoba Apr 22 '19 at 08:06
  • @CarlosCordoba : unfortunately everything is up to date. What is bizarre is it works fine from within Spyder, or the ipython window launched from conda prompt (`%run foo.py`). But working from the same working directory at the anaconda prompt entering `python foo.py` gives the above error (in a pop-up window). – eric Apr 22 '19 at 15:03
  • Ummm....I don't know what happened, but after running ipython in my conda prompt, and running `%run foo.py`, and exiting, everything is now working when I just run `python foo.py` from my anaconda prompt. – eric Apr 22 '19 at 15:06
  • @CarlosCordoba I turned it into an answer, but if you have a fuller explanation I will gladly accept it as the answer because I have no idea why this worked! – eric Apr 22 '19 at 18:37
  • Sorry, I have no idea. – Carlos Cordoba Apr 22 '19 at 20:36
  • It becomes even weirder if you have conda 4.2 ran conda/anaconda updates and side packages too from py3.2>3.4 to 3.5.6 and for sake all up to 3.7.3 via 3.6. Then there are a huge amount of mkl files and the error keeps bouncing until you uninstalled them all which take approximately 30 mins (each time an numpy update (read: downgrade). Long story short... fresh conda install 4.6.14 makes your day and you'll loose less time in reinstall processes. Then only one pip update numpy, matplot and pandas to go for :-) – ZF007 May 28 '19 at 21:54

3 Answers3

4

When I first import numpy and the import PySpin, then it works for me.

import numpy as np # must be imported first
import PySpin

system = PySpin.System.GetInstance()
version = system.GetLibraryVersion()
print('Library version: %d.%d.%d.%d' % (version.major, version.minor, version.type, version.build))
# Library version: 1.20.0.15

I am using Python 3.5 under Windows 10 with Miniconda.

Dale K
  • 25,246
  • 15
  • 42
  • 71
codingmonkey87
  • 186
  • 1
  • 4
  • I made this the accepted answer because it always works for me and is simplest. Messing around with changing how I install numpy did not work consistently and messed up my environment. The other solution of running the code from ipython from the conda prompt is just inelegant. Since in practice, this is what I have ended up doing, I've accepted this answer: thanks for the tip! – eric Apr 28 '19 at 13:52
3

The issue is caused by file libiomp5md.dll included in the spinnaker_python wheel being incompatible with Anaconda distribution. Simply removing or renaming this file will result the default Anaconda version of the file to be loaded instead.

Execute the following command from the Anaconda prompt to fix the issue. If Anaconda is installed for all users, you need Administrator version of Anaconda prompt.

move %CONDA_PREFIX%\Lib\site-packages\PySpin\libiomp5md.dll %CONDA_PREFIX%\Lib\site-packages\PySpin\libiomp5md.bak
Tomi
  • 391
  • 1
  • 3
  • 8
1

Solution recommended by Point Grey

From the developers at Point Grey, who I emailed about this issue and they were aware of it. They suggested removing the numpy that is installed with conda and reinstall it with pip. That is:

conda uninstall numpy
pip install numpy

Note while this worked, I can't guarantee it will scale well within complex projects that include other dependencies.

Update: this worked for a day or so, but in my hands it stopped working when I added other dependencies/updates (in particular OpenCV). However, maybe other people will have better luck with this solution so I'll leave it here.


Second Solution

If you are having trouble with the other solutions, maybe give this a shot it worked for me: run the code from ipython launched from the conda prompt, and then run from conda again:

ipythyon
%run foo.py  #script containing import PySpin
exit()

It worked there, which is not surprising (this is basically what Spyder does). Strangely, back in the conda prompt I tried running the program again:

python foo.py

And this time it worked. So, it was not working before I did it in ipython, and now it is working.

Frankly I have no idea why this fixed the problem, but it did. \_(ツ)_/

I'm leaving these solutions here, but frankly I would try importing numpy before PySpin, as in the accepted answer. It's just easier and less disruptive.

eric
  • 7,142
  • 12
  • 72
  • 138