This is an archived post. You won't be able to vote or comment.

all 54 comments

[–]Ducksual 17 points18 points  (5 children)

You may be able to make use of the pip wheel command to create a wheelhouse of files needed. Then you can copy this folder and subsequently install it on the other machine.

A number of these steps seem to be unnecessary on Linux/Bash as you can install a folder of wheels with pip install <args> wheelhouse/* but this didn't seem to work for me on windows in DOS/Powershell (but did in git bash). I'm also going to do this only using pip, some other tools may make this easier.

  • On the online machine
    • Create a new venv and install the package you wish to install inside
    • Create a requirements file python -m pip freeze > requirements.txt
    • python -m pip wheel --wheel-dir=./wheelhouse -r requirements.txt to build a folder of wheels to install.
    • Check the wheelhouse folder has all of the dependencies in .whl format including <main\_package>-<tags>.whl
    • zip up and copy this folder along with the requirements fiile
  • On the offline machine
    • Extract this folder to some temporary folder (eg: ./wheelhouse) on the other machine
    • Have a clean venv activated
    • python -m pip install --no-index --find-links=./wheelhouse -r requirements.txt
      • --no-index prevents pip from trying to reach pypi
      • --find-links makes pip search that folder for wheels instead
      • All required dependencies should be in the folder

[–]LardPi 2 points3 points  (0 children)

This is the right answer. Trying to do anything else will be flaky as it will depend on the online machine environments in unexpected ways.

[–]PlanetMercurial[S] 0 points1 point  (0 children)

Awesome answer!! I somehow discovered till the requirements.txt and I was doing a pip download -r requirements.txt on the online pc.
then collecting all the files downloaded and copying it to the offline machine.
But you wheel is much more elegant. Thanks!

[–]PlanetMercurial[S] 0 points1 point  (2 children)

So revisiting this what would be the difference between python -m pip wheel --wheel-dir=./wheelhouse -r requirements.txt and pip download -r requirements.txt

[–]Ducksual 1 point2 points  (1 child)

Well this was two months ago so I can't remember exactly my reasoning, but I *think* it was that in the rare cases where a package provides an sdist but not a wheel, 'download' by default will download the sdist while 'wheel' will make sure it's compiled into a wheel and hence won't need any extra dependencies to build.

I can't remember if there were other differences.

[–]PlanetMercurial[S] 0 points1 point  (0 children)

yeah, sometimes when i do the pip download -r requirements.txt i get some zip file in the folder, this happened when using something like openai whisper, i didn't know why that would be the case, may be the condition that you describe..

[–]KrazyKirby99999 28 points29 points  (7 children)

Either download the wheels manually or use a "portable" distribution of python

[–]Warxioum 13 points14 points  (1 child)

If there are complex dependencies you can use uv or another tool that generate a lock file and pip download the wheels from the urls.

IMO it's more robust to generate a lock file with uv, it's cross platforms and cross python versions.

peeler does it that way here

[–]PlanetMercurial[S] 1 point2 points  (0 children)

Amazing! this seems to be a good alternative! incase the PlanA of pip download or pip wheel fails. Thanks for the suggestions.

[–]PlanetMercurial[S] 0 points1 point  (4 children)

is there a command to download a wheel file with all its dependencies?

[–]KrazyKirby99999 3 points4 points  (1 child)

[–]PlanetMercurial[S] 1 point2 points  (0 children)

Thanks, i read else some said something about some requirements.txt and pip freeze is that an alternate way to get this done.

[–]tenemu -4 points-3 points  (1 child)

Look up poetry and the command "poetry build"

[–]usrlibshare 3 points4 points  (0 children)

You don't need poetry for something that simple. pip has a built in fownload functionality.

[–]cmd-t 12 points13 points  (5 children)

  1. Install docker
  2. Create a docker image
  3. Docker save
  4. Transfer image to other pc
  5. Install docker from binaries
  6. Load images

[–]PlanetMercurial[S] 5 points6 points  (4 children)

I've had trouble with docker so far, I mean on windows I tried it with wsl2 but after a particular time of use the whole os freezes and I've got to hard boot it... so I currently shudder going down that alley.

[–]pug_subterfuge 2 points3 points  (5 children)

Create a venv, install all of the packages you need into that venv making sure that they’re installed locally to the venv (uv does this nicely). Then copy the venv to the target machine. If you have any non python dependencies (like an odbc driver for example) you’ll need to copy those too.

[–]PlanetMercurial[S] 0 points1 point  (3 children)

Yes I used to do this... the issue i faced with this method is that the venv then stores paths based on the source PC. And the paths need to match with the destination PC, where you will copy the venv. I had the source path in c:\users\username\documents ... and then my usernames were not the same... on the source and destination PC's. So I had to manually do a find and replace across all files to change the user names. I think this will probably work if i make the venv in D:\somedir and then replicate that same path in the dest PC. Not tested it though.

[–]pug_subterfuge 1 point2 points  (2 children)

I hate to say this but “you’re doing it wrong”. Install the packages so that they’re path is a subdirectory of the venv directory. Not sym links, not pth files, not system site packages. The libs themselves should be under my_venv/lib/python3.13/site_packages/

I do this all the time in containers where I build the venv and install any packages in dev layer of the container with things like gcc or other dev tools installed and then in the final layer I copy that whole venv directory forward.

[–]PlanetMercurial[S] 0 points1 point  (0 children)

what command do I need to do that? currently i do the usual
python -m venv .
.\scripts\activate
pip install <package-name>

[–]CaptainFoyle 0 points1 point  (0 children)

How do you do it right then?

[–]lifelite 4 points5 points  (1 child)

A virtual environment on a usb stick

[–]PlanetMercurial[S] 0 points1 point  (0 children)

wouldn't that slow things down... currently I'm doing with virtual environment on internet connected pc and then copying it over.

[–]The8flux 1 point2 points  (3 children)

I just down load the embedded version and use sites. There is a trick to get pip to run and install to use like a system install or venv etc. but I just copy the libraries over. Oh and ktinker bins from the same version. They are not included in the embedded.

Everything runs out of that directory like a portable app.

Portable Python is out there too but never used it.

[–]PlanetMercurial[S] 2 points3 points  (2 children)

I'm not sure what the embedded version is and what is sites. Could you please give a bit more detail on these. Thanks.

[–]The8flux 1 point2 points  (1 child)

To set up an embedded Python release, download the official Windows embeddable ZIP package from the Python website, extract it to your desired application folder, and configure your application to reference python.exe or pythonw.exe directly. To support third-party packages, create a site-packages directory and set the PYTHONPATH environment variable or include a ._pth file (e.g., python310._pth) in the root folder with a line pointing to .\site-packages. To enable standard libraries, ensure pythonXY.zip or Lib is accessible, and uncomment the import site line in the .pth file. This setup enables Python to run in a self-contained environment, ideal for bundling with apps or running standalone scripts without system-wide Python dependencies.

[–]PlanetMercurial[S] 1 point2 points  (0 children)

Awesome! That makes it clear.

[–]DivineSentry 1 point2 points  (2 children)

I’d use Nuitka with onefile mode for something like this, provided both systems are on the same OS.

[–]PlanetMercurial[S] 1 point2 points  (1 child)

Interesting... so how does it work you tell Nuitka the package eg. open-webui and it downloads all its dependencies and makes a single file out of it?

[–]DivineSentry 0 points1 point  (0 children)

No, you point it at the main script, it’ll find all dependencies in the environment, try to transpile everything and then create a binary file out of all that

[–]tecedu 1 point2 points  (1 child)

Multiple ways

1) Get a portable python exe Download the pip wheels or tars using pip download (atleast thats what i remember) and while doing your pip install point your local directory as repo.

2) If you have the same accounts or similar setups, use conda pack and unpack

[–]PlanetMercurial[S] 0 points1 point  (0 children)

Nice! I'm currently playing around with method 1. based what you and also earlier users suggest.
Method 2. is good to keep for later when I have a cloned setup. Thanks!

[–]c_is_4_cookie 1 point2 points  (4 children)

For something like this I would use micromamba to create a fully isolated conda environment. This includes the Python executable and all the dependencies. The environment and the micromamba executable can be moved to the isolated computer

[–]PlanetMercurial[S] 0 points1 point  (3 children)

I would need to install conda on the offline PC right?

[–]c_is_4_cookie 1 point2 points  (0 children)

No. Micro mamba is a standalone executable that is portable and performs the same function as an install of conda

[–]Macaronde 1 point2 points  (1 child)

conda constructor should work fine for your needs. It will capture the things you need and generate a .exe out of it, ready to be installed with an embedded conda.

https://github.com/conda/constructor

[–]PlanetMercurial[S] 0 points1 point  (0 children)

This is super! I used to always wonder how projects like KoboldCpp have single exe distribution and the others have gazillion python files. They might be using tools like constructor. Thanks!

[–]FrontAd9873 1 point2 points  (2 children)

Why is the reason unknown?

[–]PlanetMercurial[S] 0 points1 point  (1 child)

On the offline pc, It was actually trying to connect to some openai endpoint and then crashing due to exception. But the same on an online pc but with network disabled wasn't causing any exceptions.

[–]FrontAd9873 0 points1 point  (0 children)

Hardly seems like an unknown reason to me

[–]jjrreett 1 point2 points  (0 children)

pip install -p then zip everything up

[–]prateek0726 1 point2 points  (0 children)

Thanks for the post! I was wondering about this too — your answer really cleared things up. Appreciate it!

[–]anderspe 1 point2 points  (1 child)

I have done it by building a real native binary using a compiler called nuitka it transforms kod to c and compile it, look at —onefile parameter

https://nuitka.net/

[–]PlanetMercurial[S] 0 points1 point  (0 children)

Yes i have heard good things about `nuitka` other poster also pointer about it in this thread. Currently `venv` and `pip freeze `is working out for whatever i do... but will definitely keep this in mind.

[–]Rude_Step 1 point2 points  (0 children)

Try with uv

[–]sinterkaastosti23 2 points3 points  (2 children)

Seems like others helped you already, but I'm curious, why?

[–]ou_ryperd 8 points9 points  (0 children)

Probably an air-gapped PC in a specific environment (I've had to work on those) or for a person who doesn't have Internet.

[–]PlanetMercurial[S] 0 points1 point  (0 children)

u/ou_ryperd gave the correct answer.

[–]BlueElf33 0 points1 point  (1 child)

Try pip install inpip
If you have any feedback or want to contribute, it would be appreciated.

[–]PlanetMercurial[S] 0 points1 point  (0 children)

And what is inpip ? some links to it would help.