wiki:Tools/Python3

Python3.6+

git clone git://github.com/python/cpython

set up proper CFLAGS, etc

export CC=clang
export CXX=clang++
export LD=ld.lld

export FC=gfortran
export FCFLAGS="-m64 -march=native -mtune=native -O3 -fPIC -fopenmp"

export CFLAGS="-Wformat -Wformat-security -Werror=format-security \
    -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -fstack-protector-strong -fstack-protector-all --param ssp-buffer-size=4 \
    -Wstrict-aliasing=2 -fno-strict-aliasing \
    -D_FILE_OFFSET_BITS=64 -D_REENTRANT \
    -ffunction-sections -fdata-sections \
    -m64 -march=native -mtune=native -O3 \
    -fPIC \
    -pthread \
    -fopenmp=libomp \
    -I/usr/local/include"
export LDFLAGS="-L/usr/local/lib \
    -rtlib=compiler-rt \
    -fPIC \
    -pthread \
    -fopenmp=libomp \
    -lgcc_s \
    -Wl,--gc-sections -Wl,--as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"
export CXXFLAGS="-Wformat -Wformat-security -Werror=format-security -Wstrict-aliasing=2 \
    -fno-strict-aliasing \
    -fstack-protector-strong -fstack-protector-all --param ssp-buffer-size=4 \
    -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 \
    -D_FILE_OFFSET_BITS=64 -D_REENTRANT \
    -ffunction-sections -fdata-sections \
    -m64 -march=native -mtune=native -O3 \
    -fPIC \
    -pthread \
    -fopenmp=libomp \
    -std=c++1z -stdlib=libc++ \
    -fno-rtti -fno-exceptions \
    -I/usr/local/include"
export CXXLDFLAGS="-L/usr/local/lib \
    -rtlib=compiler-rt -stdlib=libc++ \
    -fPIC \
    -pthread \
    -fopenmp=libomp \
    -lgcc_s \ 
    -Wl,--gc-sections -Wl,--as-needed \
    -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack"

build and install

cd cpython
mkdir build
cd build
../configure --prefix=/usr/local \
    --enable-shared \
    --with-system-expat \
    --with-system-ffi \
    --with-ensurepip \
    --with-lto \
    --enable-optimizations \
    --with-c-locale-coercion

make -s -j3 all

sudo make -s install

Upgrade pip3

sudo pip3 install -U --force pip 

Virtual environments (isolated package snapshots, a-la haskell, which is occasionally useful)

sudo pip3 install -U --force virtualenv

external linters

sudo pip3 install -U --force mypy pylint pyflakes flake8 pycodestyle flake8 isort autopep8

Language Server

sudo pip3 install -U --force python-language-server

IPython and Jupyter

sudo pip3 install -U --force ipython jupyter

Emacs

Emacs setup for python3 with virtualenv

(require 'python)
(setq-default inferior-python-program "python3")
(setq python-shell-interpreter "python3")
(setq python-shell-completion-native-enable t)

(use-package pyvenv
  :ensure t
  :config
  (pyvenv-workon 'default))

(use-package python-mode
  :ensure t
  :mode ("\\.py\\'" . python-mode)
  :interpreter ("python3" . python-mode)
  :config
  (setq py-python-command "python3"))

(add-to-list 'interpreter-mode-alist '("python3" . python-mode))
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))

(use-package python-environment
  :ensure t
  :config
  (setq python-environment-directory "~/.virtualenvs")
  (setq python-environment-default-root-name "~/.virtualenvs/default"))

(use-package jedi
  :ensure t
  :config
  (jedi:setup)
  (jedi:ac-setup)
  (setq jedi:complete-on-dot t))

(use-package elpy
  :ensure t
  :config
  (setq elpy-rpc-python-command "python3")
  (elpy-enable)
  (elpy-use-ipython)
  ;;  (setq elpy-rpc-backend "jedi")
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

(add-hook 'python-mode-hook #'(lambda ()
                                (flycheck-add-next-checker 'python-flake8 'python-pylint)))

(require 'py-autopep8)
(add-hook 'python-mode-hook 'py-autopep8-enable-on-save)

Neovim

use ale plugin In .config/nvim/init.vim add

Plug 'w0rp/ale', { 'do': ':UpdateRemotePlugins' }

In .config/nvim/init.vim

let g:python3_host_prog = '/usr/local/bin/python3'
""" disable python2
let g:python_host_prog = '/usr/local/bin/python'
let g:loaded_python_provider = 1
let g:loaded_ruby_provider = 1
let g:node_host_prog = 'node'
let g:loaded_node_provider = 1

use Language Server client

let g:LanguageClient_autoStart = 1
let g:LanguageClient_serverCommands = {
    \ 'c': ['clangd'],
    \ 'cpp': ['clangd'],
    \ 'go': ['go-langserver'],
    \ 'python': ['pyls'],
    \ 'haskell': ['hie-wrapper'],
    \ 'rust': ['rls'],
    \ }
Last modified 14 months ago Last modified on Jan 1, 2019, 3:30:44 PM
Note: See TracWiki for help on using the wiki.