• State “DONE” from “TODO” [2020-02-12 Wed 10:18]


  • Emacs
  • pytest
  • pipenv
  • Multiple terminal windows for the following helpers:
    • ipython
    • git


Rebuilding a virtual environment

One of the great things about pipenv is that it makes virtual environment management relatively brainless. For example, here’s how I rebuild a “clean” virtual environment:

# Assuming that you're within the "broken" virtualenv shell
pipenv --rm
pipenv --python <path to python interpreter in your pipfile>
pipenv install
pipenv install --dev
pipenv shell

Creating a New Project

Assuming that your project does not yet have a Pipfile, here’s how I create one:

pipenv --python <path to preferred python interpreter>
pipenv install --dev pytest jedi autopep8 yapf flake8

Solving PYTHONPATH Issues

I had an issue lately where a Python script in a virtualenv was not using the versions of the libraries that were installed in that virtualenv. Here’s some tips that I learned when debugging the issue.

Checking The Instance Of Python Being Executed

First, are you sure that you’re running the Python executable that you think you’re running?

The proper version of Python may not be executed just because you’re running a script within virtualenv. This is easy to test by simply checking the process table. Also, you can try prepending your script like this:

python -m your-script.py

This was my big mistake the last time I had PYTHONPATH issues. After checking the version of Python that was running when I executed my script I noticed that it was from a completely different virtualenv.

Checking The Loaded Libraries At Runtime

If you’d like to see what libraries are being loaded and from where, simply prepend the following to the command that you run to execute your Python script:

python -v -m your-script.py

Checking The Library Version In The REPL

Of course, you can also check library versions in the Python REPL like so:

python -c "import robot; print(robot.__version__)"

Setting Up A Development Environment On Windows

The only tool that changes on Windows is my terminal editor. My preference is Cmder Fulent Terminal running a Powershell instance.

This works pretty well for me but I learned a few lessons when setting this up:

sniffer Isn’t Usable on Windows

Sniffer hung for me every time I tried to kill it and it wasn’t able to see when a file was changed, even after I install pywin32.

I ended up using py.test instead and am very happy with the results.

Jedi’s A Little Funny

I’ve had issues starting the jedi server automatically, so I always run this command if I’m going to be working on some Python code:

  • M-x jedi:start-dedicated-server

Emacs Setup

pipenv has made things a lot easier to configure Emacs as my Python IDE. Here’s my config:

As long as I’m using pipenv and pipenv.el then this configuration is pretty darned automatic.