반응형

Looks like you haven't properly installed the header files and static libraries for python dev.

Use your package manager to install them system-wide.

 

For apt (Ubuntu, Debian...):

sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

For yum (CentOS, RHEL...):

sudo yum install python-devel # for python2.x installs 
sudo yum install python3-devel # for python3.x installs

For dnf (Fedora...):

sudo dnf install python2-devel # for python2.x installs 
sudo dnf install python3-devel # for python3.x installs

For zypper (openSUSE...):

sudo zypper in python-devel # for python2.x installs 
sudo zypper in python3-devel # for python3.x installs

For apk (Alpine...):

# This is a departure from the normal Alpine naming 
# scheme, which uses py2- and py3- prefixes 

sudo apk add python2-dev # for python2.x installs 
sudo apk add python3-dev # for python3.x installs

For apt-cyg (Cygwin...):

apt-cyg install python-devel # for python2.x installs 
apt-cyg install python3-devel # for python3.x installs

 

반응형

반응형

Step1. 사전 준비

파이썬 설치를 위해서는 GCC 컴파일러가 필수입니다. 설치가 필요한 서버에 ssh or shell로 접속합니다.

그리고 이외 필수로 필요한 라이브러리를 설치합니다.

# yum install gcc openssl-devel bzip2-devel libffi-devel

Step2. 다운로드 Python 3.8

파이썬 공식사이트에 접속하여 Python 3.8 최신 버전을 확인 후 링크를 복사 후 아래의 커멘드를 사용하여 다운로드 합니다.

 

# cd /opt
# sudo wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

Step3. Python 3.8 설치

아래의 커멘드로 파이썬을 컴파일합니다.

cd Python-3.8.0
sudo ./configure --enable-optimizations
sudo make altinstall

Step4. Python 버전 확인

아래 처럼 파이썬을 버전을 확인합니다.

# python3.8 -V

Python 3.8.0
반응형

반응형
  • 이미 가지고 있는 테이블을 기반으로 장고 마이그레이션이 필요할 경우 아래의 명령어로 테이블 스키마 기준 models 데이터를 생성 할 수 있다.
python manage.py inspectdb > models.py

 

반응형

반응형

Windows에서 pip install mysqlclient 설치시 아래와 같은 에러 메시지가 반환된다면

fatal error C1083: 포함 파일을 열 수 없습니다. 'mysql.h': No such file or directory
fatal error C1083: Cannot open file: 'mysql.h': No such file or directory

 

아래의 URL에 접속 해서 비공식 바이너리를 받아서 pip로 설치하면 해결이 가능하다.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

 

접속해서 본인의 python 버전과 OS에 맞는 바이너리를 다운로드 후

Mysqlclient: a fork of the MySQL-python interface for the MySQL database.

mysqlclient‑1.4.6‑pp373‑pypy36_pp73‑win32.whl

mysqlclient‑1.4.6‑cp38‑cp38‑win_amd64.whl

mysqlclient‑1.4.6‑cp38‑cp38‑win32.whl...

 

whl파일로 수동설치

pip install C:\Users\xxx\Downloads\mysqlclient-1.4.6-cp37-cp37m-win32.whl

수동 설치 진행시 아래의 에러메시지가 반환 된다면,

OS 또는 pip 버전의 차이가 있을 수 있으니 pip를 최신버전으로 업데이트 하자.

mysqlclient-1.4.6-cp37-cp37m-win32.whl is not a supported wheel on this platform.

 

pip 최신 버전 업데이트

pip install --upgrade pip

 

pip 설치 시 아래와 같은 에러가 발생 한다면 호환성 이슈이므로 강제 재설치로 최신 버전으로 업데이트 하자

Exception:
Traceback (most recent call last):
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\cli\base_command.py", line 179, in main
    status = self.run(options, args)
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\commands\install.py", line 384, in run
    installed = install_given_reqs(
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\req\__init__.py", line 53, in install_given_reqs
    requirement.install(
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\req\req_install.py", line 910, in install
    self.move_wheel_files(
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\req\req_install.py", line 437, in move_wheel_files
    move_wheel_files(
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_internal\wheel.py", line 544, in move_wheel_files
    generated.extend(maker.make(spec))
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\distlib\scripts.py", line 405, in make
    self._make_script(entry, filenames, options=options)
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\distlib\scripts.py", line 309, in _make_script
    self._write_script(scriptnames, shebang, script, filenames, ext)
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\distlib\scripts.py", line 245, in _write_script
    launcher = self._get_launcher('t')
  File "c:\workon\mysite3.8\lib\site-packages\pip-19.0.3-py3.8.egg\pip\_vendor\distlib\scripts.py", line 384, in _get_launcher
    result = finder(distlib_package).find(name).bytes
AttributeError: 'NoneType' object has no attribute 'bytes'

 

pip 강제 최신 업데이트

easy_install -U pip
반응형

반응형

오랜만에 AWS EC2에 Python을 설치하는데 아래와 같은 에러가 발생한다.

 

$ pyenv install 3.6.9
Downloading Python-3.6.9.tar.xz...
-> https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tar.xz
Installing Python-3.6.9...

BUILD FAILED (Amazon Linux AMI 2018.03 using python-build 1.2.13-4-g6563b64d)

Inspect or clean up the working tree at /tmp/python-build.20190901070310.7044
Results logged to /tmp/python-build.20190901070310.7044.log

Last 10 log lines:
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/python-build.20190901070310.7044/Python-3.6.9':
configure: error: no acceptable C compiler found in $PATH

 

아래와 같이 gcc 설치로 해결하자. 

$sudo yum install gcc

반응형

반응형

다운로드 받을 파일 타입(Mimetype) 구분 방법

import mimetypes

mimetypes.guess_type('test.png')  # return ('image/png', None)

 

 

    import mimetypes
    import urllib
    
    
    file_name = urllib.parse.quote(file_info.file_name.encode('utf-8'))

    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type=mimetypes.guess_type(file_path)[0])
            response['Content-Disposition'] = 'attachment;filename*=UTF-8\'\'%s' % file_name
            return response

 

반응형

+ Recent posts