0

I'm writing a program that uses some cryptography for a class. Since I'm low on time, I'd like to go with Python for this assignment. The issue that I run into is that the code must be able to work on the Linux machines at the school. We are able to SSH into those machines and run the code, but we aren't allowed to install anything. I'm using the Cryptography library for Python:

pip install cryptography

Is there a straightforward way that I can include this with my .py file such that the issue of not being able to install the library on the Linux machines won't be a problem?

Shoggoth269
  • 167
  • 1
  • 9
  • 1
    Do the systems come installed with virtualenv? The general practice is to use virtual environments and install python dependencies within that rather than making a system wide install. If not [this](http://stackoverflow.com/a/9349150/1068887) might help. – adarsh Feb 18 '16 at 01:04
  • Is there any clear assignment specification? Maybe custom software installs are not officially allowed. – CristiFati Feb 18 '16 at 02:22
  • We're able to grab the encryption/decryption from online for this assignment. Unfortunately it doesn't appear that we have virtualenv available, so I'll see how that workaround goes. – Shoggoth269 Feb 18 '16 at 06:04
  • @Shoggoth269 I would recommend you to install `tox` or `virtualenv` using `$ pip install --user` and then work only within virtualenvs. – Jan Vlcinsky Feb 18 '16 at 09:43

1 Answers1

0

You have few options:

virtualenv

Install into virtualenv (assuming command virtualenv is installed):

$ cd projectdir
$ virtualenv venv
$ source venv/bin/activate
(venv)$ pip install cryptography
(venv)$ vim mycode.py
(venv)$ python mycode.py

The trick is, you install into local virtual environment, which does not requires root priviledges.

tox

tox is great tool. After investing a bit of time, you can easily create multiple virtualenvs.

It assumes, you have tox installed in your system.

$ tox-quickstart
$ ...accept all defaults
$ vim tox.ini

The tox.ini my look like:

[tox]
envlist = py27
skipsdist = true

[testenv]
commands = python --version
deps =
    cryptography

then run (with virtualenvs being deactivated):

$ tox

it will create virtualenv in directory .tox/py27

Activate it (still being in the same dir):

$ source .tox/py27/bin/activate
(py27)$ pip freeze
cryptography==1.2.2
... and few more...

Install into --user python profile

While this allows installing without root priviledges, it is not recommended as it soon ends in one big mess.

EDIT (reaction to MattDMo comment):

If one user has two project with conflicting requirements (e.g. different package versions), --user installation will not work as the packages are living in one scope shared across all user projects.

With virtualenvs you may keep virtualenv inside of project folders and feel free to destroy and recreate or modify any of them without affecting any other project.

Virtualenvs have no problem with "piling up": if you can find your project folder, you shall be able to find and manage related virtualenv(s) in it.

Use of virtualenv became de-facto recommended standard. I remember numerous examples starting with creating virtualenv, but I cannot remember one case using $ pip install --user.

Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
  • How is having a bunch of virtualenvs for different projects piling up any different than installing with `--user`? I'm sorry, but you're going to have to find some significant support for your final claim, as it's simply not true. User installs can be managed just as easily as system installs or multiple virtualenvs. – MattDMo Feb 18 '16 at 02:09
  • 1
    @MattDMo If one user has two project with conflicting requirements (e.g. different package versions), `--user` installation will not work. With virtualenvs you may keep virtualenv inside of project folders and feel free to destroy and recreate or modify any of them without affecting any other project. This does not holds true for `--user` based installs. Virtualenvs have no problem with "piling up": if you can find your project folder, you shall be able to find and manage related virtualenv(s) in it. Very simple. – Jan Vlcinsky Feb 18 '16 at 09:22