본문 바로가기
Programming

<장고 + 부트스트랩 파이썬 웹개발의 정석> 스터디로그 (1)

by 느리게 걷는 즐거움 2022. 5. 16.
반응형

 

Docker Image Build

책에서 사용하는 docker의 base 이미지인 3.8.0-alpine으로 빌드 시 라이브러리 관련 빌드에러가 발생합니다. 아래의 reference 링크를 참고해서 python:3.8-slim-buster로 수정하고 RUN apk 부분을 삭제하면 정상적으로 빌드됩니다.

 

Docker Compose Up

docker image 생성을 위해 빌드 후 docker-compose up 수행 시 에러가 발생합니다. window기반으로 pip install 및 동작시에는 fromshare 부분이 문제가 발생하지 않지만 docker의 linux 이미지를 기반으로 빌드 시 아래와 같이 에러가 발생합니다.

C:\00_PRJ\django_blog(main -> origin)
(django) λ docker-compose up
[+] Running 1/1
 - Container django_blog-web-1  Recreated                                                                       0.1s
Attaching to django_blog-web-1
django_blog-web-1  | Watching for file changes with StatReloader
django_blog-web-1  | Performing system checks...
django_blog-web-1  |
django_blog-web-1  | Exception in thread django-main-thread:
django_blog-web-1  | Traceback (most recent call last):
django_blog-web-1  |   File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
django_blog-web-1  |     self.run()
django_blog-web-1  |   File "/usr/local/lib/python3.8/threading.py", line 870, in run
django_blog-web-1  |     self._target(*self._args, **self._kwargs)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
django_blog-web-1  |     fn(*args, **kwargs)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run
django_blog-web-1  |     self.check(display_num_errors=True)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check
django_blog-web-1  |     all_issues = checks.run_checks(
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks
django_blog-web-1  |     new_errors = check(app_configs=app_configs, databases=databases)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config
django_blog-web-1  |     return check_resolver(resolver)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver
django_blog-web-1  |     return check_method()
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 416, in check
django_blog-web-1  |     for pattern in self.url_patterns:
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
django_blog-web-1  |     res = instance.__dict__[self.name] = self.func(instance)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 602, in url_patterns
django_blog-web-1  |     patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__
django_blog-web-1  |     res = instance.__dict__[self.name] = self.func(instance)
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 595, in urlconf_module
django_blog-web-1  |     return import_module(self.urlconf_name)
django_blog-web-1  |   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
django_blog-web-1  |     return _bootstrap._gcd_import(name[level:], package, level)
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
django_blog-web-1  |   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_blog-web-1  |   File "/usr/src/app/django_blog/urls.py", line 26, in <module>
django_blog-web-1  |     path('blog/', include('blog.urls')),
django_blog-web-1  |   File "/usr/local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include
django_blog-web-1  |     urlconf_module = import_module(urlconf_module)
django_blog-web-1  |   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
django_blog-web-1  |     return _bootstrap._gcd_import(name[level:], package, level)
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
django_blog-web-1  |   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
django_blog-web-1  |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
django_blog-web-1  |   File "/usr/src/app/blog/urls.py", line 2, in <module>
django_blog-web-1  |     from . import views
django_blog-web-1  |   File "/usr/src/app/blog/views.py", line 9, in <module>
django_blog-web-1  |     from .forms import CommentForm
django_blog-web-1  |   File "/usr/src/app/blog/forms.py", line 1, in <module>
django_blog-web-1  |     from socket import fromshare
django_blog-web-1  | ImportError: cannot import name 'fromshare' from 'socket' (/usr/local/lib/python3.8/socket.py)

 

stackover flow에 따르면 socket 라이브러리에서 사용하는 fromshare는 window에서만 사용하기 때문에 리눅스에서 빌드시 import를 못하는 것으로 보입니다. 코드 상에서 import fromshare부분을 제거한 후 다시 빌드하면 docker-compose up시 실행됩니다.

 

 

Reference

https://stackoverflow.com/questions/70964967/python-django-heroku-importerror-cannot-import-name-fromshare-from-so

https://doitdjango.com/blog/4/

 

 

반응형