1

For a project, I can't let users use pip install before running the app.

My project is a python flask app that I used pip to grab the dependencies. How do I bundle it so the apps can run without using pip install?

davidism
  • 121,510
  • 29
  • 395
  • 339
mding5692
  • 806
  • 1
  • 10
  • 34
  • 1
    Why not? Who are the users? In general it would either be: 1. end users of the web app who don't need to know about Flask at all; or 2. developers who would be perfectly comfortable with installing the dependencies. – jonrsharpe Dec 04 '16 at 21:21
  • I'm doing this as a school project (all the code has been filled out) but have been stumped because my prof requested that I can't let people use pip install and haven't been able to google a relevant answer – mding5692 Dec 04 '16 at 21:23
  • *What* "people"? It's not clear what you're trying to deliver. Why don't you talk to the professor; even if they won't tell you everything, you'd at least have a clearer question to ask. – jonrsharpe Dec 04 '16 at 21:24
  • I presume the people are the TAs marking the project and thats what he replied with – mding5692 Dec 04 '16 at 21:36
  • 1
    Then I would encourage you to ask why the people marking your homework are unable to do basic development tasks. – jonrsharpe Dec 04 '16 at 21:37
  • Same here, i didn't know TAs were more incapable than the students, hopefully you're not my prof or TA – mding5692 Dec 04 '16 at 21:38
  • Possible duplicate of [Bundle python script and dependencies into a single file](https://stackoverflow.com/questions/28237312/bundle-python-script-and-dependencies-into-a-single-file) – tripleee Sep 08 '17 at 09:21

3 Answers3

0

I've done this before. I created a virtualenv for my project so all dependencies (including the python executable) are contained within the project sub-directory tree. Then just zip up that directory tree. To install elsewhere, just unzip and run it.

BareNakedCoder
  • 3,257
  • 2
  • 13
  • 16
  • 2
    Virtual environments aren't designed to be portable – jonrsharpe Dec 04 '16 at 21:24
  • Yes, not 100% portable. But is 100% portability needed in this case? In my case, we all used the same opsys and I'm guessing that might be the case for OP too. But again you are correct: if portability across different opsys is required, this ain't your solution. – BareNakedCoder Dec 04 '16 at 21:25
  • what would the exact steps be? – mding5692 Dec 04 '16 at 21:43
  • virtualenv is a ultra-core topic that every Python coder should know. Learn it even if you don't use it here. There are many tutorials on it. Here's one I found in the Google: http://docs.python-guide.org/en/latest/dev/virtualenvs/ – BareNakedCoder Dec 04 '16 at 21:46
  • Also, re-found this tutorial I read a while ago and liked. Especially the advice that pip and virtualenv are the ONLY packages you need and should install globally. All the rest, install in a virtualenv. See https://www.dabapps.com/blog/introduction-to-pip-and-virtualenv-python/ – BareNakedCoder Dec 04 '16 at 21:51
-1

I'm pretty sure python checks it's install directory for file dependencies and inside the same directory as the python file you are running. You can copy the packages from the pip install directory and place them in the same directory as your python file. It should see them.

It's pretty easy to make a bash script. Open a text editor, save it with a .sh extension. type in your commands.

This is a linux bash script:

#!/bin/bash
#This is a comment
sudo pip install -U memory_profiler
sudo pip install pympler

This is a windows batch script. Save as a .bat file

ECHO
cd [pip install directory]
pip command
pip command
Nice1013
  • 125
  • 2
  • 8
  • 1
    Is there an alternative where bash scripts or pip install is not needed? Because no offense but this seems to be the same as pip install but instead you're running a bash script – mding5692 Dec 04 '16 at 21:40
  • Yeah, but the user doesn't have to install them themselves. You could also have the script just run your start file at the end. Or l just Copy your dependencies into the same directory as your starting python file. – Nice1013 Dec 04 '16 at 21:45
  • How is running that bash script any harder than `pip install -r requirements.txt` or `python setup.py install`? – jonrsharpe Dec 04 '16 at 22:07
-1

when python runs a file, it adds the current working directory to where it will look for modules to import.

you just need to install the requirements directly into your project folder.

the easiest way to do this is:

  • create a virtualenv somewhere and do your pip install -r requirements.txt
  • copy the contents of the site-packages folder from the environment ( $VIRTUAL_ENV/lib/python2.7/site-packages note: you might have to change accordingly for python version) to your project folder.
  • distribute your project folder.

edit: to add that I remembered that you're doing something similar to packaging an AWS Lambda.

adityajones
  • 601
  • 1
  • 4
  • 10