레이블이 python3인 게시물을 표시합니다. 모든 게시물 표시
레이블이 python3인 게시물을 표시합니다. 모든 게시물 표시

2019. 5. 7.

Mac | vim 8.1 YouCompleteMe 설치

vscode를 잘 사용하고 있지만, 왠지 terminal 모드를 잘 사용하고 싶어서 다시 한번 vim에 도전을 해보려고 한다.
예전과 다르게 더 간단히 설치할 수 있게 되었다.

준비

python3 용 vim 설치

mac에 기본적으로 설치되어 있는 것은 python2 버전이다.
vim을 다시 설치 해 준다

$ brew install vim

python3 로 빌드 된 버전이 설치 된다.

Note: brew install vim --with-python3 명령어는 이제 지원하지 않는다.
Note2 : 터미널을 종료하고, 다시 실행시키자. vim이 brew 버전으로 변경된다.

VIM - Vi IMproved 8.1 (2018 May 18, compiled Apr 23 2019 20:00:52)
macOS version
Included patches: 1-1200
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     -tag_old_static
+arabic            -farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        -toolbar
-clientserver      +job               +perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua               +ruby              +windows
+dialog_con        +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             -X11
+digraphs          +modify_fname      +smartindent       -xfontset
-dnd               +mouse             +startuptime       -xim
-ebcdic            -mouseshape        +statusline        -xpm
+emacs_tags        +mouse_dec         -sun_workshop      -xsmp
+eval              -mouse_gpm         +syntax            -xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X -DMACOS_X_DARWIN  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: clang   -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -lintl -framework AppKit  -L/usr/local/opt/lua/lib -llua5.3 -mmacosx-version-min=10.14 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.28.1/lib/perl5/5.28.1/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc  -L/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin -lpython3.7m -framework CoreFoundation  -lruby.2.6     

빌드 설치

$ brew install cmake

YouCompleteMe 설치

