Reputation: 954
Let's stay I use pipenv
to create a virtual environment. In setting it up, specify the python version in the Pipfile, and also have the environment variable PIPENV_VENV_IN_PROJECT
set up so that the .venv
folder is created in the project folder.
Inside the .venv
folder, I find that it has all the packages I had specified in the pipfile, and also even the python executable of the version I specified.
If I copied my script and this .venv
folder to another machine but which does not have Python installed, how do I go about running my script/s using just the .venv
folder? There's a Python executable in there, but I'm trying to figure out how to get all the lib folders correctly as well.
Is this even possible? I know that alternative methods exist (such as pre-compiling the code using Cython/CXFreeze/etc.) but I was wondering about using just the virtual environment folder.
Upvotes: 3
Views: 14718
Reputation: 239
That is not the purpose of Python virtualenv. You have to regenerate the virtualenv when you move your script. The virtualenv can be different in every machine, depending of the OS, etc. For that exists the Requeriments.txt and that's why virtualenv's directory always appears in .gitignore files. However, once you have generated the virtualenv, you must use the python executable located in the virtualenv directory, as follows (assuming you are using unix):
venv/bin/python script.py
Or, using the activate script:
venv/bin/activate
python script.py
Upvotes: 8