Python Module Installations #6
Replies: 3 comments 2 replies
-
Would be interested in adding a simple “parse generated code, determine whether packages are installed in current venv, generate install command, run install command, run code” preprocessing step. Would have to be an effective no-op if packages are installed though. Will probably have to be heuristic on individual package versions too (can’t be inferred from import statement). |
Beta Was this translation helpful? Give feedback.
-
import ast
import stdlib_list
def get_imports(path):
with open(path) as f:
root = ast.parse(f.read(), path)
for node in ast.iter_child_nodes(root):
if isinstance(node, ast.Import):
module = []
for n in node.names:
module.append(n.name.split('.')[0])
yield module
elif isinstance(node, ast.ImportFrom):
yield [node.module.split('.')[0]]
def generate_pip_install(file_path):
stdlib_modules = stdlib_list.stdlib_list()
imports = list(get_imports(file_path))
non_stdlib_modules = {module for sublist in imports for module in sublist if module not in stdlib_modules}
if non_stdlib_modules:
print("pip install " + " ".join(non_stdlib_modules))
else:
print("No non-system package imports found.")
generate_pip_install("your_file.py") As per GPT-4 👆 |
Beta Was this translation helpful? Give feedback.
-
See #73 for an attempt to dealing with this. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm excited to check out the new gpt-code-ui repository! I've been playing around with it for a bit, and it's really cool. However, I've noticed that it doesn't automatically install the Python modules that are needed to run the code that is generated by OpenAI's API. This can be a bit of a pain, as I have to manually install the modules before I can run the code.
I tried creating a simple scraping code and it doesn't even have access to a module as simple as pandas, so it does generate the code for me, but execution is still not at its best.
I was wondering if it would be possible to add a feature to automatically install the Python modules that are needed to run the code. This would make it much easier to use the gpt-code-ui repository, and it would allow people to get started with it more quickly.
Thanks for your time!
I hope this helps!
Beta Was this translation helpful? Give feedback.
All reactions