성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Modules 창(Ctrl+Shift+U)을 띄워서, 해당 Op...
[정성태] 만드실 수 있습니다. 단지, Unity 엔진 내의 스크립트와 W...
[공진영] 안녕하세요 좋은글 감사합니다. 현재 제가 wpf로 관제 모...
[정성태] The Windows Registry Adventure #1: ...
[정성태] systemd for Developers I ; https:/...
[정성태] 엄밀히 object 타입의 인스턴스가 다른 타입으로 형변환 가능...
[정성태] 아래의 글에서 나오는 "Windows Application Pa...
[정성태] The history of calling conventions,...
[정성태] Secure and Deploy .NET Windows Form...
[정성태] Get Started with Milvus Vector DB i...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>uwsgi-plugin-python3 환경에서 "ModuleNotFoundError: No module named 'django'" 오류 발생</h1> <p> 희한하군요. ^^; 지난번 글에 따라,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > WSL Ubuntu 20.04에서 파이썬을 위한 uwsgi 설치 방법 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/12857'>https://www.sysnet.pe.kr/2/0/12857</a> </pre> <br /> 이번에는 docker에서 실습을 해봤습니다. "python:3.8-slim-buster" 이미지를 기반으로 환경 구성 후,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C:\temp> <span style='color: blue; font-weight: bold'>docker run -p 18000:18000/tcp -v /d/temp/testprj/myapp:/app/myapp_root --name python38_uwsgi_demo_myapp --rm -it python:3.8-slim-buster /bin/bash</span> # <span style='color: blue; font-weight: bold'>apt update</span> # <span style='color: blue; font-weight: bold'>apt upgrade -y</span> # <span style='color: blue; font-weight: bold'>apt install python3-pip -y</span> # <span style='color: blue; font-weight: bold'>apt install uwsgi-core -y</span> # <span style='color: blue; font-weight: bold'>apt install uwsgi-plugin-python3 -y</span> # <span style='color: blue; font-weight: bold'>pip install django</span> </pre> <br /> uwsgi를 실행했는데,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # <span style='color: blue; font-weight: bold'>cd /app/myapp_root</span> # <span style='color: blue; font-weight: bold'>uwsgi --plugin /usr/lib/uwsgi/plugins/python3_plugin.so --http-socket :18000 --wsgi-file ./myapp/wsgi.py</span> *** Starting uWSGI 2.0.18-debian (64bit) on [Mon Dec 13 08:46:12 2021] *** compiled with version: 8.2.0 on 10 February 2019 02:42:46 os: Linux-5.10.76-linuxkit #1 SMP Mon Nov 8 10:21:19 UTC 2021 nodename: 95d2ed822c69 machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 4 current working directory: /app/build_root detected binary path: /usr/bin/uwsgi-core uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes detected max file descriptor number: 1048576 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uwsgi socket 0 bound to TCP address :18000 fd 3 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** <span style='color: blue; font-weight: bold'>Python version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]</span> *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x559217e27b60 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72920 bytes (71 KB) for 1 cores <span style='color: blue; font-weight: bold'>*** Operational MODE: single process *** Traceback (most recent call last): File "./myapp/wsgi.py", line 17, in <module> from django.core.wsgi import get_wsgi_application ModuleNotFoundError: No module named 'django'</span> unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode *** uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 1898, cores: 1) </pre> <br /> 재미있는 것은, 시스템의 python은 3.8.12 버전인데 uwsgi의 출력에는 3.7.3이라고 나온다는 점입니다. 아마도 제 짐작으로는 "uwsgi-plugin-python3" 모듈이 내부적으로 <a target='tab' href='https://www.sysnet.pe.kr/2/0/12861'>파이썬 런타임 환경을 제공</a>하는 것이 아닌가... 싶은데 혹시 아시는 분은 덧글 부탁드립니다. ^^<br /> <br /> 그나저나... 이 문제를 어떻게 해결해야 할지 모르겠군요. 일단, 이 상황에서 sys.path를 출력해 보면 다음의 결과를 얻습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > ['.', '', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload'] </pre> <br /> 그리고 "pip install django"가 설치된 경로는 '/usr/local/lib/python3.8/site-packages'인데, 이걸 그냥 추가해 주면 될까요? ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # wsgi.py import sys sys.path.append('/usr/local/lib/python3.8/site-packages') print(sys.path) </pre> <br /> 그랬더니, 이번에는 다음과 같은 식의 오류가 발생합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Traceback (most recent call last): File "./myapp/wsgi.py", line 21, in <module> from django.core.wsgi import get_wsgi_application File "/usr/local/lib/python3.8/site-packages/django/core/wsgi.py", line 2, in <module> from django.core.handlers.wsgi import WSGIHandler File "/usr/local/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 5, in <module> from django.core.handlers import base File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 11, in <module> from django.urls import get_resolver, set_urlconf File "/usr/local/lib/python3.8/site-packages/django/urls/__init__.py", line 1, in <module> from .base import ( File "/usr/local/lib/python3.8/site-packages/django/urls/base.py", line 8, in <module> from .exceptions import NoReverseMatch, Resolver404 File "/usr/local/lib/python3.8/site-packages/django/urls/exceptions.py", line 1, in <module> from django.http import Http404 File "/usr/local/lib/python3.8/site-packages/django/http/__init__.py", line 5, in <module> from django.http.response import ( File "/usr/local/lib/python3.8/site-packages/django/http/response.py", line 16, in <module> from django.core.serializers.json import DjangoJSONEncoder File "/usr/local/lib/python3.8/site-packages/django/core/serializers/__init__.py", line 23, in <module> from django.core.serializers.base import SerializerDoesNotExist File "/usr/local/lib/python3.8/site-packages/django/core/serializers/base.py", line 8, in <module> from django.db import models File "/usr/local/lib/python3.8/site-packages/django/db/models/__init__.py", line 3, in <module> from django.db.models.aggregates import * # NOQA File "/usr/local/lib/python3.8/site-packages/django/db/models/aggregates.py", line 63 if (default := c.default) is None: ^ SyntaxError: invalid syntax </pre> <br /> 일단, django는 정상적으로 올라온 것 같은데, "/usr/local/lib/python3.8/site-packages/django/db/models/aggregates.py" 파일에 있는 "if (default := c.default) is None:" 문장에서 ":=" 기호가 python 3.8에만 추가되었기 때문에 오류가 발생했습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > 파이썬 3.8의 새로운 기능 ; <a target='tab' href='https://docs.python.org/ko/3/whatsnew/3.8.html'>https://docs.python.org/ko/3/whatsnew/3.8.html</a> </pre> <br /> 이름이 바다코끼리 연산자(the walrus operator)라는군요. ^^<br /> <br /> 자, 그렇다면 이 오류를 회피하기 위해 아마도 파이썬 3.8 구문을 사용하지 않는 Django 버전을 설치하면 될 텐데요, 따라서 pip install을 이렇게 주면 해결이 됩니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > # pip install django==3.2.6 </pre> <br /> 그런데, 이렇게 해도 불안 요소가 있습니다. 그건 다음 기회에! ^^;<br /> <br /> <hr style='width: 50%' /><br /> <br /> 참고로, 이런 식의 문제 때문에라도 그냥 <a target='tab' href='https://www.sysnet.pe.kr/2/0/12881'>"pip install uwsgi"로 설치하는 방식</a>이 더 낫습니다.<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
2492
(왼쪽의 숫자를 입력해야 합니다.)