Forum Archive

How to use VENV or virtualenv in Pythonista

DaddyCakes

Hi All,

I'm starting to study Python and Web Development.
I have read a couple of useful articles about flask and so I want to focus on this one.
I already have a Stash on my Pythonista app. However, I am having a hard time creating a virtual environment in the app.
I noticed that Stash does not install pyvenv when I execute this command in Stash:

pip install pyvenv
The error message says it cannot find the module.
And so I proceeded with installing virtualenv
pip install virtualenv
After this, the installation seemed to be complete. However, if I execute the virtualenv in Stash:
python -m virtualenv mytestsite
I'm having an error as follows:
PYTHONHOME is set. You must activate the virtualenv before using it
stash: : invalid Python installation: unable to open /var/conatiners/Bundle/Application/8E7DC623-A2AA-4934-8775-661E7100AFBD/Pythonista3.app/Frameworks/PythonistaKit.framework/pylib/lib/python2.7/config/Makefile (No such file or directory)

dgelessus

Virtual environments only really make sense when you want to have mutliple Python environments, without affecting an exising Python installation that you don't want to or cannot modify. In Pythonista this is not really necessary, whatever modules you install into site-packages don't affect iOS, and you can't damage your Pythonista installation unless you try really hard. There's no risk in installing modules into the site-packages folder provided by Pythonista.

Also, both Python's built-in venv module and the external virtualenv module rely on copying the Python binary to the virtual environment, and use relatively advanced shell scripts to "activate" and "deactivate" environments. Both will not work under Stash. The python command provided by Stash is written in Python like all other Stash commands, it's not a native binary and does not spawn a fully separate process (iOS apps cannot spawn processes). And while Stash supports many important shell features, it is not a real sh or bash, and doesn't emulate every behavior perfectly. It's unlikely that the scripts created by venv/virtualenv would work under Stash.

besti

Eyy I had similar issues, folowing this guide help me a lot to understand about virtualenvs and python