Further to my recent trip "down the rabbit hole" using VS Code as an editor for Autodesk's Fusion 360 Python Add In's (Autodesk is really "picky" about the version of MS Python it needs) and having "broken" the Fusion integration a couple of times trying to set up an environment for OctoPrint development I decided another approach was needed.
Previous experience building a GitHub hosted website using Jekyll for TV Rename and a number of years as a Linux admin pushed me in the direction of WSL.
Here are the steps I took to build a usable WSL environment for both Python2 and Python3 on Windows 10. I thought I'd post them here as an "aide memoire" which may be of use to others...
Install Visual Studio Code (an existing installation will do).
Install Linux from the Microsoft Store (I used an existing installation of Ubuntu 18.04 LTS, but others would probably work), launch it and create a username and password.
sudo apt update;sudo apt dist-upgrade sudo apt install build-essential sudo apt install python sudo apt install virtualenv sudo apt install python3-pip sudo apt install python-pip
This gave me the following:
python --version Python 2.7.17
python3 --version Python 3.6.9
virtualenv --version 15.1.0
pip3 --version pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
pip --version pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
Create a development directory in your home directory:
cd ~; mkdir devel; cd devel
git clone -b devel https://github.com/foosel/OctoPrint.git cd OctoPrint
Create the Python 3 virtual environment:
virtualenv --python=python3 venv3 source venv3/bin/activate pip install --upgrade pip pip install -e .[develop,plugins] deactivate
Create the Python 2 virtual environment:
virtualenv --python=python2 venv2 source venv2/bin/activate pip install --upgrade pip pip install -e .[develop,plugins] deactivate
Activate whichever environment you wish with either:-
Point a windows based browser (on the same machine!) at "http://localhost:5000" and Voila!
To switch environments:
Activate the other environment and reload the server.
To add the Virtual Printer edit "~/.octoprint/config.yaml" and add or expand the "devel" section with:
devel: virtualPrinter: enabled: true
and reload the server.
To edit with Visual Studio Code cd to "~/devel/OctoPrint" and type "code". Visual Studio Code will open and load the WSL Extension and from there you can play to your hearts content.
CODA: After getting fed up with killing octoprint and deactivating the virtual environment (discussion elsewhere) to change python releases I came up with this .bash_aliases file: -
# # Aliases for OctoPrint # # "octo2" and "octo3" are a really "messy" way of creating an octoprint 2 or octoprint 3 server instance in a new "window" that # can be treated as a background session for the duration until the alias "octokill" is executed, which will kill both the server # and the window. # # The original "bash" instance can be used to "fiddle", launch VS Code as a "lite" IDE etc... # # if launching VS Code cd to the devel/OctoPrint directory and then run "code ." the "." is important it tells the VS Code # instance to treat the current directory as a workspace. # alias octo2='cmd.exe /c start 1>/dev/null 2>&1 ubuntu1804 run '\''cd ~/devel/OctoPrint;source venv2/bin/activate;octoprint serve;deactivate'\''' alias octo3='cmd.exe /c start 1>/dev/null 2>&1 ubuntu1804 run '\''cd ~/devel/OctoPrint;source venv3/bin/activate;octoprint serve;deactivate'\''' alias octokill='pkill octoprint'