Nice programing

ImportError : Cython.Distutils라는 모듈이 없습니다.

nicepro 2021. 1. 6. 20:50
반응형

ImportError : Cython.Distutils라는 모듈이 없습니다.


파일을 zenlib사용하여 Python 라이브러리를 설치하는 동안 이상한 문제 setup.py있습니다. setup.py파일을 실행하면 다음과 같은 가져 오기 오류가 발생합니다.

ImportError : Cython.Distutils라는 모듈이 없습니다.

하지만 그런 모듈이 있으며 문제없이 파이썬 명령 줄에서 가져올 수 있습니다. 이 가져 오기 오류가 발생하는 이유는 무엇입니까?

문제는 우분투 12.04와 함께 제공되는 Python 2.7을 사용하는 것이 아니라 미리 설치 한 Enthought Python Distribution을 사용하고 있다는 사실과 관련이있을 수 있다고 생각합니다 .

더 많은 배경 : 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

그러나 명령 줄에서 작동합니다.

>>> 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

첫 번째 가져 오기가 작동하고 두 번째 가져 오기에서 오류가 발생합니다. 이것을 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

Ubuntu와 함께 제공되는 Python이 아닌 Enthought Python Distribution이 기본적으로 실행되는지 확인하고 편집 ~/.bashrc하여 내 bash $ PATH 환경 변수를 앞에 추가하고이를 마지막 줄에 추가합니다.

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

실제로 which python밖으로 뱉어 /usr/local/epd/bin/python시도하는 그 밖의 무엇을 모르고 ..., 나는 내 사이트 패키지 디렉토리에 가서 ( /usr/local/epd/lib/python2.7/site-packages) 및 모든 권한을 (R, X, W)을 얻었다 Cython, Distutils, build_ext.py, 그리고 __init__.py파일. 시도하는 것은 어리석은 일이지만 아무것도 바뀌지 않았습니다.

다음에 무엇을 시도할지 생각할 수 없습니다!? 어떤 아이디어?


귀하의 sudo가 올바른 파이썬을 얻지 못하고 있습니다. 이것은 Ubuntu에서 sudo의 알려진 동작입니다. 자세한 내용은이 질문 을 참조하십시오. sudo가 전체 경로를 사용하여 올바른 파이썬을 호출하는지 확인해야합니다.

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

또는 다음을 수행합니다 (bash에서).

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

Cython 설치 :

pip install cython

운영

which python

시스템이 기본값으로 설정 한 파이썬의 경로이기도 한 다음 @tiago의 방법으로 이동하십시오.

sudo <output of which python> setup.py install


python3의 경우

sudo apt-get install cython3

python2의 경우

sudo apt-get install cython

세부에서 읽을 수있는


한 가지 조언 만 드릴게요 : 가상 환경을 만드세요. 이렇게하면 하나의 Python 버전과 모든 패키지가 로컬로 설치되고 전체 시스템에는 설치되지 않습니다.
해결책 중 하나 여야합니다.


CLI-python에서 sys를 가져 와서 sys.path 안에 무엇이 있는지
확인한 다음export PYTHONPATH=whatyougot


Running the following commands resolved the issue for me in 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


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.

It will upgrade your easy_install built in python.


Just install Cython from http://cython.org/#download and install it using this command

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.

ReferenceURL : https://stackoverflow.com/questions/11108461/importerror-no-module-named-cython-distutils

반응형