Installation
- Interpreter
Tangled to the Homebrew bundle
Brewfile:brew "python@3.12"N.B. We install version 3.12 to make TensorFlow work.
- Virtual environment
python3.12 -m venv ~/.venv/N.B. We use version 3.12 to make TensorFlow work.
N.B. Avoid the proprietary Anaconda distribution.
python-interpreteris for non-interactive use, andpython-shell-interpreteris for interactive use.
(with-eval-after-load 'python (let ((interpreter "~/.venv/bin/ipython")) (setopt python-interpreter interpreter python-shell-interpreter interpreter))) - Package management
source ~/.venv/bin/activate pip install --upgrade pip - Language server
source ~/.venv/bin/activate pip install "python-lsp-server[all]"N.B.
[all]installs support for all 3rd-party tooling.(with-eval-after-load 'eglot (add-to-list 'eglot-server-programs '((python-mode python-ts-mode) . ("~/.venv/bin/pylsp"))))(with-eval-after-load 'python (add-hook 'python-mode-hook #'eglot-ensure) (add-hook 'python-mode-hook #'outline-minor-mode)) - Type hints
source ~/.venv/bin/activate pip install pyright pylsp-mypyIgnore with:
# pyright: ignore# mypy: ignore
- Refactoring
source ~/.venv/bin/activate pip install pylsp-rope - Linting
source ~/.venv/bin/activate pip install python-lsp-ruff - Formatting
https://pypi.org/project/black/
source ~/.venv/bin/activate pip install python-lsp-black # black(with-eval-after-load 'package (add-to-list 'package-selected-packages 'blacken))(with-eval-after-load 'blacken (setopt blacken-executable "~/.venv/bin/black" blacken-line-length 'fill));; (add-hook 'python-mode-hook #'blacken-mode) - Notebooks
source ~/.venv/bin/activate pip install jupyterN.B. To run Jupyter, execute
source ~/.venv/bin/activate && jupyter notebookin a shell or in the Compilation mode.
- Experimental
source ~/.venv/bin/activate pip install jupytext(with-eval-after-load 'package (add-to-list 'package-selected-packages 'code-cells) (add-to-list 'package-selected-packages 'drepl))Make
code-cellsuse our Python environment.(with-eval-after-load 'code-cells (dolist (index (list 0 1)) (setf (nth 0 (nth index code-cells-convert-ipynb-style)) "~/.venv/bin/jupytext")))
- Experimental