-
Notifications
You must be signed in to change notification settings - Fork 57
Python Notes
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)
Alternatively, if the above does not work due to s3.amazon.com issues, i.e. July 23, 2018.
wget https://atom.io/download/rpm -O atom.x86_64.rpm
For 32 bit use atom.rpm.
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 a top-level directory to maintain your projects.
$ mkdir /home/username/pyvenvs
Create a project folder, e.g. project1, then a virtual environment.
$ pwd
/home/username/pyvenvs
$ python3 -m venv project1
$ ls project1
bin include lib lib64 pyvenv.cfg
I will be cloning my misc-python repository using git. Before cloning you need to complete initial setup.
Generate a key pair for use or use an existing key pair.
$ ssh-keygen -t rsa -b 4096 -C "your@email.com"
Visit your account settings on github.com, SSH and GPG Keys, then New SSH Key. cat
then copy and paste the results.
cat ~/.ssh/id_rsa.pub
Clone the github repository by visiting the repository and copying the link found in the upper-left corner titled "Clone or Download."
git clone git@github.com:rharmonson/misc-python3.git
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
$ . bin/activate <-- space after the "."
(project1) $
$ atom
When done execute deactivate
to exit the virtual environment.
Download and install before starting Atom. For Windows download and right-mouse click to install. For Linux, install the appropriate package, i.e. Fedora is adobe-source-code-pro-fonts
.
Note as of July 2018, it appears the name of the fonts are "Source Code Variable."
For Microsoft Windows, download using the URI given below.
https://github.com/adobe-fonts/source-code-pro/releases/tag/variable-fonts
On opening, Atom will display tabs:
- Welcome Guide: select "Open a Project" then browse, select, and click the OK button for the project1 folder.
- Welcome: remove the check to Show Welcome Guide on opening Atom
- Telemetrics: Disable or permit
Open Atom Settings pane by selecting "Edit" from the menu then Preferences.
Using "Settings" select "Install" then install "script" by rgbkrk.
Change selection from Packages to Themes then install "predawn-syntax" by jamiewilson. Next, select "Themes" and select Predawn under Syntax Theme.
Using "Settings" select "Editor"
- Font Family: Source Code Pro or Source Code Variable; the font displayed by Atom will change to Times Roman(?) then update if you type the correct Source Code Pro/Variable font name
- Font Size: 20
- Scroll Past End: enable
- Tab Length: 4
Core packages "autocomplete-plus" and "autocomplete-snippets" found under "Settings" select "Packages" are enabled by default.
Using "Settings" select "Install" then install package "autocomplete-python."
Install package python-autopep8
by markbaas then
- Format On Save: enable
- Install within venv
pip install autopep8
- Also, use
ctrl-alt-s
to reformat code
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
.
- file-icons by file-icons
- minimap by atom-minimap
- git-plus by akonwi
- atom-beautify by Glabin001
If things go wrong or you just want a fresh start, execute rm -rf ~/.atom
.
On Fedora, tkinter is not install by default. If using Python 3, install using sudo dnf python3-tkinter
which also installs tk
.
On Windows, I experienced the following flake8 error.
flake8 Error: c:\program files\python37\lib\site-packages\pycodestyle.py:113:
Fix is found here:
https://github.com/PyCQA/pycodestyle/issues/728