안녕하세요? 영어쌤 죠니입니다.
이번엔 파이썬 가상환경(pipenv) 내에서 프로젝트 실행 시 발생했던 문제 해결에 대해 포스팅합니다.
이번에도 조언을 주하고 도움을 받은 나는 쓰레기...
우선 오류 메세지는 다음과같이 다왔어요.
(1) 서버 실행시 오류 발생 발견
$ python3 ./leadmanager/manage.py runserver
위와 같이 서버를 실행하려는데 다음과 같은 오류가 발생했습니다.
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
우선 가장 마지막 줄에 보이는 did you install mysqlclient?라는 문구를 보고 나서 이를 해결하기 위해 설치를 시도하였습니다.
(2) mysqlclient 설치 시도
다음의 명령어로 설치를 합니다. 그러면 또다른 오류 메세지가 발생되었더랬죠...
우선 가상환경이므로 pip나 pip3 대신 pipenv로 설치를 합니다.
$ pipenv install mysqlclient
다음과 같은 오류가 발생합니다.
Installing mysqlclient…
✔ Installation Succeeded
Installing dependencies from Pipfile.lock (db5f03)…
An error occurred while installing mysqlclient==1.4.2.post1 --hash=sha256:425e733b05e359a714d6007c0fc44582be66b63e5a3df0a50949274ae16f4bc6 --hash=sha256:62e4770b6a797b9416bcf70488365b7d6b9c9066878108499c559293bb464380 --hash=sha256:f257d250f2675d0ef99bd318906f3cfc05cef4a2f385ea695ff32a3f04b9f9a7! Will try again.
🐍 ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 12/12 — 00:00:02
Installing initially failed dependencies…
[pipenv.exceptions.InstallError]: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1992, in do_install
[pipenv.exceptions.InstallError]: skip_lock=skip_lock,
[pipenv.exceptions.InstallError]: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 1253, in do_init
[pipenv.exceptions.InstallError]: pypi_mirror=pypi_mirror,
[pipenv.exceptions.InstallError]: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 859, in do_install_dependencies
[pipenv.exceptions.InstallError]: retry_list, procs, failed_deps_queue, requirements_dir, **install_kwargs
[pipenv.exceptions.InstallError]: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 763, in batch_install
[pipenv.exceptions.InstallError]: _cleanup_procs(procs, not blocking, failed_deps_queue, retry=retry)
[pipenv.exceptions.InstallError]: File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pipenv/core.py", line 681, in _cleanup_procs
[pipenv.exceptions.InstallError]: raise exceptions.InstallError(c.dep.name, extra=err_lines)
[pipenv.exceptions.InstallError]: ['Collecting mysqlclient==1.4.2.post1 (from -r /var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pipenv-5olm0xu8-requirements/pipenv-uoiigeu_-requirement.txt (line 1))', ' Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz', 'Building wheels for collected packages: mysqlclient', ' Building wheel for mysqlclient (setup.py): started', " Building wheel for mysqlclient (setup.py): finished with status 'error'", ' Running setup.py clean for mysqlclient', 'Failed to build mysqlclient', 'Installing collected packages: mysqlclient', ' Running setup.py install for mysqlclient: started', " Running setup.py install for mysqlclient: finished with status 'error'"]
[pipenv.exceptions.InstallError]: ['ERROR: Complete output from command /Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/bin/python3 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-install-vwc1zzo0/mysqlclient/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' bdist_wheel -d /private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-wheel-h_urxn7m --python-tag cp37:', ' ERROR: running bdist_wheel', ' running build', ' running build_py', ' creating build', ' creating build/lib.macosx-10.9-x86_64-3.7', ' creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' warning: build_py: byte-compiling is disabled, skipping.', ' ', ' running build_ext', " building 'MySQLdb._mysql' extension", ' creating build/temp.macosx-10.9-x86_64-3.7', ' creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb', " gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 -I/usr/local/Cellar/mysql/8.0.16/include/mysql -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o", ' gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql/8.0.16/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so', ' ld: library not found for -lssl', ' clang: error: linker command failed with exit code 1 (use -v to see invocation)', " error: command 'gcc' failed with exit status 1", ' ----------------------------------------', ' ERROR: Failed building wheel for mysqlclient', ' ERROR: Complete output from command /Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/bin/python3 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-install-vwc1zzo0/mysqlclient/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-record-7aku2w45/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/bin/../include/site/python3.7/mysqlclient:', ' ERROR: running install', ' running build', ' running build_py', ' creating build', ' creating build/lib.macosx-10.9-x86_64-3.7', ' creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb', ' creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants', ' warning: build_py: byte-compiling is disabled, skipping.', ' ', ' running build_ext', " building 'MySQLdb._mysql' extension", ' creating build/temp.macosx-10.9-x86_64-3.7', ' creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb', " gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 -I/usr/local/Cellar/mysql/8.0.16/include/mysql -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o", ' gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql/8.0.16/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so', ' ld: library not found for -lssl', ' clang: error: linker command failed with exit code 1 (use -v to see invocation)', " error: command 'gcc' failed with exit status 1", ' ----------------------------------------', 'ERROR: Command "/Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/bin/python3 -u -c \'import setuptools, tokenize;__file__=\'"\'"\'/private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-install-vwc1zzo0/mysqlclient/setup.py\'"\'"\';f=getattr(tokenize, \'"\'"\'open\'"\'"\', open)(__file__);code=f.read().replace(\'"\'"\'\\r\\n\'"\'"\', \'"\'"\'\\n\'"\'"\');f.close();exec(compile(code, __file__, \'"\'"\'exec\'"\'"\'))\' install --record /private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-record-7aku2w45/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hyun/.local/share/virtualenvs/lead_manager_react_django-1JT1euE8/bin/../include/site/python3.7/mysqlclient" failed with error code 1 in /private/var/folders/dz/bf7jm6853ms0zjc_l0r9_j3r0000gr/T/pip-install-vwc1zzo0/mysqlclient/']
ERROR: ERROR: Package installation failed...
☤ ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/1 — 00:00:02
굉장히 길고 긴 오류메세지가 출력되더군요...
이해하기 힘들었습니다...만 도움을 받았어요.
쨌든 위의 오류 메세지중 주목해야 할 것은 다음의 링커 관련 메세지 였습니다.
lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so'
이제 구글링을 해야겠죠?
마스터 포테이토께선 다음과 같이 바로 찾으셨습니다.
검색어 : brew openssl lssl not found
stackoverflow에서 찾은 해결책입니다. 링크는 아래 첨부합니다.
https://github.com/brianmario/mysql2/issues/795
자 이제 오류를 해결합니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
298 mysql --version
299 pipenv install mysqlclient
300 uname
301 brew search ssl
302 brew install openssl@1.1
303 /usr/local/opt/openssl@1.1/bin/c_rehash
304 export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
305 export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
306 pipenv install mysqlclient
307 pipenv --help
308 pipenv uninstall mysqlclient
309 pipenv install mysqlclient
310 history
(lead_manager_react_django) bash-3.2$
|
cs |
위와 같이 순서대로 해 보십시오!
결론적으론 위와 같이 304번줄과 305번줄에서 볼 수 있듯이 경로 등을 수정해 주고 바로잡으면 된다고 합니다.
그리고!!!! 다시 mysqlclient를 설치해 줍니다.
$ python3 ./leadmanager/manage.py runserver
이런... 성공한 화면을 꺼버렸네요... 아무튼 해 보시면 성공할 것 입니다.
화이팅!!!