Distribute script that uses third party libraries

Hi,

In short, I am looking for a convenient way to enable others to run scripts that use third party libraries.

Below some more context:

I have a script that uses a third party library (numpy). That library sits in the site-packages folder of another Python interpreter installed on my computer, and is added to sys.path of the Python processes launched from pyRevit via the environment variable PYTHONPATH. This follows the pyRevit instructions and works all fine.

The inconvenience comes when sharing the script with others. They would have to go through the same process, and not everyone is able to do so. I’m therefore looking for ways to simplify/automate that process for others.

Below two approaches I could come up with so far:

  • Share a script that executes above commands - a downside might be the impact of the Python install and setting PYTHONPATH as environment variable on and other (Python) processes
  • Share a script that copies the required libraries from a repo to the site-packages of the pyRevit program files - not sure if the files and folders of a 3rd party library can simply be copy-pasted to the site-packages folder, as a normal install also places files outside the site-package folder

So my question: what is the best way to enable others to run scripts that use third party libraries?

2 Likes

For anyone interested, my current approach is to add the desired 3rd party libraries to a separate ‘lib’ extension:

  1. Create a ‘lib’ extension
  2. Mimic the CPython engine embedded in PyRevit by creating a Conda environment with the same Python version
  3. Activate the environment and pip install the desired 3rd party libraries to the ‘lib’ extension: pip install <packages> --target=<path to lib extension>
  4. Remove unnecessary files (e.g. __pycache__)
  5. Add the ‘lib’ extension as dependency to extensions where you want to use the 3rd party libraries

This avoids users from mimicking the CPython environment themselves, as all 3rd party library files are in the ‘lib’ extension. Not sure if I will run into issues later, but for now it seems to work.

1 Like