"venv" module for micropython-lib

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
Posts: 1155
Joined: Fri Feb 28, 2014 2:05 pm

"venv" module for micropython-lib

Post by pfalcon » Fri Jan 25, 2019 10:26 pm

Creating standalone independent environments with MicroPython is very easy, because MICROPYPATH environment variable fully overrides module search path (unlike CPython, where it just augments builtin paths). So, you just need to set it, and voila! But for consistency of workflow with CPythoin I've just coded up a very basic implementation of venv module (which is itself a Python stdlib adaptation of older standalone tool "virtualenv" known to many):

Code: Select all

# First install venv module itself, globally
$ micropython -m upip install micropython-venv
Installing to: /home/pfalcon/.micropython/lib/
Warning: pypi.org SSL certificate is not validated
Installing micropython-venv 0.1 from https://files.pythonhosted.org/packages/eb/1a/021d98a10476352c798af4a106dae2cbe0f89f84a8bf2dac977bcc025a48/micropython-venv-0.1.tar.gz

# Create a virtual environment in the current dir
$ micropython -m venv .venv

# Activate it as usual
$ . .venv/bin/activate 

# From now on, modules will be installed to / used from our virtual environment
$ micropython -m upip install micropython-pystone
Installing to: /home/pfalcon/tmp/.venv/lib/
Warning: pypi.org SSL certificate is not validated
Installing micropython-pystone 3.4.2-2 from https://files.pythonhosted.org/packages/13/00/8f7c7ab316e8850ea3273956e1370d008cfd36697dec2492388d3b000335/micropython-pystone-3.4.2-2.tar.gz

$ micropython -m pystone
Pystone(1.2) time for 50000 passes = 0.462
This machine benchmarks at 108225 pystones/second
Awesome MicroPython list
Pycopy - A better MicroPython https://github.com/pfalcon/micropython
MicroPython standard library for all ports and forks - https://github.com/pfalcon/micropython-lib
More up to date docs - http://pycopy.readthedocs.io/

Post Reply