4

I have a simple python shell script (no gui) who uses a couple of dependencies (requests and BeautifulfSoup4).

I would like to share this simple script over multiple computers. Each computer has already python installed and they are all Linux powered.

At this moment, on my development environments, the application runs inside a virtualenv with all its dependencies.

Is there any way to share this application with all the dependencies without the needing of installing them with pip? I would like to just run python myapp.py to run it.

philshem
  • 24,761
  • 8
  • 61
  • 127
gaggina
  • 5,369
  • 10
  • 31
  • 31
  • 3
    What are your reasons to not use pip? Because that would seem to be an obvious solution. – Mark van Lent Nov 11 '13 at 16:26
  • Because I cant install it on some computers.. – gaggina Dec 08 '13 at 14:37
  • Have you resolved this issue? I also cannot install anything on the system, but I can ship my script with all necessary binaries and drop it in a directory and execute. Hard to believe people's never encountered such need. Everyone seems to just install all stuff on their servers... – Simon Apr 19 '15 at 21:04
  • Did you fix this issue. I am on a similar circumstance to be solved. Please share – Tara Prasad Gurung May 16 '17 at 07:50

3 Answers3

1

You will need to either create a single-file executable, using something like bbfreeze or pyinstaller or bundle your dependencies (assuming they're pure-python) into a .zip file and then source it as your PYTHONPATH (ex: PYTHONPATH=deps.zip python myapp.py).

The much better solution would be to create a setup.py file and use pip. Your setup.py file can create dependency links to files or repos if you don't want those machines to have access to the outside world. See this related issue.

Community
  • 1
  • 1
TkTech
  • 4,729
  • 1
  • 24
  • 32
0

As long as you make the virtualenv relocatable (use the --relocatable option on it in its original place), you can literally just copy the whole virtualenv over. If you create it with --copy-only (you'll need to patch the bug in virtualenv), then you shouldn't even need to have python installed elsewhere on the target machines.

Alternatively, look at http://guide.python-distribute.org/ and learn how to create an egg or wheel. An egg can then be run directly by python.

Marcin
  • 48,559
  • 18
  • 128
  • 201
  • 1
    link doesn't work anymore. What about some C-based dependencies. How can I include them in the system? I don't want the target system to install all stuff system-wide. I want to ship all necessary binaries with the package... something like JAR file in JAVA world... all stuff should be there purely python and external stuff too. – Simon Apr 19 '15 at 21:07
-1

I haven't tested your particular case, but you can find source code (either mirrored or original) on a site like github.

For example, for BeautifulSoup, you can find the code here.

You can put the code into the same folder (probably a rename is a good idea, so as to not call an existing package). Just note that you won't get any updates.

philshem
  • 24,761
  • 8
  • 61
  • 127