annyoung

python 버전 관리를 위한 pyenv 본문

프로그래밍

python 버전 관리를 위한 pyenv

nopsled 2023. 8. 4. 12:48

개요

개발하고 있는 서버 A,B가 있는데 A서버는 python@3.7.6에서는 돌아가지만 python@3.11.4에서는 돌아가지 않는다.하지만, B서버는 python@3.11.4에서 돌아가고 python@3.7.6에서는 돌아가지 않는 상황..

따라서 필자는 파이썬 버전 관리가 필요하다고 생각했다.

 

 

설치

pyenv 설치

brew install pyenv

 

 

.bash_profile.zshrcpyenv 활성화 하는 스크립트 추가

echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bash_profile

 

 

.bash_profile.zshrc 변경사항 적용

exec "$SHELL"

 

 

pyenv를 이용해 python 설치

pyenv install 3.7.6
pyenv install 3.11.4

 

 

그런데 pyenv로 python@3.7.6 설치하다가 에러가 발생했다.

nopsled@playground  ~  pyenv install 3.7.6

python-build: use openssl@1.1 from homebrew
python-build: use readline from homebrew
Downloading Python-3.7.6.tar.xz...
-> https://www.python.org/ftp/python/3.7.6/Python-3.7.6.tar.xz
Installing Python-3.7.6...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk

BUILD FAILED (OS X 13.4 using python-build 20180424)

Inspect or clean up the working tree at /var/folders/dl/r_8xbf8s37z1qztd3nml4tvh0000gn/T/python-build.20230804122132.4931
Results logged to /var/folders/dl/r_8xbf8s37z1qztd3nml4tvh0000gn/T/python-build.20230804122132.4931.log

Last 10 log lines:
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration   -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include  -DPy_BUILD_CORE_BUILTIN  -c ./Modules/pwdmodule.c -o Modules/pwdmodule.o
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration   -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include  -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_sre.c -o Modules/_sre.o
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include  -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration   -I. -I./Include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include -I/usr/local/opt/readline/include -I/usr/local/opt/readline/include -I/Users/nopsled/.pyenv/versions/3.7.6/include  -DPy_BUILD_CORE_BUILTIN  -c ./Modules/_codecsmodule.c -o Modules/_codecsmodule.o
./Modules/posixmodule.c:8436:15: error: implicit declaration of function 'sendfile' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = sendfile(in, out, offset, &sbytes, &sf, flags);
              ^
1 error generated.
make: *** [Modules/posixmodule.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.

 

문법 검사를 하다가 sendfile이 묵시적 선언 되어 컴파일할 때 에러가 난다는 내용인것 같다.

 

관련 내용 리서치하다 보니 다음 커맨드를 입력해서 설치하니까 에러없이 잘 설치 되었다.

CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.7.6 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)

 

 

출처

1) https://www.daleseo.com/python-pyenv/

 

여러 버전의 파이썬 관리하기 (pyenv)

Engineering Blog by Dale Seo

www.daleseo.com

2) https://github.com/pyenv/pyenv/issues/1737#issuecomment-827865222

 

Python 3.6-3.8 cannot be installed on Mac OS 11.0.1: "implicit declaration of function 'sendfile' is invalid in C99" · Issue #1

Hi,Morning: First of all, thank you very much for thinking about and maintaining pyenv. We found problems installing pypypy3 via pyenv, but we were also able to find solutions we would like to shar...

github.com

 

Comments