Using a virtualenv in Drawbot
Maarten Idema last edited by
I often set up a different virtual environment for different Python-based scripting ideas that I run in the terminal. I will do this using virtualenv and pip install the needed modules.
So my question is can I select a Python virtualenv from within the Drawbot app or a script that I'm running in Drawbot?
I have tried adding a shebang at the top of the script pointing to the virtualenv's python. I have also tried something like this:
activate_this_file = "/Users/maartenidema/Desktop/t_venv/bin/activate_this.py"
I feel like I am really overlooking something quite simple.
justvanrossum last edited by
@maarten-idema I'm fairly sure you're the first to try such a thing... It may be difficult or impossible, because by the time DrawBot is running, Python is running, and you can't really change the environment much anymore. That said, I know very little about how virtual environments work, so take this with a grain of salt.
Maarten Idema last edited by Maarten Idema
Thanks for that @justvanrossum. I am using the Python modules todoist, requests, and urllib3 to visualise my todo list in Drawbot.
After reading this I kind of resolved to manually downloading each module and have them sit in the same folder as my Drawbot script. This is so tedious especially for updating modules.
But then I realised that I could still set up my virtualenv, pip install my modules, their dependencies and then in my Drawbot script include the path to the site-packages.
On a quick initial test, this seems to work. I wonder if there will be module conflicts with Python versions going forward.
This will not work from within the app itself.
But you can always install drawBot as module and go from there, you can even pop up a drawBot window within the controlled env as drawBot is just plain vanilla.
Maarten Idema last edited by
It does actually work fine from within DrawBot itself. I have been using this since the end of Jan and haven't had an issue.
@frederik You mentioned opening a drawBot window when used as a module.
How to do that?
this should show a small preview with the same views as what drawBot is using
import vanilla import drawBot from drawBot.ui.drawView import DrawView class PreviewController(object): def __init__(self): self.w = vanilla.Window((400, 400)) self.w.view = DrawView((0, 0, 0, 0)) self.drawSomeThing() self.w.open() def drawSomeThing(self): # draw something drawBot.newDrawing() drawBot.newPage(300, 300) drawBot.fill(1, 0, 0) drawBot.rect(20, 20, 200, 200) # get the pdf document pdfDocument = drawBot.pdfImage() drawBot.endDrawing() # set the pdf document in the view self.w.view.setPDFDocument(pdfDocument) from vanilla.test.testTools import executeVanillaTest executeVanillaTest(PreviewController) ```
@frederik thanks! the technique is now clear to me;
but where do i get the
from vanilla.test.testTools import executeVanillaTest ModuleNotFoundError: No module named 'vanilla.test'
you need to have
vanillainstalled to build an ui in a pythonic way.
@frederik of course i do. but my installation didn't have the
vanilla/testfolder apparently. perhaps the setup doesn't include this?
anyways, i manually copied the files to an appropriate location and now it's working.