cythonize

Can't redirect error stream from Cython

笑着哭i 提交于 2019-12-12 22:21:23
问题 The SFML library that I'm trying to cythonize defines this function below that allows to change where errors are printed to (by default SFML writes error messages to the console when this function is not called): namespace sf { std::ostream& err() { static DefaultErrStreamBuf buffer; static std::ostream stream(&buffer); return stream; } } My simplified .pxd file for the above function: cdef extern from 'SFML/System.hpp' namespace 'sf': ostream& cerr 'sf::err' () And my .pyx module, which

Import error undefined symbol (C++ module in python) ZTINSt8ios_base7failureB5cxx11E

…衆ロ難τιáo~ 提交于 2019-12-11 03:14:37
问题 I know there are lots of similar questions on the website but I couldn't find an answer to my problem. I'm wrapping C++ classes with Cython in order to use them with Python3. After building the external module with a setup.py , when I run the python program I got the following error: from "name of.pyx file" import "name of the class to import" Import error: /home/.../filename.so: undefined symbol: _ZTINSt8ios_base7failureB5cxx11E. I'm on Ubuntu 16.04, I build the extensions from the terminal

Attempting to build a cython extension to a python package, not creating shared object (.so) file

谁说胖子不能爱 提交于 2019-12-11 01:29:33
问题 I have attempted to use the answer here to add the building of a cython extension into my package. It currently cythonizes the code to produce a .c file from the .pyx file but doesn't create a shared object .so file, as such when I try to import the package, and one of the modules attempts to import the shared object file it cannot find it. My setup.py file (this is slightly cut-down) is like so: from setuptools import setup from setuptools.extension import Extension import os import numpy

Cython cimport cannot find .pxd module

和自甴很熟 提交于 2019-12-10 10:37:41
问题 Solved, see Edit #3 Assume a package is structured as: Some_Package/ some_package/ __init__.py core/ __init__.py definition.pxd helper/ __init__.py helper.pxd helper.pyx setup.py Where in definition.pxd I have: import numpy as np cimport numpy as np # ... ctypedef np.int32_t INT_t And in helper.pxd I have: cimport some_package.core.definition from some_package.core.definition cimport INT_t # ... In helper.pyx I didn't cimport anything. I configured setup.py as: ext_modules=cythonize('./some

How to import depending cython modules from parent folder in python

試著忘記壹切 提交于 2019-12-08 05:35:58
问题 Imagine the following folder structure: /project run.py /Helper Helper.pxd Helper.pyx setup.py /Settings Settings.pxd Settings.pyx setup.py Helper uses the types Settings and PySettings defined in Settings.pxd. Therefor in Helper.pxd I'm doing: from Settings cimport Settings, PySettings In the setup.py in the Helper directory I put include_path=[".", "../Settings/"] in the cythonize command. Thus Helper knows about Settings and everything compiles. In run.py I'd like to import Settings as

LINK : fatal error LNK1104: cannot open file 'C:\Users\hp\.pyxbld\lib.win32-2.7\gensim\models\word2vec_inner.pyd'

只谈情不闲聊 提交于 2019-12-07 16:52:13
问题 I run the sourcecode of TWE model. I need to compile the C extension of python. I have installed the Microsoft Visual C++ Compiler for Python 2.7 and Cython. First, I need to run the TWE/train.py: import gensim sentence_word = gensim.models.word2vec.LineSentence("tmp/word.file") print "Training the word vector..." w = gensim.models.Word2Vec(sentence_word,size=400, workers=20) sentence = gensim.models.word2vec.CombinedSentence("tmp/word.file","tmp/topic.file") print "Training the topic vector.

Cython: How to print without GIL

混江龙づ霸主 提交于 2019-12-07 03:40:02
问题 How should I use print in a Cython function with no gil? For example: from libc.math cimport log, fabs cpdef double f(double a, double b) nogil: cdef double c = log( fabs(a - b) ) print c return c gives this error when compiling: Error compiling Cython file: ... print c ^ ------------------------------------------------------------ Python print statement not allowed without gil ... I know how to use C libraries instead of their python equivalent ( math library for example here) but I couldn't

Cython cimport cannot find .pxd module

两盒软妹~` 提交于 2019-12-06 09:19:16
Solved, see Edit #3 Assume a package is structured as: Some_Package/ some_package/ __init__.py core/ __init__.py definition.pxd helper/ __init__.py helper.pxd helper.pyx setup.py Where in definition.pxd I have: import numpy as np cimport numpy as np # ... ctypedef np.int32_t INT_t And in helper.pxd I have: cimport some_package.core.definition from some_package.core.definition cimport INT_t # ... In helper.pyx I didn't cimport anything. I configured setup.py as: ext_modules=cythonize('./some_package/helper/helper.pyx', include_dirs=['.', './some_package/core']) Now my problem is with python

How to build cython pyx to pyd in anaconda(python3.6) in windows 8.1?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 14:42:33
I have referred some websites to build pyx to pyd in Windows 8.1.I 'm using Anaconda Distribution with Spyder IDE, I have developed pyx file and unable to build in "Anaconda Command Prompt" Anaconda> python setup.py build --inplace --compiler=mingw32 and tried python setup.py build_ext --inplace --compiler=mingw32 getting following error: File "C:\ProgramData\Anaconda3\lib\distutils\cygwinccompiler.py", line 129 in __init__ if self.ld_version >= "2.10.90": TypeError: '>=' not supported between instances of 'NoneType' and 'str' my simple pyx code is cdef int fib(int n): cdef int a, b, i a, b =

Cython class AttributeError

孤者浪人 提交于 2019-12-01 21:49:46
问题 I have started to experiment with Cython and ran into the following problem. Consider the following class representing a vertex in the 3D space: #Vertex.pyx cdef class Vertex(object): cdef double x, y, z def __init__(self, double x, double y, double z): self.x = x self.y = y self.z = z Now I try to create an object from the Python console: import Vertex as vt v1 = vt.Vertex(0.0, 1.0, 0.0) which works fine. However, when I'm trying to access the class attributes, I'm getting an AttributeError