0

I need to make a .whl file of a package and it will be installed in a isolated environment which cannot connect to Internet.

In this package, it will use some third party libraries for example black and pydantic. I know that in setup.py we can set "required" packages, but this method will work only if the environment can connect to Internet.

Currently I use a workaround. This is my directory structure.

└── src
    └── my_package

I download the required packages and add them to my source code before packing them into a whl file.

pip install --target=lib -r requirements.txt
cp -r lib/* src

So the directory structure will be like below

└── src
    ├── my_package
    ├── black
    └── pydantic

In my setup.py, I set

package_dir={
        "": "src",
    },

So that after I pip install this whl file, my_package, black, pydantic will appear in python site-packages directory.

However, with this method, console script of third party libraries like black test.py cannot work since there is no console script under the (virtualenv path)/bin directory. Is there a more elegant way to merge third party libraries into my whl file?

Regards,

phd
  • 82,685
  • 13
  • 120
  • 165
YYLIZH
  • 26
  • 3
  • 2
    This seems like a bad idea. Instead, why not download all the wheels you need (including black, pydantic, etc.) in advance and transfer them to the target machine? This is called building a "wheelhouse", it is a common practice. – sinoroc Nov 10 '22 at 10:01
  • Thank you very much. Since I don't know how others usually do to deal with this problem, this is the only approach I came up with. I will try with the wheelhouse approach. – YYLIZH Nov 10 '22 at 10:29
  • 1
    Does this answer your question? [How to install packages offline?](https://stackoverflow.com/questions/11091623/how-to-install-packages-offline) – phd Nov 10 '22 at 10:45
  • https://stackoverflow.com/search?q=%5Bpip%5D+offline – phd Nov 10 '22 at 10:45
  • @phd Yes. Thank you. I think "pip download" or "pip wheels" may solve my problem. – YYLIZH Nov 10 '22 at 10:57

0 Answers0