반응형

1. Miniconda 란?

  • Python을 사용하는 방법은 매우 다양하다. local system에 python을 설치한 후 그냥 실행을 한다거나, venv를 실행한다거나, anaconda를 사용하거나.
  • 이 중에서 Miniconda라는 프로그램을 사용하는 방법도 존재한다.
  • 하여 Miniconda란, anaconda 를 최소화한 프로그램으로써 작업하고자하는 프로젝트별로 python의 버전을 설정할 수 있으며, 모듈 또한 각 프로젝트 환경에 종속되어 설치할 수 있다.
  • 이러한 기능으로 프로젝트별 모듈 관리하기가 편하며, 간단한 명령어를 이용하여 project switching 하기도 용이하다.

2. Miniconda 설치법

2.1) 설치 스크립트 다운로드

  • 다운로드 사이트에서 설치하고자 하는 환경을 다운로드받으면 된다. Windows, MacOS, Linux 모두 지원하고 있다.
  • Mac OS M1
      wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
  • MacOS Intel
      wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
  • Linux
      wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh

2.2) 설치 스크립트에 실행권한 주기

chmod +x Miniconda3-latest-Linux-x86_64.sh

2.3) 설치 스크립트 실행하기

  • 스크립트 실행

      ./Miniconda3-latest-Linux-x86_64.sh
  • 설치 시작

      $ ./Miniconda3-latest-Linux-x86_64.sh
    
      Welcome to Miniconda3 py311_23.5.2-0
    
      In order to continue the installation process, please review the license
      agreement.
      Please, press ENTER to continue
      >>> [엔터 입력하기]
  • Licence 동의

      In order to continue the installation process, please review the license
      agreement.
      Please, press ENTER to continue
      >>>
      ======================================
      End User License Agreement - Miniconda
      ======================================
    
      Copyright 2015-2023, Anaconda, Inc.
    
      All rights reserved under the 3-clause BSD License:
    
      This End User License Agreement (the "Agreement") is a legal agreement between you and
      Anaconda, Inc. ("Anaconda") and governs your use of Miniconda.
    
      ... 중략 ...
    
      Last updated March 21, 2022
    
      Do you accept the license terms? [yes|no]
      [no] >>>  yes 
  • Miniconda 설치경로 지정하기

      Miniconda3 will now be installed into this location:
      /Users/user/miniconda3
    
      - Press ENTER to confirm the location
      - Press CTRL-C to abort the installation
      - Or specify a different location below
    
      [/Users/user/miniconda3] >>>
  • Miniconda 초기화 하기

      Do you wish the installer to initialize Miniconda3
      by running conda init? [yes|no]
      [no] >>> yes
      no change     /Users/user/miniconda3/condabin/conda
      no change     /Users/user/miniconda3/bin/conda
      no change     /Users/user/miniconda3/bin/conda-env
      no change     /Users/user/miniconda3/bin/activate
      no change     /Users/user/miniconda3/bin/deactivate
      no change     /Users/user/miniconda3/etc/profile.d/conda.sh
      no change     /Users/user/miniconda3/etc/fish/conf.d/conda.fish
      no change     /Users/user/miniconda3/shell/condabin/Conda.psm1
      no change     /Users/user/miniconda3/shell/condabin/conda-hook.ps1
      no change     /Users/user/miniconda3/lib/python3.11/site-packages/xontrib/conda.xsh
      no change     /Users/user/miniconda3/etc/profile.d/conda.csh
      modified      /Users/user/.bashrc
    
      ==> For changes to take effect, close and re-open your current shell. <==
    
      If you'd prefer that conda's base environment not be activated on startup,
      set the auto_activate_base parameter to false:
    
      conda config --set auto_activate_base false
    
      Thank you for installing Miniconda3!
  • .bashrc 최신화 하기 (이 작업을 해야 conda 명령어를 사용할 수 있다.)

      $ source ~/.bashrc
      (base) $ conda
      usage: conda [-h] [-V] command ...
    
      conda is a tool for managing and deploying applications, environments and packages.

3. Conda 명령어 사용해보기.

