Hey guys, can someone please point me in the direc...
# ask-community
j
Hey guys, can someone please point me in the direction of importing user-created functions from other python files? We have a large library of common functions that are used in almost every script, I'm developing a use-case for using Prefect over VisualCron but I'm running into some issues here
k
I assume this works when running on local but gives an error when running elsewhere?
j
yessir, we use sys.path.appends like so:
Copy code
sys.path.append('D:\\_Common\\python')
from fnLibrary import fnODBConnect, setLogging
k
I think the best practice here is to package that library with the common tools and include that in a Docker image. If you package it as a wheel, you can pip install it. and then import
fnLibrary
j
I have used celery automation with these type of imports in the past, but perhaps due to running Prefect Cloud, I need to pass in the imported module metadata somehow.
k
What storage and run config are you using for Prefect?
The local run works because it sees those files on the local machine, but you need the agent to be able to see the files as well when it runs it.
j
Right now, I'm using the Prefect python package on a Windows Server 2019 VM. Believe me, I would much rather use the docker image, but at present our scripts are run from python venvs (trust me, this is alarming). I did manage to hackathon my way into using Docker in process-isolation mode, as enabling nested virtualization is too risky for the financial market work until I'm able to bug test it as much as possible
and at present, we're only able to run docker in windows containers (missing out on 80% of the powerful docker images built in linux containers). This is due to WSL2 not being supported and/or broken in WS2019 at the moment 😕
I'll look into the docker storage docs and try to get something going using Windows containers though
k
Are the flows that will be orchestrated by Prefect going to run on the same Windows Server 2019 VM?
j
yes, and everything that those flows need to run (environment, filepaths for output, imported modules) are all located on the same drive within that VM
k
To circumvent Docker, you can package that library and install it wherever your flows will be running. There are just a couple of stuff to keep track of (making sure the latest version is installed). Versioning that set of helper scripts inside the module would probably be the way to go.
j
well I'll be damned, this worked BEAUTIFULLY Kevin!! Thank you so much!
k
Didn’t do much here. Happy you figured it out! 🙂
🙌 1