2

I'm working on a python code. This code uses a library that is written in cython. when I run, I face this error:

enter image description here

I use python3.7. I've searched a lot but I couldn't find a useful way to solve it. I think that visual cpp has not been matched with python. First I had visual cpp 2017 but didn't work and I uninstalled it. After that I installed only visualcppbuildtools but the result didn't change. Can anyone help me? (Also I added the below part to my code but the result didn't change.)

enter image description here

This is setup.py :

from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy
ext_modules=[
    Extension("lib2",
              ["lib2.pyx"],
              language="c++", 
              libraries=["m"],
              extra_compile_args = ["-std=c++11", "-O3", "-ffast-math", "- 
              march=native", "-fopenmp" ],
              extra_link_args=['-fopenmp'],
              include_dirs=[numpy.get_include()]
              ) 
    ]

setup( 
  name = "lib2",
  cmdclass = {"build_ext": build_ext},
  ext_modules = ext_modules,
  include_dirs=[numpy.get_include()]
)

this the main.py:

import sys
sys.path.append('E:\EDU\Hipp\septo-hippocampal-model-master\septo- 
hippocampal-model-master\cython_code')
import pyximport
pyximport.install()
import lib2 as lib

and the last one is lib2.pyx:

from libc.math cimport exp, cos
from libcpp.map cimport map
from libcpp.pair cimport pair
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp cimport bool
from cython.operator cimport dereference, preincrement
import numpy as np
cimport numpy as np
from libcpp.queue cimport queue
from cython.parallel cimport parallel, prange
cimport cython

By those simple codes I still receive the above error.

MH.AI.eAgLe
  • 592
  • 1
  • 6
  • 22
  • Please paste your code and error messages as text, don't use screenshots. – dspencer Apr 09 '20 at 04:38
  • The code is too massive – MH.AI.eAgLe Apr 09 '20 at 05:14
  • You need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – dspencer Apr 09 '20 at 05:14
  • I added an example of an error situation. – MH.AI.eAgLe Apr 09 '20 at 05:47
  • 3
    Using both setup.py and pyximport makes no sense. You should pick one and stick to it. I'd guess the problem is the numpy include path isn't give by pyximport (and since you never use setup.py then specifying it there is pointless). The more useful bit if the error message is probably earlier. – DavidW Apr 09 '20 at 06:27
  • 2
    btw your setup.py is for gcc and not msvc. I think best is to adapt setup.py than to use pyximport, which involves more magic and is more complicated to fix if something go wrong (and more people can help with setup.py than with pyximport). – ead Apr 09 '20 at 06:53
  • Here is a starting point how things can be done with pyximport: https://stackoverflow.com/a/14678559/5769463, however you will need to add c++ as language and at least openmp as compile/link option. – ead Apr 09 '20 at 07:00

0 Answers0