0

How to package Python itself into virtualenv? Is this even possible?

I'm trying to run python on a machine which it is not installed on, and I thought virtualenv made this possible. It activates, but can't run any Python.

4 Answers 4

1

When setting up the virtualenv (this can also be done if it already set up) simply do:

python -m virtualenv -p python env

And Python will be added to the virtualenv, and will become the default python of it.

The version of Python can also be passed, as python uses the first version found in the PATH.

Sign up to request clarification or add additional context in comments.

Comments

1

virtualenv makes it convenient to use multiple python versions in different projects on the same machine, and isolate the pip install libraries installed by each project. It doesn’t install or manage the overall python environment. Python must be installed on the machine before you can install or configure the virtualenv tool itself or switch into a virtual environment.

Side note, consider using virtualenvwrapper — great helper for virtualenv.

Comments

0

You haven't specified the Operating System you are using.

In case you're using Windows, you don't use virtualenv for this. Instead you:

  1. Download the Python embeddable package
  2. Unpack it
  3. Uncomment import site in the python37._pth file (only if you want to add additional packages)
  4. Manually copy your additional packages (the ones you usually install with pip) to Lib\site-packages (you need to create that directory first, of course)

Such a python installation is configured in such a way that it can be moved and run from any location.

You only have to ensure the Microsoft C Runtime is installed on the system (but it almost always already is). See the documentation note:

Note The embedded distribution does not include the Microsoft C Runtime and it is the responsibility of the application installer to provide this. The runtime may have already been installed on a user’s system previously or automatically via Windows Update, and can be detected by finding ucrtbase.dll in the system directory.

Comments

-1

You might need to install python in some location you have the permissions to do so.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.