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

'NoneType' object has no attribute 'group' in jupyter_translate.py #6

Closed
FernandoCarazoMelo opened this issue Aug 13, 2023 · 2 comments

Comments

@FernandoCarazoMelo
Copy link

Description:

Issue Summary:

When running the testpython jupyter_translate.py 01_intro.ipynb --language 'pt' command with the provided script jupyter_translate.py, I encountered an AttributeError: 'NoneType' object has no attribute 'group' error. The error occurs in the context of using regular expressions and the group attribute, but I'm having difficulty pinpointing the exact source of the issue.

Steps to Reproduce:

  1. Run the following command in the terminal:
    testpython jupyter_translate.py 01_intro.ipynb --language 'pt'
    

Expected Behavior:

I expected the script to execute without errors and successfully translate the Jupyter Notebook content into the specified language.

Actual Behavior:

The script encountered an AttributeError: 'NoneType' object has no attribute 'group' error during execution.

Error Stack Trace:

Traceback (most recent call last):
  File "jupyter_translate.py", line XXX, in jupyter_translate
    ...
    result = match.group()
AttributeError: 'NoneType' object has no attribute 'group'

Code Snippet:

Here's the relevant portion of the code where the error occurs:

# ... (other code)
# Inside jupyter_translate function

# ...
if cell['cell_type'] == 'markdown':
    if source[:3] == '```':
        skip_row = not skip_row  # Invert flag until I find next code block

    if not skip_row:
        if source not in ['```\n', '```', '\n'] and source[:4] != '<img':
            # The following line is where the error occurs
            data_translated['cells'][i]['source'][j] = translate_markdown(source, dest_language=language)
# ... (other code)

Additional Information:

  • Python version: 3.9.16
  • Operating System: mac
@JeremiasBaez
Copy link

Hi,

Testing this tool i ran into the same issue as you in Python 3.11.4.

Then, at the bottom of the documentation it indicates that to set it up to work in the conda environment, you need to install a specific version of the googletranslate package. So i modified the requirements.txt file to have the package version to match the one in environment.yml

requirements.txt

fire
googletrans==3.1.0a0

After that, just install the new requirements.

pip install -r requirements.txt

Should install the specific version of the googletrans package, and in my case, that solved the issue.

@andrebelem
Copy link
Collaborator

We are now using deep-translator as main interface. It should work now. Please, report in a new PR.

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

3 participants