dynamically load a Python package #577
-
I'm trying to run a program that lets me input and execute Python code, but when I add a package that's not in the requirements, it crashes. My question is: can I add this package while the program is running? |
Beta Was this translation helpful? Give feedback.
Answered by
tonybaloney
Jul 9, 2025
Replies: 1 comment 1 reply
-
Yes, this is possible today. See https://tonybaloney.github.io/CSnakes/environments/#installing-packages-at-runtime examples)
.WithPython()
.WithVirtualEnvironment(Path.Join(home, ".venv"))
.WithPipInstaller(); // Optional - installs packages listed in requirements.txt on startup
// Environment/host builder setup
var installer = serviceProvider.GetRequiredService<IPythonPackageInstaller>();
await installer.InstallPackage("attrs==25.3.0"); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tonybaloney
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, this is possible today. See
https://tonybaloney.github.io/CSnakes/environments/#installing-packages-at-runtime