1

I have 64-bit Windows 7 and 64-bit Python installed.

C:\Work\Python>python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

I installed primesieve using this:

C:\Work\Python>pip install primesieve
Collecting primesieve
  Using cached primesieve-1.3.0-cp36-cp36m-win_amd64.whl
Installing collected packages: primesieve
Successfully installed primesieve-1.3.0

I am then trying to run a Python program/script which is
importing this primesieve library but I am getting this error:

C:\Work\Python>run 500A

C:\Work\Python>python EulerProblem500A.py
Traceback (most recent call last):
  File "EulerProblem500A.py", line 1, in <module>
    import primesieve # pip install primesieve
  File "C:\Programs\Python36\lib\site-packages\primesieve\__init__.py", line 1, in <module>
    from primesieve._primesieve import *
ImportError: DLL load failed: %1 is not a valid Win32 application.

I don't understand this error since the versions of OS, Python and primesieve library all match.

Any ideas?!

peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • Do you have the correct version? This might happen if for example your python is 32 bit and the lib is 64, or reversed. I had a similar problem and I had to reinstall python using the 64bit version. Might not be the best solution, but worth a try (make sure you backup stuff you need). – N. Ivanov Dec 12 '17 at 09:02
  • @N.Ivanov Well, I specifically mentioned which bit versions I have. – peter.petrov Dec 12 '17 at 09:02
  • That does not necessarily mean that you are using the correct ones. For example have you checked your python Path if it is pointing towards the correct version/directory? – N. Ivanov Dec 12 '17 at 09:04
  • @N.Ivanov I only have 1 python version installed which is 3.6.3 64-bit. – peter.petrov Dec 12 '17 at 09:05
  • I guess, you have seen this update here: https://stackoverflow.com/questions/14629818/importerror-dll-load-failed-1-is-not-a-valid-win32-application – Mr. T Dec 12 '17 at 09:23
  • @Piinthesky No, I haven't. Thanks. What does it mean in my case? That I need to add the primesieve binaries to the WINDOWS path? If so, where can I find these binaries? I am new to Python. All I see is a pyd file here: C:\Programs\Python36\Lib\site-packages\primesieve – peter.petrov Dec 12 '17 at 09:25
  • I wouldn't even pretend to have Windows knowledge. Apart from that - I know, you mentioned that you have Win 64 bit. But why does Python say in the first message `on win32`? – Mr. T Dec 12 '17 at 09:46
  • @Piinthesky I don't know. But the OS is 64-bit. I guess it is normal to see that message. – peter.petrov Dec 12 '17 at 09:47

1 Answers1

-1

Looking at the source code , you should import the following;

from libc.stdint cimport uint64_t, int64_t
from libcpp.vector cimport vector
cimport cpp_primesieve

Seems like cython

Try:

pip install cython 

Also see https://github.com/hickford/primesieve-python

Mo. Atairu
  • 753
  • 8
  • 15