Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

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

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...