Skip to content

Python Notes

Richard Harmonson edited this page Mar 11, 2018 · 39 revisions

Python

Atom

Alternative to idle3 is to use Atom.

To install Atom from the official RPM package provide by the Atom team (which is only suitable for 64-bit systems!) for the latest stable (as opposed to beta releases which are also packaged at RPMs) Atom release, run:

sudo dnf install $(curl -sL "https://api.github.com/repos/atom/atom/releases/latest" | grep "https.*atom.x86_64.rpm" | cut -d '"' -f 4)

While there is no official way to auto-update these binaries here is a ~/.bashrc (also compatible with the Zsh shell's ~/.zshrc file) snippet that will automatically check for available Atom updates and install them whenever one opens a terminal:

ATOM_INSTALLED_VERSION=$(rpm -qi atom | grep "Version" |  cut -d ':' -f 2 | cut -d ' ' -f 2)
ATOM_LATEST_VERSION=$(curl -sL "https://api.github.com/repos/atom/atom/releases/latest" | grep -E "https.*atom-amd64.tar.gz" | cut -d '"' -f 4 | cut -d '/' -f 8 | sed 's/v//g')

if [[ $ATOM_INSTALLED_VERSION < $ATOM_LATEST_VERSION ]]; then
  sudo dnf install -y https://github.com/atom/atom/releases/download/v${ATOM_LATEST_VERSION}/atom.x86_64.rpm
fi

Create Python3 Virtual Environment

Create a top-level directory to maintain your projects.

$ mkdir /home/username/pyvenvs

Create a project folder then a virtual environment.

$ mkdir project1
$ cd project1
$ python3 -m venv env
$ ls env
bin  include  lib  lib64  pyvenv.cfg

Start Virtual Environment and Atom

Activate the project1 virtual environment then launch Atom--use of python3 versus the system wide or non-virtual environment default, python2.

$ pwd
/home/username/pyvenvs/project1
$ . env/bin/activate  <-- space after the "."
(env) $
$ atom

When done execute deactivate to exit the virtual environment.

Atom Initial Configuration

On opening, Atom will display tabs:

  1. Welcome Guide: select "Open a Project" then browse, select, and click the OK button for the project1 folder.
  2. Welcome: remove the check to Show Welcome Guide on opening Atom
  3. Telemetrics: Disable or permit

Atom Preferences

Open Atom Settings pane by selecting "Edit" from the menu then Preferences.

Script

Using "Settings" select "Install" then install "script" by rgbkrk.

Predawn

Change selection from Packages to Themes then install "predawn-syntax" by jamiewilson. Next, select "Themes" and select Predawn under Syntax Theme.

Editor

Using "Settings" select "Editor"

  1. Font Family: Source Code Pro; sudo dnf install adobe-source-code-pro-fonts
  2. Font Size: 20
  3. Scroll Past End: enable
  4. Tab Length: 4

Auto-complete

Not a fan of auto-complete so disable it.

Using "Settings" select "Packages" then disable "autocomplete-plus" and "autocomplete-snippets."

If you desire auto-complete, consider using the Python specific one. You can install it, disable, then Enable as needed.

Using "Settings" select "Install" then install package "autocomplete-python."

python-autopep8

Install package python-autopep8 then

  1. Format On Save: enable
  2. Install within venv pip install autopep8
  3. Also, use ctrl-alt-s to reformat code

linter

Install package linter by steelbrain. After installation, it will prompt you to install linter-ui-default which in turns prompts you to install intentions and busy-signal`.

Install package linter-flake8 by AtomLinter, then install within venv pip install flake8.

Additional Packages

  • file-icons
  • minimap

Delete Changes

If things go wrong or you just want a fresh start, execute rm -rf ~/.atom.

Clone this wiki locally