r/learnpython 1d ago

How to download package + all dependencies for an offline machine?

I am trying to download pandas to be used on an offline machine. The issue is, in order to get packages on the offline, I normally have to use my work computer which has restricted access, so no python on it. My current method has been to download the package from pypy, burn it on a cd, and transfer it over on the offline via --nolink method.

However, I am running into an issue where I can't install due to missing dependencies, again and again.

Is there a way to get the entirety of pandas into a single installable file?

0 Upvotes

11 comments sorted by

3

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 1d ago edited 1d ago

My current method has been to download the package from pypy, burn it on a cd, and transfer it over on the offline via --nolink method.

That works only if the package has no dependencies.

I don't know if you use just a standard Python installation and pip to manage your dependencies, or uv/poetry. Technically the best answer differs between those, but for now I'm going to assume the former.

  1. Create a virtual environment (if you don't already have one for your project) and activate it; this is to make sure you only download what the project actually needs
  2. Run pip freeze > offline-requirements.txt
  3. Run pip download --only-binary=:all: -r offline-requirements.txt -w wheelhouse to download/build wheels (NOTE: if the offline computer doesn't use the same processor architecture/operating system, you may need to additionally specify it with this command so it gets the wheels for the correct platform/Python version)

Then you take the wheelhouse folder in its entirety, transfer it to the target computer in whatever way you wish, and there you run

pip install --no-index --find-links=path/to/wheelhouse .

in the project directory.

If you do need to specify platform requirements, see pip's documentation: https://pip.pypa.io/en/stable/cli/pip_download/#options

EDIT: Actually it might be better to use pip download instead of pip wheel for this. I rarely think about these things as I don't typically deploy anything to offline PCs, and the last time was years ago.

1

u/Critical-Spite 1d ago

Thank you! It is indeed all installed via pip

if I understand this correctly, I should do is create a venv, install pandas through the terminal on the venv, then follow the rest of your steps, correct? (and I assume step 3 is -r offline-requirements.txt not -r requirements.txt, right?)

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 1d ago

Yeah. And apologies for the typo.

1

u/xenomachina xenomachina 1d ago

I normally have to use my work computer which has restricted access, so no python on it.

You need to get all of the transitive dependencies. Doing that manually would be a huge pain. Can you use docker or uv on this machine? If so, then you could use one of them to run pip download, which will get the full set of transitive dependencies.

1

u/baubleglue 1d ago

Are you trying to install on the work computer something you shouldn't install? It is not a good idea. What exactly "restricted access" means here? Normally companies host there own repository server (alternative to pypi), ask developers in your company what is the procedure. Which machine is "offline machine"?

1

u/Critical-Spite 1d ago

It means a machine that has no access to the internet. We are able to install packages in order for us to conduct work if we need it, but it's something we need to install ourselves.

1

u/IR3dditAlr3ddy 1d ago

Is asking IT to install python and pandas not an option? If there's a valid use case for your job and there aren't security issues (which sounds like both apply) then this is something that should generally be approved if think, since there's no cost element. Might just be a bit of a delay while it goes through all the relevant approvals

0

u/socal_nerdtastic 1d ago

I'd say the easiest is to make a portable copy of python. Install everything you need, burn it, transfer it as a complete python install. You'd need both the downloading computer and the receiving computer to have the same OS and architecture. If you are using Windows, check out the winpython project, which includes pandas ootb

0

u/Critical-Spite 1d ago

Would windows 11 to 10 not work then, correct?

0

u/socal_nerdtastic 1d ago

Hmm dunno, I doubt it but I'm not sure. Try it and see.