0

I recently completed a school project in Python, and I used some non-included libraries like numpy and nltk.

The problem is I am required to demo the projects on school computers (not my own laptop) and the school computers run Python but don't allow me to install any additional packages (so no pip install numpy)

Is there any way I can include these libraries on my USB and help Python find them so my program can still run?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

0

You can do this by downloading to folders and setting the PYTHONPATH before executing.

https://docs.python.org/2/using/cmdline.html#envvar-PYTHONPATH

Also, to get the dependencies on there in a convenient manner (other than copying files etc.), you can give pip install options to specify a prefix while installing. See Install a Python package into a different directory using pip? for more details on this.

Community
  • 1
  • 1
Will Hogan
  • 909
  • 4
  • 9
  • 1
    This will only work if the OP uses a machine with the same architecture as his school computer. Numpy has C code in it that generates an architecture-specific shared object library. I'm not sure about NLTK but I wouldn't be surprised if it had some too... it's common to include Python C extensions in mathematical processing libraries in order to improve performance. –  Oct 18 '15 at 00:55
  • Yes, good point. If the architectures don't match then it would be down to setup.py with some prefix setting, probably requiring a bit of scripting. I'm also not sure how well it would work at all on a Windows machine. – Will Hogan Oct 18 '15 at 01:00
  • I don't think I have access to `PYTHONPATH`. I'm programming in Windows but the school computer uses CentOS – CodyBugstein Oct 18 '15 at 01:09
  • `PYTHONPATH` would be set at runtime, but the difference in architecture renders this somewhat moot as @Mike pointed out since there are native dependencies. If they let you use a virtualenv. You could then `pip freeze` and make a requirements file and then `pip install -r requirements.txt` in the virtualenv. You could also make a `setuptools` based project but both of those options don't really fit into the "copy and run" model as some installation is still required, even though it would be isolated (not system-wide). A Docker container would be best if supported (fairly unlikely). – Will Hogan Oct 18 '15 at 01:25