3.1) 신규 프로젝트 생성

  • 기본 명령기

      (base) ➜  ~ conda create -n {프로젝트 이름} python={파이썬 버전}
  • 생성해보기

      (base) ➜  ~ conda create -n conda-test python=3.11
      Retrieving notices: ...working... done
      Collecting package metadata (current_repodata.json): done
      Solving environment: done
    
      ==> WARNING: A newer version of conda exists. <==
      current version: 23.1.0
      latest version: 23.7.4
    
      Please update conda by running
    
          $ conda update -n base -c defaults conda
    
      Or to minimize the number of packages updated during conda update use
    
          conda install conda=23.7.4
    
      ## Package Plan ##
    
      environment location: /Users/user/miniconda3/envs/conda-test
    
      added / updated specs:
          - python=3.11
    
      The following packages will be downloaded:
    
          package                    |            build
          ---------------------------|-----------------
          python-3.11.5              |       hb885b13_0        15.4 MB
          ------------------------------------------------------------
                                              Total:        15.4 MB
    
      The following NEW packages will be INSTALLED:
    
      bzip2              pkgs/main/osx-arm64::bzip2-1.0.8-h620ffc9_4
      ca-certificates    pkgs/main/osx-arm64::ca-certificates-2023.08.22-hca03da5_0
      libffi             pkgs/main/osx-arm64::libffi-3.4.4-hca03da5_0
      ncurses            pkgs/main/osx-arm64::ncurses-6.4-h313beb8_0
      openssl            pkgs/main/osx-arm64::openssl-3.0.10-h1a28f6b_2
      pip                pkgs/main/osx-arm64::pip-23.2.1-py311hca03da5_0
      python             pkgs/main/osx-arm64::python-3.11.5-hb885b13_0
      readline           pkgs/main/osx-arm64::readline-8.2-h1a28f6b_0
      setuptools         pkgs/main/osx-arm64::setuptools-68.0.0-py311hca03da5_0
      sqlite             pkgs/main/osx-arm64::sqlite-3.41.2-h80987f9_0
      tk                 pkgs/main/osx-arm64::tk-8.6.12-hb8d0fd4_0
      tzdata             pkgs/main/noarch::tzdata-2023c-h04d1e81_0
      wheel              pkgs/main/osx-arm64::wheel-0.38.4-py311hca03da5_0
      xz                 pkgs/main/osx-arm64::xz-5.4.2-h80987f9_0
      zlib               pkgs/main/osx-arm64::zlib-1.2.13-h5a0b063_0
    
      Proceed ([y]/n)? y
    
      Downloading and Extracting Packages
    
      Preparing transaction: done
      Verifying transaction: done
      Executing transaction: done
      #
      # To activate this environment, use
      #
      #     $ conda activate conda-test
      #
      # To deactivate an active environment, use
      #
      #     $ conda deactivate

    3.2) 생성된 프로젝트 보기

  • 기본 명령어

      (base) ➜  ~ conda env list
  • 실행 결과

    3.3) 프로젝트 활성화(전환)

  • 기본 명령어

      (base) ➜  ~ conda activate conda-test
  • 실행 결과 (명령 프롬프트를 보면 base에서 conda-test로 변경된것을 확인할 수 있음)

      (conda-test) ➜  ~ python --version
      Python 3.11.5

3.4) 프로젝트 비활성화

  • 기본 명령어 및 실행 결과
      (conda-test) ➜  ~ conda deactivate
      (base) ➜  ~ python --version
      Python 3.10.

3.5) 프로젝트 삭제

  • 프로젝트명으로 삭제하기 (option: -n)

      (base) ➜  ~ conda-env remove -n conda-test
    
      Remove all packages in environment /Users/user/miniconda3/envs/conda-test:
  • 프로젝트 경로로 삭제하기 (option: -p)

      (base) ➜  ~ conda env list # 삭제할 프로젝트가 저장된 path 찾기
      # conda environments:
      #
      conda-test               /Users/user/miniconda3/envs/conda-test
      (base) ➜  ~ conda-env remove -p /Users/user/miniconda3/envs/conda-test # path 삭제하기
    
      Remove all packages in environment /Users/user/miniconda3/envs/conda-test:
반응형

1. Intro

github에서는 August 13, 2021부로 패스워드 인증 방식을 제거한다고 발표하였습니다. (공지 링크) 이후부터 원격지(ssh)에서 git push 및 기타 작업을 할 때 권한이 없다는 에러가 발생하고 있는데요. 개발자에게는 아주 중요한 부분이라, 이러한 에러를 어떻게 해결할 수 있을지 step-by-step으로 정리를 해보았습니다.

에러 요약

  fatal: Authentication failed for  'https://github.com/___/_____.git/'

에러 전체

  blackcon.github.io git:(master) ✗ git push origin master
  Username for 'https://github.com': 
  Password for 'https://blackcon@github.com':
  remote: Support for password authentication was removed on August 13, 2021.
  remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
  fatal: Authentication failed for 'https://github.com/___/_____.git/'

2. Summary

위 에러를 해결하기 위한 세 줄 요약. 아래와 같습니다. 3줄 요약만으로 무슨 말인지 모르느 좀 더 상세한 설명을 이어서 다루어 볼게요.

  1. Personal Access Token 발급
  2. git clone 시 Personal Access Token을 사용하여 clone하기
  3. 또는 git push 할 때 password가 아닌 Personal Access Tocken 사용하기

3. Detail

