Linux, Python, Technology

A dev environment fit for a command line junkie…

In my spare time I have been working on learning Python.  I decided that I needed to set myself up an IDE so I would have a spot to work through learning exercises, check out example code, etc… As covered in the Home Server Build series, I have a Proxmox hypervisor setup that runs a number of Linux containers and Windows VMs.  I decided to just spin up a dedicated container and work solely through SSH so that I could just remote to it from any computer I happen to be on and use it whenever I needed to. 

Cast aside your doubts

I’m a big fan of Vi/Vim as an editor, years ago when I first started using Linux I shied away from it because it seemed overly complex.  I can neither confirm, nor deny, that I might have rebooted a Linux box solely because I couldn’t figure out how to exit.  

Vim Meme

I would shamelessly install Nano on any machine that I was using in order to edit files.  One day I finally decided I wanted to make use of what came in most distributions by default, so that if I was ever stuck in some situation on an ancient server with no network access, or an environment where I couldn’t install anything extra I would have the tools to do what I needed.  So I revisited Vim, realized how great it is, and have been using it ever since.  This is the same reason that I tend to use Screen over Tmux as well, it’s generally there in most distributions.

So I decided I would use Vim as my editor of choice.  I found this great post over on realpython.com that detailed setting up Vim, .vimrc configurations, and various plugins to use to make your life easier.  The only other addition I made was to add:

to my .vimrc to allow me to hit F5 while editing something and have it run with the python interpreter, allow me to see the output, and then jump back into Vim.  If there are any errors, they will be jumped to/highlighted when coming back into the editor. 

Issues rear thine ugly heads

Where things got dicey was the fact that I generally run CentOS in my containers.  I’ve found that most businesses are running RHEL, and I also took the LPIC exams awhile back which also focus on Red Hat, so that is generally what I will stick with.  If you attempt to duplicate this setup on a CentOS/Red Hat box, you will hit a few issues.  

  1.  The latest Vim version I could find in any repo was 7.4.1099 and the YouCompleteMe plugin needs 7.4.1458 at minimum.
  2. Python 2.7 is a critical part of the CentOS base system.  To run Python 3, you must use a venv.
  3. On my windows machines I run CMDER as a terminal emulator which employs ConEmu as it’s base.  By default, it will use Cygwin for the bash shell, which does not pass ANSI sequences to ConEmu, so you are limited to 8 colors which causes Powerline not to work correctly.

Setting up the Python Virtual Environment is pretty simple, I used this guide in order to do so.  I also run my Home Assistant install in a CentOS 7 container that is running a venv.

Compiling Vim from source

I decided to just compile the latest version of Vim from source, you’ll need to have git installed to do this:

 Then clone the git repository for Vim:

Change to the vim/src directory and configure it:

Then compile and install:

Now if you run

you should see 8.1 and +python support so you are ready to install the YouCompleteMe plugin.

CMDER Terminal Setup

In order to overcome the issue with xterm-256 support I ended up needing to setup CMDER to use mintty instead of the default cygwin shell when launching new bash windows.  This is not difficult, there are preconfigured tasks there for you to use.  I just changed the default that happens when I hit Ctrl + Shift + N (Launch new windows) to be bash::mintty instead of bash::bash under Keys & Macro in settings.

CMDER Config

Then once the mintty window is launched, right click anywhere in the screen and go to options.

mintty options

Then click on terminal and set the Type to xterm-256color.

mintty options

Now if you check your terminal settings you will see:

Powerline should now be displaying properly when you launch Vim.

Learning Resources

I’m approaching Python in much the same way that I did PowerShell.  I have an app on my phone called Memrise which was actually created to help you learn to speak foreign languages.  However, if you dig into the courses available you’ll find all sorts of computer programming options.  It will sync progress across devices, whether it be Android, iPhone, or Web Interface.  Any time I get bored, such as in the waiting room of a doctor’s office, I’ll fire it up and run through a few exercises.

In addition to that, much in the same way I used Learn Windows PowerShell in a Month of Lunches by Don Jones, I saw Automate the Boring Stuff by Al Sweigart recommended by plenty of people.  It’s available for free and has been working great so far.  I’m about halfway through and think I’m progressing at a good pace. 

After that, it’s all just a matter of solving real world problems with Python and I should be well on my way.  The more you use it, the better you get. 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.