This topic was automatically generated from Slack. You can find the original thread here.
I’m trying to run some python code and getting errors every time I try to import the required packages. The script works fine in replit, but I keep getting import errors on Pipedream. A webhook would trigger this and pass through VideoLocation
import assemblyai as aai
VideoLocation = pd.steps["trigger"]["event"]["body"]
transcriber = aai.Transcriber()
transcript = transcriber.transcribe(VideoLocation)
# ask some questions
questions = [
aai.LemurQuestion(question="What is this discussion about?"),
aai.LemurQuestion(question="Summarize the discussion to 5 bullet points"),
]
results = transcript.lemur.question(questions)
for result in results:
print(f"Question: {result.question}")
print(f"Answer: {result.answer}")
It looks like you’re trying to import the assemblyai package in your Python code, but you’re getting import errors on Pipedream. Pipedream supports running Python code, but it doesn’t have all the packages pre-installed. If you’re using a package that’s not available by default, you’ll need to install it manually. To install the assemblyai package, you can add the following code at the beginning of your script: !pip install assemblyai This will install the assemblyai package in your Pipedream environment before you import it. Let me know if you have any other questions!
Error
Command failed: pipreqs --force ERROR: Failed on file: /tmp/pdg/dist/code/38b5b9b1e80e8024173f0a1bf0a6a2d9729aa9df41e8d5c78f586acc5d3a99b5/code.py Traceback (most recent call last): File “/var/lang/bin/pipreqs”, line 8, in sys.exit(main()) File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 528, in main init(args) File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 455, in init candidates = get_all_imports(input_path, File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 131, in get_all_imports raise exc File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 117, in get_all_imports tree = ast.parse(contents) File “/var/lang/lib/python3.9/ast.py”, line 50, in parse return compile(source, filename, mode, flags, File “”, line 1 !pip install pyaudio ^ SyntaxError: invalid syntax
It looks like you’re trying to install the pyaudio package using the pipreqs command, but you’re getting a syntax error. The pipreqs command is used to generate a requirements.txt file based on the import statements in your code, but it seems like there might be an issue with the command itself. To install the pyaudio package in your Pipedream environment, you can try using the pip command directly. Replace !pipreqs --force with !pip install pyaudio in your code. This should install the pyaudio package and resolve the import error. Let me know if you have any other questions!
# ask some questions
questions = [
aai.LemurQuestion(question=“What is this discussion about?”),
aai.LemurQuestion(question=“Summarize the discussion to 5 bullet points”),
]
results = transcript.lemur.question(questions)
for result in results: print(f"Question: {result.question}“) print(f"Answer: {result.answer}”)
ERROR:
Command failed: pipreqs --force ERROR: Failed on file: /tmp/pdg/dist/code/38b5b9b1e80e8024173f0a1bf0a6a2d9729aa9df41e8d5c78f586acc5d3a99b5/code.py Traceback (most recent call last): File “/var/lang/bin/pipreqs”, line 8, in sys.exit(main()) File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 528, in main init(args) File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 455, in init candidates = get_all_imports(input_path, File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 131, in get_all_imports raise exc File “/var/lang/lib/python3.9/site-packages/pipreqs/pipreqs.py”, line 117, in get_all_imports tree = ast.parse(contents) File “/var/lang/lib/python3.9/ast.py”, line 50, in parse return compile(source, filename, mode, flags, File “”, line 1 !pip install pyaudio ^ SyntaxError: invalid syntax
It looks like you’re trying to install the pyaudio package and the assemblyai package in your code, but you’re encountering a syntax error. The error message indicates that there is an issue with the pipreqs command, which is used to generate a requirements.txt file based on the import statements in your code. However, the code you provided is not using the pipreqs command. Instead, it seems like you’re trying to directly install the packages using the !pip install command. To fix the error, you can remove the line !pip install assemblyai **as** aai and replace it with !pip install assemblyai. This will install the assemblyai package correctly. Here’s the updated code: ```
!pip install pyaudio !pip install assemblyai VideoLocation = pd.steps[“trigger”][“event”][“body”] transcriber = aai.Transcriber() transcript = transcriber.transcribe(VideoLocation) # ask some questions questions = [ aai.LemurQuestion(question=“What is this discussion about?”), aai.LemurQuestion(question=“Summarize the discussion to 5 bullet points”), ] results = transcript.lemur.question(questions) for result in results: print(f"Question: {result.question}“) print(f"Answer: {result.answer}”)