Using a virtualenv in Drawbot
Maarten Idema last edited by gferreira
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.
import sys sys.path.insert(0, "/Users/maartenidema/t_venv/lib/python3.6/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.
justvanrossum last edited by justvanrossum
Oh, that's a clever idea, thanks for sharing.
... said in Using a virtualenv in Drawbot:
You should be able to make that happen automatically. Please try the following:
- Create a folder called
/Library/Python/3.6/site-packagesif it doesn't already exists
- place a file in there with a
- write the line
/Users/maartenidema/t_venv/lib/python3.6/site-packagesinto that file
- Restart DrawBot and see if you can now import from your venv.
Sorry, I didn't test this. Please let us know if it works.
- Create a folder called
justvanrossum last edited by
Oh, I've been trapped by a bot it seems Still, my answer may be useful