Python and packages

Hey, I have a question about Python and Packages:

let’s suppose I create a Python program that includes one or more external packages (not included within Python, like random) and I share it with another person which has not these packages installed. What will happen? Will not the program run? If so, how I can automatically install this packaging on their machine? Or would be better to change my Python file into a .exe or mac app compatible? :thinking:

Thanks!

You can’t install Python libraries on someone else’s machine. They need to install them.
What context are you talking about? Sharing a .ipynb file? Jupyter Notebook or Colab?
The easiest way to share a notebook is with Google Colab. It’s cloud-based and based on Jupyter. It’s an app that one adds to their Google Drive. Most libraries are installed in it. If not, then pip install is required.

2 Likes

Assuming you’re sharing with someone who can install Python and additional modules…

I quite like @lisalisaj’s options for sharing things online. This may be easier than trying to ensure requirements are met yourself as the online solutions often have the requirements in place.

In more general terms for Python programs requiring some libraries (e.g. from PyPA): If you haven’t already you’d want to look into virtual environments for Python due to dependency issues. Because libraries and packages change so often you’d want to make sure whoever you shared your code with has the same versions. See for example-

There are a few routes to then ensuring the correct dependencies are listed in what you share, e.g. freezing requirements files, yaml, Pipfile etc. The following link seems to cover a few of the better known options and then how to install packages (on the receiver end for example) using those requirements files:

If you’re trying to share your program with someone who does not have access to Python or the permission to install packages then it is much more difficult; you’d best have a web search for some useful information. There are tools to squeeze python programs into binaries you could pass on with external storage devices e.g. pyinstaller, py2exe (and others) but they have some drawbacks e.g. file size and compatibility.

2 Likes

Was more a general question, in case I want to share some project(s) with other people :slight_smile:

thanks for the hint!

Look into Colab. The documentation is thorough and I think it’s easy to use. You can push notebooks to your GitHub repo as well. It’s great for sharing.

This is helpful too.

1 Like