简体   繁体   English

导入错误:没有名为 Cython.Distutils 的模块

[英]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.我在尝试使用setup.py文件安装 Python 库zenlib时遇到了一个奇怪的问题。 When I run the setup.py file, I get an import error, saying当我运行setup.py文件时,出现导入错误,说

ImportError: No module named Cython.Distutils`导入错误:没有名为 Cython.Distutils 的模块

but I do have such a module, and I can import it on the python command line without any trouble.但是我确实有这样一个模块,我可以在 python 命令行上毫无困难地导入它。 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.我认为问题可能与我使用的是预先安装的Enthought Python Distribution的事实有关,而不是使用 Ubuntu 12.04 附带的 Python 2.7。

More background: Here's exactly what I get when trying to run setup.py:更多背景:这正是我在尝试运行 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:将此与 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:我通过编辑~/.bashrc将我的 bash $PATH 环境变量添加到最后一行,以确保默认情况下运行的是 Enthought Python Distribution 而不是 Ubuntu 附带的 python:

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.确实which python吐出/usr/local/epd/bin/python ... 不知道还能尝试什么,我进入了我的站点包目录,( /usr/local/epd/lib/python2.7/site-packages ) 并授予CythonDistutilsbuild_ext.py__init__.py文件的完全权限 (r,w,x)。 Probably silly to try, and it changed nothing.尝试可能很愚蠢,但它什么也没改变。

Can't think of what to try next!?想不出接下来要尝试什么!? Any ideas?有任何想法吗?

安装 Cython:

pip install cython

Your sudo is not getting the right python.你的 sudo 没有得到正确的 python。 This is a known behaviour of sudo in Ubuntu.这是 sudo 在 Ubuntu 中的已知行为。 See this question for more info.有关更多信息,请参阅此问题 You need to make sure that sudo calls the right python, either by using the full path:您需要确保 sudo 调用正确的 python,或者使用完整路径:

sudo /usr/local/epd/bin/python setup.py install

or by doing the following (in bash):或通过执行以下操作(在 bash 中):

alias sudo='sudo env PATH=$PATH'
sudo python setup.py install

For python3 use对于python3使用

sudo apt-get install cython3

For python2 use对于python2使用

sudo apt-get install cython

Details can be read at this详情可在阅读

Run跑步

which python

Thats the path to the python that your system has defaulted too then go to @tiago's method of:这就是你的系统默认的 python 路径,然后转到@tiago的方法:

sudo <output of which python> setup.py install

I only got one advice for you : Create a virtualenv.我只有一个建议给你:创建一个 virtualenv。 This will ensure you have only one version of python and all your packages installed locally (and not on your entire system).这将确保您只有一个版本的 python 并且所有软件包都安装在本地(而不是整个系统上)。
Should be one of the solutions.应该是解决方案之一。

In the CLI-python, import sys and look what's inside sys.path在 CLI-python 中,导入 sys 并查看 sys.path 中的内容
Then try to use export PYTHONPATH=whatyougot然后尝试使用export PYTHONPATH=whatyougot

Running the following commands resolved the issue for me in ubuntu 14.04:在 ubuntu 14.04 中运行以下命令为我解决了这个问题:

sudo apt-get install python-dev    
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libsystemd-daemon-dev
sudo pip install cython

This link helped me: https://github.com/trezor/python-trezor/issues/40这个链接对我有帮助: https : //github.com/trezor/python-trezor/issues/40

Ran into this again in modern times.在现代再次遇到这个问题。 The solution was simple:解决方法很简单:

pip uninstall cython && pip install cython

That is easy.那很容易。

You could try install cython package first.您可以先尝试install cython包。

It will upgrade your easy_install built in python.它将升级您的easy_install内置python。

I had dependency from third party library on Cython, didn't manage to build the project on Travis due to the ImportError.我在 Cython 上依赖于第三方库,由于 ImportError 无法在 Travis 上构建项目。 In case someone needs it - before installing requirements.txt run this command:如果有人需要它 - 在安装 requirements.txt 之前运行以下命令:

pip install Cython --install-option="--no-cython-compile" pip install Cython --install-option="--no-cython-compile"

Installing GCC also might help.安装 GCC 也可能有帮助。

Read like a thousand of these threads and finally got it for Python 3. (replace pip with pip3 if you have that kind of installation, and run pip uninstall cython if you have tried other solutions before running any of these)读一千个这样的线程,最后得到它用于 Python 3。(如果你有那种安装,用 pip3 替换 pip,如果你在运行任何这些之前尝试过其他解决方案,请运行pip uninstall cython

Mac:苹果:

brew install cython
pip install --upgrade cython

Ubuntu Ubuntu

sudo apt-get install cython3 python-dev  
pip install --upgrade cython

Windows (must have conda, and MinGW already in path) Windows(必须有 conda,并且 MinGW 已经在路径中)

conda install cython
conda install --upgrade cython

Just install Cython from http://cython.org/#download and install it using this command只需从http://cython.org/#download安装 Cython 并使用此命令安装它

sudo python setup.py install

Then run the command然后运行命令

sudo python -c 'import Cython.Distutils'

and it will be installed and the error message will disappear.它将被安装并且错误消息将消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入错误:没有名为 distutils 的模块 - ImportError: No module named distutils 导入错误:没有名为“Cython”的模块 - ImportError: No module named 'Cython' Cython ImportError:没有名为并行的模块 - Cython ImportError: No module named parallel 导入错误:pandas pyinstaller 中没有名为“distutils”的模块 - ImportError: No module named 'distutils' in pandas pyinstaller cygdb ImportError:没有名为'Cython'的模块 - cygdb ImportError: No module named 'Cython' ImportError:没有名为numpy.distutils.core的模块(Ubuntu xgboost安装) - ImportError: No module named numpy.distutils.core (Ubuntu xgboost installation) ImportError:没有名为numpy.distutils.core的模块(在安装keras期间) - ImportError: No module named numpy.distutils.core (during keras installation) Cython:ImportError:没有名为&#39;myModule&#39;的模块:如何将包含cimport的cython模块调用到另一个cython结节? - Cython: ImportError: No module named 'myModule': how to call a cython module containing a cimport to another cython nodule? ImportError:AppEngine标准本地中没有名为grpc._cython.cygrpc的模块 - ImportError: No module named grpc._cython.cygrpc in AppEngine standard local 无法使用distutils构建Cython模块 - Failure to build Cython module using distutils
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM