mac에서 pip를 통해서 install 시 compile error 가 발생하는 경우가 있습니다.

저의 경우 mysqlclient 설치시 오류가 발생했는데요.

$pip install -U mysqlclient Collecting mysqlclient Using cached mysqlclient-1.3.9.tar.gz Installing collected packages: mysqlclient Found existing installation: mysqlclient 1.3.7 Uninstalling mysqlclient-1.3.7: Successfully uninstalled mysqlclient-1.3.7 Running setup.py install for mysqlclient ... error Complete output from command /Volumes/Macintosh HD/virtualenv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/z5/g5z8xyp94191_q7dyz_j_z440000gn/T/pip-build-yHUcbd/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 /var/folders/z5/g5z8xyp94191_q7dyz_j_z440000gn/T/pip-tPZKUE-record/install-record.txt --single-version-externally-managed --compile --install-headers /Volumes/Macintosh HD/virtualenv/include/site/python2.7/mysqlclient:

running install running build running build_py creating build creating build/lib.macosx-10.12-intel-2.7 copying _mysql_exceptions.py -> build/lib.macosx-10.12-intel-2.7 creating build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/compat.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/converters.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/connections.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/cursors.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/release.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb copying MySQLdb/times.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb creating build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.12-intel-2.7/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.macosx-10.12-intel-2.7 cc -fno-strict-aliasing -fno-common -dynamic -arch i386 -arch x86_64 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,3,9,'final',1) -D__version__=1.3.9 -I/usr/local/Cellar/mariadb/10.1.18/include/mysql -I/usr/local/Cellar/mariadb/10.1.18/include/mysql/.. -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.12-intel-2.7/_mysql.o In file included from _mysql.c:40: In file included from /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/Python.h:8: /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:1062:9: warning: 'SIZEOF_TIME_T' macro redefined [-Wmacro-redefined] #define SIZEOF_TIME_T 4 ^ /usr/local/Cellar/mariadb/10.1.18/include/mysql/my_config.h:660:9: note: previous definition is here #define SIZEOF_TIME_T 8 ^ 1 warning generated. _mysql.c:260:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32] cmd_argc = PySequence_Size(cmd_args); ~ ^~~~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:290:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32] groupc = PySequence_Size(groups); ~ ^~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:441:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32] int j, n2=PySequence_Size(fun); ~~ ^~~~~~~~~~~~~~~~~~~~ _mysql.c:1070:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = mysql_real_escape_string(&(self->connection), out, in, size); ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:1073:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = mysql_escape_string(out, in, size); ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:1116:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32] size = PyBytes_GET_SIZE(s); ~ ^~~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/bytesobject.h:8:26: note: expanded from macro 'PyBytes_GET_SIZE' #define PyBytes_GET_SIZE PyString_GET_SIZE ^ /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE' #define PyString_GET_SIZE(op) Py_SIZE(op) ^~~~~~~~~~~ /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE' #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size) ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ _mysql.c:1128:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = mysql_real_escape_string(&(self->connection), out+1, in, size); ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:1131:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = mysql_escape_string(out+1, in, size); ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _mysql.c:1221:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32] if ((n = PyObject_Length(o)) == -1) goto error; ~ ^~~~~~~~~~~~~~~~~~ /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length' #define PyObject_Length PyObject_Size ^ _mysql.c:1433:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = strlen(buf); ~ ^~~~~~~~~~~ _mysql.c:1435:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = strlen(buf); ~ ^~~~~~~~~~~ _mysql.c:1471:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = strlen(buf); ~ ^~~~~~~~~~~ _mysql.c:1473:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32] len = strlen(buf); ~ ^~~~~~~~~~~ 13 warnings generated. cc -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -Wl,-F. build/temp.macosx-10.12-intel-2.7/_mysql.o -L/usr/local/Cellar/mariadb/10.1.18/lib -lmysqlclient -lz -lssl -lcrypto -o build/lib.macosx-10.12-intel-2.7/_mysql.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- Rolling back uninstall of mysqlclient Command "/Volumes/Macintosh HD/virtualenv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/z5/g5z8xyp94191_q7dyz_j_z440000gn/T/pip-build-yHUcbd/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 /var/folders/z5/g5z8xyp94191_q7dyz_j_z440000gn/T/pip-tPZKUE-record/install-record.txt --single-version-externally-managed --compile --install-headers /Volumes/Macintosh HD/virtualenv/include/site/python2.7/mysqlclient" failed with error code 1 in /private/var/folders/z5/g5z8xyp94191_q7dyz_j_z440000gn/T/pip-build-yHUcbd/mysqlclient/


오류의 원인은 compile에 필요한 xcode-select 가 설치되어 있지 않아서입니다.

아래와 같이 xcode-select를 설치해 주면 문제없이 pip로 설치 가능해집니다.

$ xcode-select --install

$ pip install -U phonenumbers
/home/deploy/sites/event.kidsnote.com/virtualenv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/home/deploy/sites/event.kidsnote.com/virtualenv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
Collecting phonenumbers
  Downloading phonenumbers-7.7.3-py2.py3-none-any.whl (2.7MB)
    100% |████████████████████████████████| 2.7MB 280kB/s 
Installing collected packages: phonenumbers
  Found existing installation: phonenumbers 7.2.4
    Uninstalling phonenumbers-7.2.4:
      Successfully uninstalled phonenumbers-7.2.4
Successfully installed phonenumbers-7.7.3

Posted by xelloss. :

Mac에서는 Homebrew라는 툴을 이용해서 MySQL, MariaDB, Redis, RabbitMQ 등을 간단히 설치하고 사용할 수 있습니다.

이 프로그램들을 백그라운드로 실행하는데 옳바른 방법은 brew services 라는 명령어를 통해서 제어하는 방법입니다.



현재 설치된 프로그램 중 데몬으로 사용 가능한 리스트는 아래의 명령어를 통해서 확인 가능합니다.


$brew services list
Name     Status  User          Plist
mariadb  started joonghyeonkim /Users/joonghyeonkim/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
rabbitmq started joonghyeonkim /Users/joonghyeonkim/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
redis    stopped 


제 Mac에는 MariaDB, RabbitMQ는 백그라운드로 실행 중이고, Redis는 정지된 상태이네요.


이제 Redis를 백그라운드로 실행해보겠습니다.

이때 사용하는 명령어는 brew services start redis 입니다.

$ brew services start redis
==> Successfully started `redis` (label: homebrew.mxcl.redis)

$ brew services list
Name     Status  User          Plist
mariadb  started joonghyeonkim /Users/joonghyeonkim/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
rabbitmq started joonghyeonkim /Users/joonghyeonkim/Library/LaunchAgents/homebrew.mxcl.rabbitmq.plist
redis    started joonghyeonkim /Users/joonghyeonkim/Library/LaunchAgents/homebrew.mxcl.redis.plist


Redis가 백그라운드에서 잘 동작하고 있음을 확인할 수 있습니다.


실제 사용할 수 있는 명령어는 아래와 같습니다.

    • brew services list : 서비스 목록을 출력합니다.
    • brew services start 서비스명 : 서비스를 백그라운드 실행해줍니다.
    • brew services stop 서비스명 : 서비스를 종료합니다.
    • brew services restart 서비스명 : 서비스를 재시작합니다.
    • brew services restart --all : 모든 서비스를 재시작합니다.

* 출처 : https://github.com/Homebrew/homebrew-services 


리스트 결과를 보면 Plist라는 항목이 있는데요 백그라운드로 실행할때 Mac의 환경에 맞도록 plist 파일입니다.

원본은 각 프로그램의 디렉토리에 있으며 /User/유저명/Libray/LaunchAgents/ 안에 파일을 자동으로 생성해줍니다.


이 파일들의 생성과 서비스 등록 등은 brew에서 자동으로 처리해줍니다.

굳이 plist 파일을 만들 필요도 없고 launchctl 명령어로 등록할 필요도 없습니다.


참고로 brew services로 데몬의 실행은 사실 데몬방식이 아닙니다.

그래서 Redis의 설정 중 daemonize를 yes할 경우 서비스가 실행되지 않으니 이점 주의해 주세요.


 

Posted by xelloss. :

About me

2016. 10. 24. 18:31 from 카테고리 없음

현재 키즈노트의 백엔드셀에서 서버와 프론트엔드, 백엔드 및 잡다한 것들을 하고 있습니다. :D

Posted by xelloss. :