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

Unable to run "Getting Started" snippet; "ModuleNotFoundError" and circular import error #44

Closed
kdipippo opened this issue Oct 23, 2020 · 1 comment

Comments

@kdipippo
Copy link

Python and Captcha Versions

Python version:

➜  python --version
Python 3.8.2

Captcha version

➜  python -m pip freeze
...
captcha==0.3
...

Problem Statement

After running python -m pip install captcha and then pasting the example snippet from the README into a file called captcha.py:

from captcha.audio import AudioCaptcha
from captcha.image import ImageCaptcha

audio = AudioCaptcha(voicedir='/path/to/voices')
image = ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf'])

data = audio.generate('1234')
audio.write('1234', 'out.wav')

data = image.generate('1234')
image.write('1234', 'out.png')

I get the following error when running the file:

➜  python captcha.py
Traceback (most recent call last):
  File "captcha.py", line 1, in <module>
    from captcha.audio import AudioCaptcha
  File "[redacted_full_path]/captcha.py", line 1, in <module>
    from captcha.audio import AudioCaptcha
ModuleNotFoundError: No module named 'captcha.audio'; 'captcha' is not a package

If I change the file slightly to:

import captcha

audio = captcha.audio.AudioCaptcha(voicedir='/path/to/voices')
image = captcha.image.ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf'])

I get the following error when running the file:

➜  python captcha.py
Traceback (most recent call last):
  File "captcha.py", line 1, in <module>
    import captcha
  File "[redacted_full_path]/captcha.py", line 3, in <module>
    audio = captcha.audio.AudioCaptcha(voicedir='/path/to/voices')
AttributeError: partially initialized module 'captcha' has no attribute 'audio' (most likely due to a circular import)
@andreymal
Copy link

Just rename your captcha.py file. It's basically a bad idea to have the same filename as an external module.

And actually #45 does not fix this issue, but renaming your file fixes it.

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

No branches or pull requests

2 participants