2016-08-11 4 views
1

2 일 동안 오류로 고생했습니다. 스택 오버플로에서 답변을했지만 행운을 보지 않았습니다. 나는 관리자에서 모델에 접근하고 때 프로덕션 서버에서 장고 이미지 필드ImportError : 이름을 가져올 수 없습니다. _imaging 장고 관리 베개에서 액세스

class Author(models.Model): 
    first_name = models.CharField(max_length=30) 
    last_name = models.CharField(max_length=30) 
    email = models.EmailField() 
    url = models.URLField(blank=True, null=True) 
    short_bio = models.TextField(max_length=200, blank=True, null=True) 
    long_bio = models.TextField(max_length=5000, blank=True, null=True) 
    role = models.ManyToManyField(AuthorRole) 
    facebook_link = models.URLField(blank=True, null=True) 
    linkedin_link = models.URLField(blank=True, null=True) 
    twitter_link = models.URLField(blank=True, null=True) 
    gplus_link = models.URLField(blank=True, null=True) 
    thumbnail = models.ImageField(upload_to='images/',  default='images/user_default.jpg') 

를 사용하여 이미지를 선택하고 다음과 같은 오류를 던지고, 저장하려고 간단한 모델을 가지고있다. 나는 여러 번 베개를 설치하고 제거했다. 장고와 베개의 다른 버전을 사용해 보았습니다. 그건 그렇고 로컬 환경에서 잘 작동합니다.

[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881] 
from PIL import Image 
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881]  File"/home/.virtualenvs/wcsenvpython3/lib/python3.4/sitepackages/PIL/Image.py", line 67, in <module> 
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881] 
from PIL import _imaging as core 
[:error] [pid 20256:tid 139822013380352] [remote 72.48.102.12:60881] ImportError:cannot import name _imaging 

manage.py 셸에서 from PIL import _imaging 할 수 있습니다. 그래서 pythonpath가 올바르게 설정되어있는 것 같습니다. enter image description here

내 virtualenv 내부에서 _imaging.cpython-34m.so 파일을 볼 수 있지만 _imaging.py 파일이 없습니다. enter image description here

내 서버는 linode에서 호스팅됩니다. 그것은 우분투 14.04입니다. 나는 Apache2를 사용하고있다. 파이썬 3.4.3. 장고 1.10 베개 3.3.0. 친절한 도움은 대단히 중요합니다. 이 오류는 오랫동안 나를 괴롭 히고 있습니다.

1

: http://i.stack.imgur.com/nH8O3.jpg 2 : http://i.stack.imgur.com/Vpdoe.jpg

+0

베개를 다시 설치하는 데 사용한 명령은 무엇입니까? –

+0

pip uninstall 베개를 설치 한 후 pip 설치 베개. 귀하의 회신에 감사드립니다. 나는 그 해답을 발견했다. 아래 내 대답을 확인하십시오. –

답변

1

좋아, 나는 마침내 해답을 얻었다. 그것은 베개와 아무런 관련이 없습니다. 이미지를 저장하고 갑자기 문제를 해결 한 'media'폴더에 public에 대한 쓰기 권한을 부여했습니다. 보안 취약점인지 확실치 않지만 오류를 해결합니다.

어떻게 찾았습니까?
Image.py 파일을 PIL로 변경하기로 결정했습니다.

try: 
    # If the _imaging C module is not present, Pillow will not load. 
    # Note that other modules should not refer to _imaging directly; 
    # import Image and use the Image.core variable instead. 
    # Also note that Image.core is not a publicly documented interface, 
    # and should be considered private and subject to change. 
    from PIL import _imaging as core 
    if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None): 
     raise ImportError("The _imaging extension was built for another " 
          " version of Pillow or PIL") 

except ImportError as v: 
    core = _imaging_not_installed() 
    # Explanations for ways that we know we might have an import error 
    if str(v).startswith("Module use of python"): 
     # The _imaging C module is present, but not compiled for 
     # the right version (windows only). Print a warning, if 
     # possible. 
     warnings.warn(
      "The _imaging extension was built for another version " 
      "of Python.", 
      RuntimeWarning 
      ) 
    elif str(v).startswith("The _imaging extension"): 
     warnings.warn(str(v), RuntimeWarning) 
    elif "Symbol not found: _PyUnicodeUCS2_" in str(v): 
     # should match _PyUnicodeUCS2_FromString and 
     # _PyUnicodeUCS2_AsLatin1String 
     warnings.warn(
      "The _imaging extension was built for Python with UCS2 support; " 
      "recompile Pillow or build Python --without-wide-unicode. ", 
      RuntimeWarning 
      ) 
    elif "Symbol not found: _PyUnicodeUCS4_" in str(v): 
     # should match _PyUnicodeUCS4_FromString and 
     # _PyUnicodeUCS4_AsLatin1String 
     warnings.warn(
      "The _imaging extension was built for Python with UCS4 support; " 
      "recompile Pillow or build Python --with-wide-unicode. ", 
      RuntimeWarning 
      ) 
    # Fail here anyway. Don't let people run with a mostly broken Pillow. 
    # see docs/porting.rst 
    raise 

except 블록은 몇 가지 조건을 검사하고 마지막 행은 다시 가져 오기 오류를 발생시킵니다. 나는 raise를 주석 처리하고, 빙고는 저에게 허가 오류를 보였다. 문제가 허가 된 동안 지구에서 왜 가져 오기 오류가 표시되는지 모르겠습니다. 나는 베개의 작가가 문제를보고 문제가 정말로 오히려 오류를 가져 오지 않고 관련 오류 메시지를 생성하려고 시도 할 것을 기대합니다.