2

I have a Python 2.7 script that uses BeautifulSoup4 and requests modules.

The issue is, that I need to deploy this script on a machine to which we can not directly install any new modules/libaries via pip install or anything else. We can copy this script and any files it needs to run to that machine, but we can not directly install any modules.

I have tried PyInstaller, PEX and Nuitka to create an executable file or a bundle (in any format, for example .zip) so that we can copy the entire file or bundle into the machine and run the python script from there, without the need to do pip install or installing the modules manually via Wheel file. All without success.

Environment details: Target machine on which the script needs to run: RHEL-based Linux OS with Python 2.7. My development machine: Windows 10 but I also have access to Fedora Linux machine both with Python 3 and Python 2.7.

The import section of my script looks like this:

from __future__ import with_statement from __future__ import absolute_import import requests import re from bs4 import BeautifulSoup from io import open

Can someone, please, help me out here? We have the script ready to be deployed, but we are not able to run it in our target machine because of the missing modules/libraries.

Thank you very much

EDIT: Mentioning this since it may not be clear at first - we do not have the issue with a network connection or anything of this gender. We were prohibited to use pip install or a manual method of installing a module. Therefore, we can only bundle the modules directly with the script or something so that would not need to directly install the modules on the target machine itself.

7
  • 1
    your issues with installing from pip are because there is no network? you can download packages from PyPi and install them with pip locally on the other machine (just make sure you download all the requirements)
    – Ofer Sadan
    Commented Oct 24, 2019 at 9:24
  • 1
    Hello Ofer Sadan, the issue is not with installing it via network, but that we can not install any Python modules because the vendor of that machine prohibited us from it because when there will be an upgrade, it could break the Python installation - and that could then void our warranty (that was his reason). So, the issue in general is, that we can not directly install any modules/libraries nor via pip install nor manually. So they need to be included directly with the script or in a script directory or something. Thank you
    – rogaloo
    Commented Oct 24, 2019 at 9:31
  • 1
    are you allowed to create an isolated virtual environment and install packages there? there's no reason why that would ever mess with the original python installation folder.
    – Ofer Sadan
    Commented Oct 24, 2019 at 9:34
  • Well, the vendor said that we can not install any modules and that includes the pip install virtualenv module. So we can not use virtual environment neither. Thank you
    – rogaloo
    Commented Oct 24, 2019 at 9:38
  • you can manually copy all related packages to a folder of your own, and just add that folder to sys.path at the top of your code before importing
    – Ofer Sadan
    Commented Oct 24, 2019 at 9:40

0

Your Answer

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

Browse other questions tagged or ask your own question.