Python - Distributing a Source Code Library

I am writing a program using cryptography for a class. Since I don't have much time, I would like to go with Python for this assignment. The problem I am facing is that the code must work on Linux machines in school. We can use SSH on these machines and run the code, but we are not allowed to install anything. I use the cryptography library for Python:

pip install cryptography 

Is there an easy way to include this in my .py file, so the problem of not being able to install the library on Linux machines will not be a problem?

0
source share
1 answer

You have several options:

virtualenv

Install in virtualenv (assuming the virtualenv command 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 that you install in a local virtual environment that does not require root privileges.

toxicodendron

tox is a great tool. After a little investment, you can easily create several virtualenvs.

It is assumed that tox installed on your system.

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

It seems to me that tox.ini looks like this:

 [tox] envlist = py27 skipsdist = true [testenv] commands = python --version deps = cryptography 

then execute (with disabling virtualenvs):

 $ tox 

it will create virtualenv in the .tox/py27

Activate it (still in the same directory):

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

Install -ser python in profile

Although it allows you to install without root privileges, it is not recommended that it ends soon with one big mess.

EDIT (reaction to MattDMo's comment):

If one user has two projects with conflicting requirements (for example, different versions of the package), installing --user will not work, because packages living in the same area are divided in all user projects.

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

Virtualenvs has no "accumulation" problems: if you can find your project folder, you can find and manage the virtual virtual machines associated with it.

Using virtualenv has become the de facto recommended standard. I remember numerous examples starting with the creation of virtualenv, but I cannot recall one case using $ pip install --user .

0
source

Source: https://habr.com/ru/post/1245343/


All Articles