ImportError: cannot import name 'MailMerge' from 'mailmerge'

7.7k Views Asked by At

I am having this problem whereby I can not copy

from __future__ import print_function
from mailmerge import MailMerge
from datetime import date

I am getting

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-6791e9480127> in <module>
      1 from __future__ import print_function
----> 2 from mailmerge import MailMerge
      3 from datetime import date

ImportError: cannot import name 'MailMerge' from 'mailmerge' (C:\Users\username\AppData\Roaming\Python\Python37\site-packages\mailmerge\__init__.py)
2

There are 2 best solutions below

0
On BEST ANSWER

Jupyter Notebook

  1. Open Anaconda Prompt and press 'conda install lxml'

  2. You should get that "The following packages will be UPDATED:" press 'y'

  3. In your jupyter notebook write !pip install docx-mailmerge

  4. Then you can simply write this:

    from future import print_function

    from mailmerge import MailMerge

    from datetime import date

  5. That is all, it should work

I learned this from this webpage

This had solved my problem.

2
On

The solution, assuming you want to use the newer version, is to uninstall the mailmerge package and install docx-mailmerge,like this:

$ pip uninstall mailmerge
$ pip install docx-mailmerge

after that you can import like

from mailmerge import MailMerge

You can see similar issue on GitHub and docs for docx-mailmerge