I got ModuleNotFoundError: No module named 'Cython' when trying to make Extension

北城以北 提交于 2021-02-11 16:55:08

问题


I'm trying to run this code :

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
ext_modules = [
    Extension("sum",  ["a123.pyx"])]

setup(
    name = 'app',
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules
)

and I got this Error :

Traceback (most recent call last):
  File "compile.py", line 3, in <module>
    from Cython.Distutils import build_ext
ImportError: No module named 'Cython'

I'm using Conda and I add cython to it also I'm installing cython in my system.but error doesnot fix!


回答1:


It may be a case that you have installed cython in other conda environment. Make sure that you activate that conda environment in which you installed cython.

conda activate installed_env_name

Replace "installed_env_name" with your environment name in which you installed cython.

For example if you installed cython in base env, then do this

conda activate base

It may be a case that you are working in a different conda environment but installed cython in other environment mistakenly. So you need to install cython in your working environment. So, first activate the env in anaconda prompt :

conda activate working_env_name

Replace "working_env_name" with your working environment name. Then install cython

pip install cython

Futher, if you are using spyder from anaconda, make sure you launch spyder from the environment in which cython is installed.




回答2:


It's fixed by uninstall cython in conda and reinstall it Again!

uninstall with :

conda uninstall cython

reinstall with :

conda install -c anaconda cython


来源:https://stackoverflow.com/questions/65759328/i-got-modulenotfounderror-no-module-named-cython-when-trying-to-make-extensio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!