거두절미하고 아래의 방법으로 설정을 해주신다면 ssh상으로 git을 제어할 수 있으니 따라해보시길 바랍니다.

1) Personal Access Token 발급

  • github 페이지에서 Settings를 클릭
  • Settings 페이지에 왔다면 좌측 하단에서 Developer Settings 클릭
  • Personal Access Token 클릭
  • Generate New Token 버튼을 클릭하여 새로운 토큰 설정하는 페이지로 이동
  • 해당 토큰에 부여할 권한을 체크한 후, 페이지 하단에 있는 Generate Token 클릭

2) git clone 시 Personal Access Token을 사용하여 clone하기

  • Access key를 사용하여 clone하기
  • 이 후 작업들은 인증절차 없이 바로 진행시킬 수 있는 장점이 있음
  • 명령어
  • $ git clone https://blackcon:{Personal_Token}@github.com/blackcon/blackcon.github.io.git Cloning into 'blackcon.github.io'... remote: Enumerating objects: 2932, done. remote: Counting objects: 100% (17/17), done. remote: Compressing objects: 100% (16/16), done. remote: Total 2932 (delta 6), reused 1 (delta 1), pack-reused 2915 Receiving objects: 100% (2932/2932), 33.21 MiB | 18.67 MiB/s, done. Resolving deltas: 100% (931/931), done.

3) 또는 git push 할 때 password가 아닌 Personal Access Tocken 사용하기

  • 위 절차가 아닌 과거 하던대로 git clone을 해두었거나,
  • 매번 Personal token을 입력하면서 작업을 하고싶을 경우에는 아래 방법을 이용하면 됩니다.
  • 명령어
  • $ git clone https://github.com/user-or-organisation/myrepo.git Username: <my-username> Password: <my-personal-access-token> $ git push https://github.com/user-or-organisation/myrepo.git Username: <my-username> Password: <my-personal-access-token>

3. EOD (End of Document)

이상 개발중에 삽질을 하다가 발견한 이슈였습니다.. 동일한 증상이 있을 많은 개발자분들을 위해 포스팅을 하여보았고, 좀 더 새롭고 안전한 git life를 즐겨보도록 하겠습니다.

반응형

1. 주절주절

요즘 시대에는 Blog, Tistory, Wiki 등 방대한 정보가 쏟아져 나오고 있습니다. 하나의 정보글(또는 포스팅)은 짧게는 몇 줄, 길게는 몇 페이지 이상의 긴 글이 존재하고 있죠. 사용자 입장에서는 이렇게 긴 글을 접했을 때 현재까지 어느 정도 읽었고 앞으로 얼마나 남았는지 궁금할 때가 있더라구요. 그러한 상태표시줄(Progress Bar)을 이용하여 현재 상태를 확인할 수 있도록 Tistory blog를 수정해보도록 하겠습니다.

(오일남: 내가,,, 어디까지,,, 봤더라? )

 

2. 설정 방법

2-1. [스킨편집]: 블로그 관리자 페이지 > 꾸미기:스킨 편집

1) 하단에 있는 이미지와 같이 관리페이지에 있는 스킨편집을 클릭합니다.

스킨편집 메뉴 위치


2) 새로운 탭이 뜨고 해당 창에는 스킨편집을 할 수 있는 메뉴들이 구성되어 있습니다.

2-2. HTML 편집

1) 스킨편집 페이지를 열었다면 우측에 [html편집] 버튼을 볼 수 있는데요.
2) 해당 버튼을 클릭하여 html이라는 소스코드를 조금 추가하려 합니다.
3) 추가할 소스 코드

<div class="progress-container"> 
      <div class="progress-bar" id="indicator"></div> 
</div>

4) 앞서 알려드린 소스 코드를과사이 아무런 공간에 삽입해주시면 됩니다.

2-3. CSS 편집

1) html 을 수정하였다면 마지막으로 CSS 탭을 클릭하시고 css 코드를 조금 추가해주면 끝납니다.
2) 추가할 코드

/* Progress Bar */
.progress-container {
  position: fixed; /* 상단에 고정 */
  top: 0; /* 위치는 위에 딱 붙게 */
  width: 100%; /* 넓이는 100% */
  height: 4px; /* 높이는 4px */
  background: transparent; /* 배경색 투명하게 */
  z-index: 1000; /* 다른 요소들보다 위에 보이게 */
}
.progress-bar {
  height: 4px;
  width: 0%;
  background: #6acbe1; /* 표시될 배경색 */
}

3) 앞서 알려드린 소스 코드를 아래 이미지와 같이 추가하면 끝

