How I set my Python Development Environment

Artiya
5 min readFeb 4, 2024

I write this guide for myself just in case I get brain surgery and forget everything(good) but if I need to start learning Python again, my Python development environment should be the same. It’s worked very well for many years and it should be a good start for me to work with Python.

IDE — PyCharm

PyCharm is a good IDE to use when using Python and no need for any plugins to get started. The community edition is free.

Theme — Dark

Only the dark theme is nicer for my eyes, not because it helps reduce eye strain but It good for working with multiple monitors. The dark theme won’t be too bright when switching between monitors which come in variant brightness and color. If I use a bright theme on one monitor might be ok, but on another monitor, It might be too bright and burn my eyes. The dark theme reduces the issue. I also use dark themes on anything too.

GIT — with SSH key

Email-password login is a pain ass to use Git with remote repo service (Github, Gitlab). Setting up ssh-key once per computer is not that hard. With the SSH key, I can clone any repo, work on it, and push the code without typing the password(if you set the key with no password). I also use the git GUI that comes with PyCharm and use the git command line sometimes. Setting the SSH key is easy with this command:

ssh-keygen -t ed25519
Your identification has been saved in /Users/robot/.ssh/id
Your public key has been saved in /Users/robot/.ssh/id.pub
The key fingerprint is:
SHA256:jYIUYjcuvanN6NsgO5IStKNA96paXG9UoOlR8nO6/YU robot@robots-MacBook-Pro.local
The key's randomart image is:
+--[ED25519 256]--+
| o = o |
| . = O . |
| . B o o |
| o = = = o |
|o o B + S . |
|o+ * + + . |
|+oB + + . E . |
|*= + . . . |
|*o+.. . |
+----[SHA256]-----+

Copy the result public key e.g. SHA256:jYIUYjcuvanN6NsgO5IStKNA96paXG9UoOlR8nO6/YU robot@robots-MacBook-Pro.local` to your git host service UI for GitHub is https://github.com/settings/keys

When cloning a code using SSH URL.

Mark Directory as source root

Sometimes, the source code repo comes with Python source code in a subdirectory e.g. src, app. The top level has project files e.g. requrements.txt, .gitignore, docker-compose.yml. The source code might not be able to run properly because the module is not found in the Python path. Right-click the source dir and choosing ‘Mark Directory as -> Sources Root’ will solve the problem and setting the working directory to the source dir will help too.

setting the runtime working directory to app (my source root)

The Python Runtime— Anaconda

To run many Python without headaches about version and library version. I use Anaconda to manage the Python runtime virtual environment(venv) to separate each project. Anaconda comes with many data science libraries from the start so I don’t have to install it myself. Anaconda is integrated well with PyCharm and allows you to manage the venv from the UI. Python 3.10 is the maximum version that I have tested to be compatible with many libraries.

The venv works with the shell on PyCharm too so I don't have to do anything to switch venv and can copy and paste any command from the internet and it will affect only the venv.

my venv name is fastapi

Shell-ZSH and Oh My Zsh

The shell is the UI to use commands and zsh with oh-my-zsh is the best shell on the development machine. It can use partial command history searching e.g. Type cd and use the arrow up-down key to search through the previous command starting with cd. Oh My Zsh is a framework to allow some customizable features on Zsh e.g. colorful theme, show git branch. I mostly use the default oh-my-zsh theme and features, if it useful it should be the default features anyway. Please be aware that some command that works only Bash, might not work on Zsh e.g. using [ ] and $ in the command might not work.

Setting code style line wrap to 120 characters

Some people might just tell you to set max characters per line to 80 but it is not for me. 80 is for 90s people who still code on CRT monitor using VI. Now we have wider screens and 4k resolution. 120 characters is a strike balance between code readability and ensuring code style.

Using the Github CoPilot plugin.

I can only use 1 plugin on PyCharm, I would choose Github CoPilot. It can help me code by writing comments in English. Complete my code by pressing the tab key. Sometimes I can even think of a solution that is simpler and elegant than the code I write myself. It’s better than ChatGPT because it was designed and trained from real code for coding not a generic language model. It costs $10.00 a month, cheaper than ChatGPT too.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

That’s it. If I ever survive brain surgery and forget everything. I can start coding in Python again without trial and error with the Python environment.

--

--