简体   繁体   中英

How to package python into virtualenv?

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.

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.

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 .

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.

您可能需要在有权的位置安装python。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM