Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.3.0 needs pyaudio but doesn't specify it as a dependency #418

Closed
Tenzer opened this issue Jun 13, 2024 · 8 comments · Fixed by #419
Closed

v3.3.0 needs pyaudio but doesn't specify it as a dependency #418

Tenzer opened this issue Jun 13, 2024 · 8 comments · Fixed by #419

Comments

@Tenzer
Copy link
Contributor

Tenzer commented Jun 13, 2024

What is the current behavior?

Installing v3.3.0 of this library and trying to import deepgram gives a stack trace because deepgram-sdk depends on pyaudio, but it isn't installed as a dependency.

Steps to reproduce

  1. Create an empty virtual environment: python3 -m venv venv
  2. Install deepgram-sdk v3.3.0 in the virtual environment: venv/bin/pip install deepgram-sdk==3.3.0
  3. Try to import the library: venv/bin/python -c 'import deepgram'

It gives a stack trace like this:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/your/path/venv/lib/python3.12/site-packages/deepgram/__init__.py", line 129, in <module>
    from .audio import Microphone
  File "/your/path/venv/lib/python3.12/site-packages/deepgram/audio/__init__.py", line 5, in <module>
    from .microphone import Microphone
  File "/your/path/venv/lib/python3.12/site-packages/deepgram/audio/microphone/__init__.py", line 5, in <module>
    from .microphone import Microphone
  File "/your/path/venv/lib/python3.12/site-packages/deepgram/audio/microphone/microphone.py", line 15, in <module>
    class Microphone:  # pylint: disable=too-many-instance-attributes
  File "/your/path/venv/lib/python3.12/site-packages/deepgram/audio/microphone/microphone.py", line 23, in Microphone
    import pyaudio  # pylint: disable=import-outside-toplevel
    ^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'pyaudio'

Expected behavior

It should be possible to install the library and import it without having to install extra dependencies manually.

Please tell us about your environment

This happens regardless of operating system. I have only tested on Python 3.12.

Other information

@dvonthenen
Copy link
Contributor

dvonthenen commented Jun 13, 2024

That's actually a 100% intentional.

Please see:
#302

In case that issue isn't clear, on certain platforms, the pip install deepgram-sdk will fail if portaudio isn't installed. That would force people with a hard requirement to install portaudio just to use the SDK when they might not be interested in any of the examples that use it.

All the examples that use the Microphone have documentation in the README.md to install (like brew install portaudio or whatever it is for your platform) before running.

@Tenzer
Copy link
Contributor Author

Tenzer commented Jun 13, 2024

This wasn't a problem in version 3.2.7 which is why I am reporting it.

The problem seems to stem from the import which is done at the class-level here:

import pyaudio # pylint: disable=import-outside-toplevel

It attempts to import pyaudio as soon as the Microphone class is parsed by Python, which is done as soon as import deepgram is done.

Since that import is only used for type checking, it can instead be put in a conditional, so this isn't a problem. I'll make a PR in a moment to demonstrate.

@dvonthenen
Copy link
Contributor

dvonthenen commented Jun 13, 2024

ooooh you are reportng that it is giving you the error. now I see what you are saying. If you want to do the PR to remove the line, that would be awesome. Otherwise, I can.

@Tenzer
Copy link
Contributor Author

Tenzer commented Jun 13, 2024

Yep, exactly. See #419.

@dvonthenen
Copy link
Contributor

I think TYPE_CHECKING was introduced a little later in v3. I will need to see if this works for the supported versions of of the SDK.

@dvonthenen
Copy link
Contributor

dvonthenen commented Jun 13, 2024

@Tenzer would you happen to know if this works for 3.10? and I have been working on a side project on getting the SDK to work on 3.9 (because some have been complaining about this) but I haven't been able to devote a ton of time to it.

@Tenzer
Copy link
Contributor Author

Tenzer commented Jun 13, 2024

As mentioned here, typing.TYPING_CHECKING was added in Python 3.5.2 according to the documentation, so I don't see why it shouldn't work.

@dvonthenen
Copy link
Contributor

@Tenzer thanks again for the PR. just posted a new release with this fix:
https://github.com/deepgram/deepgram-python-sdk/releases/tag/v3.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants