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
479 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named Cython.Distutils

I'm having a strange problem while trying to install the Python library zenlib, using its setup.py file. When I run the setup.py file, I get an import error, saying

ImportError: No module named Cython.Distutils`

but I do have such a module, and I can import it on the python command line without any trouble. Why might I be getting this import error?

I think that the problem may have to do with the fact that I am using Enthought Python Distribution, which I installed right beforehand, rather than using the Python 2.7 that came with Ubuntu 12.04.

More background: Here's exactly what I get when trying to run setup.py:

enwe101@enwe101-PCL:~/zenlib/src$ sudo python setup.py install
Traceback (most recent call last):
  File "setup.py", line 4, in <module>
    from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils

But it works from the command line:

>>> from Cython.Distutils import build_ext
>>> 
>>> from fake.package import noexist
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named fake.package

Note the first import worked and the second throws an error. Compare this to the first few lines of setup.py:

#from distutils.core import setup
from setuptools import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import os.path

I made sure that the Enthought Python Distribution and not the python that came with Ubuntu is what is run by default by prepending my bash $PATH environment variable by editing ~/.bashrc, adding this as the last line:

export PATH=/usr/local/epd/bin:$PATH

and indeed which python spits out /usr/local/epd/bin/python... not knowing what else to try, I went into my site packages directory, (/usr/local/epd/lib/python2.7/site-packages) and give full permissions (r,w,x) to Cython, Distutils, build_ext.py, and the __init__.py files. Probably silly to try, and it changed nothing.

Can't think of what to try next!? Any ideas?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Install Cython:

pip install cython

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

...