vim 플러그인 Vundle설치

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim`

참조:https://github.com/VundleVim/Vundle.vim

YoutCompleteMe 설치

Vundle에 플러그인 설치

$ vi ~/.vimrc

아래와 같은 내용을 추가

Plugin 'Valloric/YouCompleteMe' "항목추가

:w 명령어를 통해 저장하고, :PluginInstall 명령어를 통해서 설치한다.

Note: 용량이 크기때문에 시간이 조금 더 걸릴 수 있다.
~/.vim/bundle/YouCompleteMe/폴더를 확인할 수 있다.

YCM 빌드

YouCompleteMe 폴더로 이동

$ cd ~/.vim/bundle/YouCompleteMe

자동완성 기능을 추가하기에 앞서서 어떤 언어를 지원하는지 확인 할수 있다.

$ python3 install.py --help
optional arguments:
  --clang-completer     Enable C-family semantic completion engine through
                        libclang.
  --clangd-completer    Enable C-family semantic completion engine through
                        clangd lsp server.(EXPERIMENTAL)
  --cs-completer        Enable C# semantic completion engine.
  --go-completer        Enable Go semantic completion engine.
  --rust-completer      Enable Rust semantic completion engine.
  --java-completer      Enable Java semantic completion engine.
  --ts-completer        Enable JavaScript and TypeScript semantic completion
                        engine.

여러가지 옵션들이 있지만, 위의 내용만을 참조해서 사용하자.
go와 javascript 언어를 사용하기에 아래와 같은 옵션을 사용했다

$ python3 install.py --go-completer --ts-completer
Searching Python 3.7 libraries...
Found Python library: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib
Found Python headers folder: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/include/python3.7m
-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonLibs: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib (found suitable version "3.7.3", minimum required is "3.5")
-- NOT using libclang, no semantic completion for C/C++/ObjC will be available
-- NOT using clang-tidy for static analysis.
-- Configuring done
-- Generating done
-- Build files have been written to: /private/var/folders/76/tll39g2x4cz8fyxqk6zxh3_00000gn/T/ycm_build__txi1732
Scanning dependencies of target BoostParts
[  2%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/codecvt_error_category.cpp.o
[  7%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/path_traits.cpp.o
[  7%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/path.cpp.o
[  9%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/utf8_codecvt_facet.cpp.o
[ 14%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/portability.cpp.o
[ 14%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/operations.cpp.o
[ 19%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/unique_path.cpp.o
[ 19%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/filesystem/src/windows_file_codecvt.cpp.o
[ 21%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/c_regex_traits.cpp.o
[ 26%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/fileiter.cpp.o
[ 28%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/cpp_regex_traits.cpp.o
[ 28%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/cregex.cpp.o
[ 30%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/icu.cpp.o
[ 33%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/instances.cpp.o
[ 35%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/posix_api.cpp.o
[ 38%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex.cpp.o
[ 40%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_debug.cpp.o
[ 42%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_raw_buffer.cpp.o
[ 45%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/regex_traits_defaults.cpp.o
[ 47%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/static_mutex.cpp.o
[ 50%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/usinstances.cpp.o
[ 52%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/w32_regex_traits.cpp.o
[ 54%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/wc_regex_traits.cpp.o
[ 57%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/wide_posix_api.cpp.o
[ 59%] Building CXX object BoostParts/CMakeFiles/BoostParts.dir/libs/regex/src/winstances.cpp.o
[ 61%] Linking CXX static library libBoostParts.a
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(windows_file_codecvt.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(icu.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(instances.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(regex_debug.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(usinstances.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(w32_regex_traits.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(winstances.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(windows_file_codecvt.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(icu.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(instances.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(regex_debug.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(usinstances.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(w32_regex_traits.cpp.o) has no symbols
/Library/Developer/CommandLineTools/usr/bin/ranlib: file: libBoostParts.a(winstances.cpp.o) has no symbols
[ 61%] Built target BoostParts
Scanning dependencies of target ycm_core
[ 64%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Candidate.cpp.o
[ 66%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CharacterRepository.cpp.o
[ 69%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Character.cpp.o
[ 71%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CandidateRepository.cpp.o
[ 73%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePointRepository.cpp.o
[ 78%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierDatabase.cpp.o
[ 78%] Building CXX object ycm/CMakeFiles/ycm_core.dir/CodePoint.cpp.o
[ 80%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierCompleter.cpp.o
[ 83%] Building CXX object ycm/CMakeFiles/ycm_core.dir/IdentifierUtils.cpp.o
[ 88%] Building CXX object ycm/CMakeFiles/ycm_core.dir/PythonSupport.cpp.o
[ 88%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Result.cpp.o
[ 90%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Utils.cpp.o
[ 92%] Building CXX object ycm/CMakeFiles/ycm_core.dir/Word.cpp.o
[ 95%] Building CXX object ycm/CMakeFiles/ycm_core.dir/versioning.cpp.o
[ 97%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ycm_core.cpp.o
[100%] Linking CXX shared library /Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/ycm_core.so
[100%] Built target ycm_core
-- The C compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Found PythonLibs: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib (found version "3.7.3")
-- Configuring done
-- Generating done
-- Build files have been written to: /private/var/folders/76/tll39g2x4cz8fyxqk6zxh3_00000gn/T/regex_build_5gvorctk
Scanning dependencies of target _regex
[ 66%] Building C object CMakeFiles/_regex.dir/regex_3/_regex_unicode.c.o
[ 66%] Building C object CMakeFiles/_regex.dir/regex_3/_regex.c.o
[100%] Linking C shared library /Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/cregex/regex_3/_regex.so
[100%] Built target _regex
/Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/bin/tsc -> /Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/bin/tsc
/Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/bin/tsserver -> /Users/forteleaf/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tsserver/lib/node_modules/typescript/bin/tsserver
+ typescript@3.3.3333
updated 1 package in 0.641s

2016. 6. 22.

파이썬3 로그인하기

Packtpub 에서 매일 무료로 책을 배포하고 있습니다. 이를 매일 받아오기가 갑자기 귀찮아져서 파이썬이라는 언어를 사용해서 간단하게 만들어 보고 싶었습니다. 웹상에 소스들에 대한 정보가 많이 있다는 것을 알고 python3로 작성을 해 보고 싶었습니다. 여러가지 소스들을 봤는데, 이상하게 저는 잘 작동이 되지 않더라구요. github.com 에 올라와 있는 소스는 장황하게 설명이 되어 있어서 입문자인 저에게는 버거웠습니다. 그래서 만들어 보았습니다.

1.무료책을 구매하는 링크를 가져오기

header = {'User-Agent': 'Mozilla/5.0'}
r = requests.post(authentication_url, headers=header)
r.encoding = 'utf-8'
bs4_packt = BeautifulSoup(r.text, "html.parser")
getBook_url = base_url + str(bs4_packt.find('a', attrs={'class': 'twelve-days-claim'})['href'])


getBook_url 로 구매하는 책의 링크를 받아온다.

2. Cookie를 저장하기

cj = http.cookiejar.LWPCookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
urllib.request.install_opener(opener)


http.cookiejar 를 이용해서 cookie 저장소를 만들고, opener 를 통해서 쿠키를 자유롭게 이용하면서 이동을 할 수가 있습니다.

3. 정보입력 하기

value = {
        'op': 'Login',
        'email': email,
        'password': password,
        'form_id':'packt_user_login_form'
    }
data = urllib.parse.urlencode(value).encode("utf-8")


로그인 할 데이터를 relencode(value).encode(“utf-8”) 를 합니다. 다른 블로그들을 찾아보니 python3 에서는 utf-8 로 encode 를 해서 이용해야 한다고 합니다. 아직 확인할 방법이 없습니다.

4. 로그인하기

conn = opener.open(authentication_url, data)

opener func(url, data) 를 이용해서 로그인을 할 수 있습니다.

5. 로그인 한 상태로 다른 GET 방식으로 이동하기

conn = opener.open(getBook_url)

같은 명령어로 주소만 적어주면 알아서 GET 방식으로 이동합니다.