[英]Cython doesn't recognize pymalloc Python
I have a conda environment which exhibits a bug when using Cython.我有一个 conda 环境,在使用 Cython 时会出现错误。 I was not able to reduce the dependency list without making the bug disappear, so here is the full environment:
我无法在不使错误消失的情况下减少依赖项列表,所以这里是完整的环境:
# environment.yml
name: test
channels:
- conda-forge
- defaults
dependencies:
- pip
- compilers
- make
- setuptools
- cython
- daetk
- hdf5 =*=*mpich*
- h5py =*=*mpich*
- metis
- mpich
- numpy
- openblas
- parmetis
- petsc4py
- petsc
- python=3
- scorec
- superlu
- superlu_dist
- triangle
- pychrono
- mpi4py
- gmsh
- matplotlib
- mpi4py
- nose
- pytables
- pytest
- pytest-cov
- pytest-xdist
- scipy
- tetgen
- ncurses
- pychrono
- python=3
- future
- ipyparallel
- pillow
- recordtype
Create the environment with: conda env create -f environment.yml
创建环境:
conda env create -f environment.yml
Activate it: conda activate test
激活它:
conda activate test
Create a file helloworld.pyx
:创建一个文件
helloworld.pyx
:
print("Hello World")
Create a setup.py
:创建一个
setup.py
:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
Cythonize it: python setup.py build_ext --inplace
Cythonize 它:
python setup.py build_ext --inplace
When you import it with python -c "import helloworld"
, you get the following error:当您使用
python -c "import helloworld"
导入它时,您会收到以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'helloworld'
It created a file helloworld.cpython-37-x86_64-linux-gnu.so
, where it should have been helloworld.cpython-37m-x86_64-linux-gnu.so
.它创建了一个文件
helloworld.cpython-37-x86_64-linux-gnu.so
,它应该是helloworld.cpython-37m-x86_64-linux-gnu.so
。 Indeed you can verify that it works fine if you rename it:事实上,如果你重命名它,你可以验证它是否工作正常:
mv helloworld.cpython-37-x86_64-linux-gnu.so helloworld.cpython-37m-x86_64-linux-gnu.so
And in the conda environment the m
suffix is present: $CONDA_PREFIX/include/python3.7m
.在 conda 环境中,存在
m
后缀: $CONDA_PREFIX/include/python3.7m
。 I know it is related with whether Python was compiled with pymalloc, but I don't understand why Cython doesn't see that it was in this case.我知道这与 Python 是否使用 pymalloc 编译有关,但我不明白为什么 Cython 没有看到它在这种情况下。
It was actually caused by a broken build of Python 3.7.6 in conda-forge.它实际上是由 conda-forge 中 Python 3.7.6 的一个损坏的构建引起的。 It has been fixed.
它已被修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.