[Python] 설치된 패키지 목록 requirements.txt 만들기 가상환경(venv)이나 현재 python에 pip으로 설치된 패키지 목록에 대한 정보를 requirements.txt 로 만들기 위해서는 freeze 명령어를 사용하면 된다. $ pip freeze > requirements.txt requirements.txt의 패키지들을 모두 설치하기 위해서는 아래 명령어를 이용하면 된다. $ pip install -r requirements.txt [참고] https://docs.python.org/ko/3/tutorial/venv.html
Python
[Python][ERROR] SSL: CERTIFICATE_VERIFY_FAILED 에러 urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581) 임시 context를 만들어 ssl 인증을 우회할 수 있다. import ssl ssl._create_default_https_context = ssl._create_unverified_context [참고] https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error
[Python][MySQL] Warning: Incorrect string value 에러 해결 방법 project.py:83: Warning: Incorrect string value: '\xED\x94\x84\xEB\xA1\x9C...' for column 'name' at row 11584 cur.execute(query) Python 에서 MySQL에 데이터를 Insert 하는데, 한글을 입력하려는 경우 위와 같은 경고가 뜨며, Insert 된 값은 ??? 로 된다면, Insert 하려는 테이블의 CHARSET 값을 확인 한 후 UTF8이 아니면 UTF8로 변경해 주면된다. ALTER TABLE 테이블명 CONVERT TO CHARACTER SET utf8;
[Python] 이중배열(matrix) 정보를 csv로 저장하는 방법 pandas 모듈의 to_csv 함수를 이용하면 가능하다. 1) pandas 없을 경우 설치 $ pip install pandas 예) import pandas as pd fileName = "file.csv" pd.DataFrame(csvData).to_csv(fileName, header=False, index=False) 위 예제에서 사용된 파라메터(옵션) -header : 0, 1, .... 헤더(열) 번호 생성 ( default : True ) -index : 0, 1, .... 행 번호 생성 ( default : True ) 사용 가능한 파라메터(옵션) : https://pandas.pydata.org/pandas-docs/..
[Python][pip] ImportError: No module named _socket 해결 방법 virtualenv 에서 pip 으로 모듈 설치시 ImportError 오류가 발생할 경우 --> Python 설치 경로의 DLLs 폴더 (ex. C:/Python27/DLLs) 폴더를 virtualenv 폴더에 복사해서 붙여넣으면 된다.
[Django] 테이블에 값이 없을 때만 추가하는 방법 아래와 같이 1) get() 으로 해당 데이터가 있는지 검사 (Select)2) 없으면 save()로 데이터 삽입 (Insert)try-catch 방식을 사용하여 작성이 가능하다. try: obj = Person.objects.get(first_name='John', last_name='Lennon') except Person.DoesNotExist: obj = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)) obj.save() Django 문서에 get_or_create() 를 지원하며, 해당 메소드를 이용하면 위에 try-catch를 사용한 방식보다 쉽게 구현이 ..