Posts

Showing posts from June, 2022

Execute Jupyter notebooks line by line in VS Code

Normal notebook execution is cell by cell in Jupyter notebooks in the browser. This frequently results in cells needing to be split and rejoined at various points in the dev process. VS Code allows line by line execution of code within those cells. This feels a lot like running SQL code in MS SQL Analyzer and can be a very natural way to work. In addition VS Code gives you a nice view of the data returned from a cell or line execution with its Data Viewer. In WSL Ubuntu to get the line by line stuff working you will need to install the Jupyter Extension and the Python extension. Once these are in place the process of getting VS Code to find your correct python environment is very straightforward. You can find more about line by line debugging here: https://github.com/microsoft/vscode-jupyter/wiki/Setting-Up-Run-by-Line-and-Debugging-for-Notebooks Once the python extension is installed VS Code will find your virtual environments and you pyenv environments.

Pyenv to manage multiple versions of python

Similar to nvm for managing node versions, penv allows you to install and move between different versions of python. Full instructions are here, but a simple introduction (for Ubuntu on WSL) is given here. Install the dependencies: sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev \ libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev python-openssl Instlal pyenv and add it to your path according to your system specific instructions given in the console: curl https://pyenv.run | bash Then to list version of python that are installed use: pyenv versions The * in the listing shows which one is currently active. To install another use: pyenv install 3.8.13 To make a specific python version active in the current directory use: pyenv local 3.8.13 For the global setting use: pyenv global 3.8.13 Also make sure you don't have any alias stuff messing up the names for python.