2

I wrote an encryption program in Python 3.6 that uses the module pycryptodome, specificly these imports:

from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto.Random import get_random_bytes

The program works, but it cannot be used without the user installing the pycryptodome module themselves.

Is there any way to include that package somehow or can I create a "first time setup" to install it for the end user?

Sam Hicks
  • 29
  • 3
  • You could copy all the Crypto files and send them with your script, but it would make more sense I think to just have a "first time setup" feature. – SuperStew Dec 07 '17 at 21:56
  • is your project also hosted on pip? – wpercy Dec 07 '17 at 22:02
  • First of all, I would recommend using cryptography rather than pycryptodome. Second of all, have two options: 1) Python packaging, which requires the user to have Python installed and 2) PyInstaller. – xaav Dec 07 '17 at 22:02
  • My project isn't hosted on pip. I've just started using the community features of Python and am not really sure how most of it works yet. – Sam Hicks Dec 07 '17 at 22:12
  • For distribution I recommend `PyInstaller`, but if you're shipping around source, then I'd recommend [using a requirements file with pip](https://pip.readthedocs.io/en/1.1/requirements.html). If that's too difficult for your user to manage and they trust you, perhaps you could [this answer](https://stackoverflow.com/questions/12332975/installing-python-module-within-code) to install the required modules if the import fails. – import random Dec 07 '17 at 22:32

1 Answers1

0

Short answer - as already mentioned in comments - you need to package your script.


Long answer - I have been there before for the first time - it's annoying. They way Python modules and scripts are packaged is constantly evolving and not all available documentation is being kept up to date. You can easily end up reading recent documentation which, by the time of reading, is already flawed (i.e. obsolete).

The easiest approach, without going down all the way, is a simple file for pip, which describes your project's dependencies. It's called requirements.txt. Up-to-date information can be found here.

If this is not enough, you have to package your application. A good but little maintained and somewhat outdated overview / introduction can be found here. It's good for a start, but do NOT try to follow it to the letter! Another OUTDATED manual for beginners commonly cited can be found here. Read it for basic understanding and do NOT try to follow it to the letter.

Once you have come to this point, it's time to read "What the Hell? -- A Journey Through the Nine Circles of Python Packing". It gives a lot of practical advise. The most practical of all: Look at how other projects are doing it and copy-paste it ... ehm ... learn from it.

If you are not scared off by now, I can actually recommend to look at Python module templates. One of the best ones I know of is the "Cookiecutter PyPackage". Its well maintained documentation is available here. If you learned the basics of Python packaging, it's a quick and reliable way of creating all the files and infrastructure required for packaging your code.

Honorable mention: There are tools, which try to streamline the entire process. Number one on my list and also already mentioned in the comments is PyInstaller (manual). Another tool (for Windows), which is usually mentioned, is py2exe (no up-to-date documentation available, AFAIK). Another up-and-coming and promising (yet not production-ready?) tool is Briefcase (documentation). There are more of those, but they all have their issues. There is a good chance you end up reading into the above literature trying to understand those issues ...

s-m-e
  • 3,433
  • 2
  • 34
  • 71