3. 설정 후 블로그 글

  • 테스트 삼아서 기존 포스팅 글을 열람해보았습니다. (https://blackcon.tistory.com/368)
  • [주소표시줄] 아래에 보면 파란색 bar가 하나 생긴걸 확인하였구요.
  • 포스팅의 초반에는 짧았다가, 후분바에 가니 Progress bar가 증가한 것을 볼 수 있네요!

 

EOD ... 

End of document

반응형

1. 취지

요즘 숨고 의뢰를 받다보면 다양한 주제가 인입됩니다. 우선, 저는 개발/레슨 항목으로 등록해두었으며, 관련해서 계속 알림을 받고 있어요. 많은 의뢰중 하나가 python을 이용하여 Trend keyword를 알아보는 의뢰였는데요. 저도 의뢰를 해결하다가 아래와 같이 문득 궁금증이 들었습니다.

  • 인입되는 숨고의 요청서에 자주 사용되는 키워드가 뭔지?
  • 어떤 내용을 주로 요청하는지?

2. 숨고 API 분석

숨고에 로그인을 하고 견적요청서 메뉴를 클릭하면 요청서 정보를 받아오기 위하여 숨고API를 호출합니다. python을 이용하여 해당 API로 요청서 정보를 받아오도록 하겠습니다.

  • 크롬 개발자 도구롸 확인한 숨고API 주소
  • Python 코드
    headers = {
         'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
         'Authorization': ~Input your own auth key~
     }
     url = "https://api.soomgo.com/v1/me/requests/received"
     res = requests.get( url, headers=headers)
     res = res.json()

3.  요청서 분석

2번 단계에서 API를 통해 전달받은 contents를 word 단위로 파싱을 해줍니다. Okt() 모듈을 활용한다면 조사,접속사 등 다양하게 파싱을 해주지만, 저는 간단하게 1) 특수문자 제거, 2) 띄어쓰기로 단어 구분을 하였습니다.

  • Python 코드
output = ", ".join(content_list)
# 특수문자 제거
special_chr = ["‘", "’", "!",  ",", ".", "(", ")", "?", "&", "'", "\”", "\"", "~"]
etc = ["을", "를", "와", "으로", "하는"]
for char in special_chr+etc:
    output = output.replace( char, " " )
print( output )
temp = output.split( " " )
for i in temp:
    if i != "":
        results.append( i )

4.  최종 결과

  • 사용도 순으로 나열된 단어들
Count: 13, Keyword: 싶습니다
Count: 10, Keyword: 배우고
Count: 8, Keyword: 수
Count: 7, Keyword: 도
Count: 6, Keyword: 싶어요
Count: 5, Keyword: 파이썬
Count: 5, Keyword: 코딩
Count: 4, Keyword: 등
Count: 3, Keyword: 희망
Count: 3, Keyword: 제작
...
  • 이미지로 만들어본 Trend Keywords

  • 전체 소스코드
from bs4 import BeautifulSoup
from urllib.request import urlopen
import requests
from wordcloud import WordCloud
from konlpy.tag import Okt
from collections import Counter
import matplotlib.pyplot as plt

def get_soomgo_data():
    headers = {
        'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',
        'Authorization': ~Input your own auth key~
    }
    after_page = 0
    results = []
    #while True
    for kk in range(20):
        print(after_page)
        if after_page == -1:
            break
        elif after_page == 0:
            url = "https://api.soomgo.com/v1/me/requests/received"
        else:
            url = "https://api.soomgo.com/v1/me/requests/received?after={0}".format(after_page)

        res = requests.get( url, headers=headers)
        res = res.json()
        response = res["response"]
        after_page = response['pagination']['after']
        items = response['items']
        content_list = []
        for _item in items:
            _id = _item['request']['id']
            _content =  _item['request'][ 'requestContent']
            _content = _content.split(", ")[-1]
            content_list.append( _content )

        output = ", ".join(content_list)
        # 특수문자 제거
        special_chr = ["‘", "’", "!",  ",", ".", "(", ")", "?", "&", "'", "\”", "\"", "~"]
        etc = ["을", "를", "와", "으로", "하는"]
        for char in special_chr+etc:
            output = output.replace( char, " " )
        print( output )
        temp = output.split( " " )
        for i in temp:
            if i != "":
                results.append( i )

    return results

results = get_soomgo_data()

# 가장 많이 나온 단어부터 50개를 저장한다.
counts = Counter(results)
tags = counts.most_common(50)
for tag in tags:
    print( u"Count: {0}, Keyword: {1}".format(tag[1], tag[0]))

_path = r'/Users/user/Downloads/NanumGothicCoding-2.5/NanumGothicCoding.ttf'
wc = WordCloud(font_path=_path, background_color="white", max_font_size=60)
cloud = wc.generate_from_frequencies(dict(tags))

# 생성된 WordCloud를 test.jpg로 보낸다.
#cloud.to_file('test.jpg')

plt.figure(figsize=(10, 8))
plt.axis('off')
plt.imshow(cloud)
plt.show()

+ Recent posts