我有一个conda环境,它在使用Cython时显示了一个bug。我无法在不消除bug的情况下减少依赖项列表,因此下面是完整的环境:
# 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
创建环境:conda env create -f environment.yml
激活它:conda activate test
创建文件helloworld.pyx
:
print("Hello World")
创建setup.py
:
from distutils.core import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
把它环化:python setup.py build_ext --inplace
使用python -c "import helloworld"
导入时,会出现以下错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'helloworld'
它创建了一个文件helloworld.cpython-37-x86_64-linux-gnu.so
,它应该在那里helloworld.cpython-37m-x86_64-linux-gnu.so
。实际上,如果您重命名它,您可以验证它是否正常工作:
mv helloworld.cpython-37-x86_64-linux-gnu.so helloworld.cpython-37m-x86_64-linux-gnu.so
在conda环境中,存在m
后缀:$CONDA_PREFIX/include/python3.7m
。我知道这与Python是否是用pymalloc编译的有关,但是我不明白为什么Cython在这个例子中没有看到它。你知道吗
它实际上是由conda forge中一个损坏的python3.7.6版本引起的。已经修好了。你知道吗
相关问题 更多 >
编程相关推荐