본문 바로가기
Python

amazon linux 2 - 파이썬 3.11 설치

by 앗사비 2023. 7. 10.
728x90

sqlite와 ssl 사용시 문제 나올 수 있으니 주의 (아직 해결책 못찾음)


ModuleNotFoundError: No module named '_sqlite3'
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)

 

---

 

필요한 도구들 사전 설치

파이썬 3.10 부터는 openssl1.1.1 이상이 필요 (링크)

sudo yum update -y
sudo yum groupinstall "Development Tools" -y
sudo yum erase openssl-devel -y
sudo yum install openssl11 openssl11-devel libffi-devel bzip2-devel wget -y


파이썬 소스코드 다운로드 후 압축 해제

wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz
tar -xf Python-3.11.4.tgz
cd Python-3.11.4


옵션 설정 후 설치

기본 인터프리터에 영향주지 않기 위해 altinstall 사용

./configure --enable-optimizations
sudo make altinstall


설치 완료 확인 및 pip 업그레이드

python3.11 --version
python3.11 -m pip install --upgrade pip

 

파이썬 선택 위해 등록

which python3.11 
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.11 1


기본 파이썬 선택

sudo update-alternatives --config python

 

sudo vi ~/.zshrc  실행 후 아래 내용 추가 (또는 bashrc)
alias pip="pip3.11"

 

source ~/.zshrc 로 적용 

 

다운받았던 압축 및 압축해제 폴더은 필요없으니 삭제하자

 

----

 

참고 : https://taejoone.jeju.onl/posts/2023-03-11-setup-aws-linux2-part2

 

----

 

pip로 모듈 설치시 PATH 문제 발생하면 export PATH 에 $HOME/.local/bin 추가

https://mong9data.tistory.com/114

 

----

 

Max retries exceeded with url: ... (Caused by SSLError(SSLError(1, '[SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1002)')))

 

requests 사용시 이런 오류가 발생하면 보안 수준 변경 필요하므로 아래 코드 추가

requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:@SECLEVEL=1'

https://ivorycirrus.github.io/TIL/openssl-seclevel/

https://github.com/kubernetes-client/python/issues/1824

 

ssl 사용 중 발생하면

ctx = ssl.create_default_context()
ctx.set_ciphers("DEFAULT@SECLEVEL=1") #해당 라인 추가

 

---

 

https://dev.to/hkamran/installing-a-newer-version-of-python-on-amazon-ec2-1b4n

 

---

 

기타 오류 발생시 참고

https://sangchul.kr/entry/aws-amazon-Linux-2%EC%97%90-python-39%EB%A5%BC-%EC%84%A4%EC%B9%98%ED%95%98%EB%8A%94-%EB%B0%A9%EB%B2%95

https://junho85.pe.kr/2157

https://hello-bryan.tistory.com/487

https://hkamran.com/article/installing-newer-python-amazon-ec2

https://www.gcptutorials.com/post/python-3.10-installation-on-amazon-linux-2

https://help.dreamhost.com/hc/en-us/articles/360001435926-Installing-OpenSSL-locally-under-your-username

https://taejoone.jeju.onl/posts/2023-03-11-setup-aws-linux2-part2

728x90

'Python' 카테고리의 다른 글

yield 한 방에 이해하기  (0) 2023.08.04
edge-tts 사용해보기  (0) 2023.07.21
tkinter - 입력란 내용 없으면 버튼 비활성화  (0) 2023.05.11
판다스 치트시트  (0) 2023.04.27
비동기로 웹크롤링  (0) 2023.04.01