Unable to Update in test environment: No Module named pyPDF2

Hi,
I seem to be getting an error on my test environment on update as below, I have also tried to install

sudo apt-get install python-pypdf2

But even after that I am getting the below error on patch execution, but the error does seem like asking me to install pyPDF2 but why is it giving an error even after the installation of pyPDF2 is perplexing

aditya@aditya-notebook:~/frappe-bench$ bench --site local-rigpl migrate
Migrating local-rigpl
Executing erpnext.patches.v8_7.add_more_gst_fields in local-rigpl (rigpl)
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/aditya/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 94, in <module>
    main()
  File "/home/aditya/frappe-bench/apps/frappe/frappe/utils/bench_helper.py", line 18, in main
    click.Group(commands=commands)(prog_name='bench')
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/aditya/frappe-bench/env/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/commands/__init__.py", line 24, in _func
    ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/commands/site.py", line 217, in migrate
    migrate(context.verbose, rebuild_website=rebuild_website)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/migrate.py", line 31, in migrate
    frappe.modules.patch_handler.run_all()
  File "/home/aditya/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 29, in run_all
    if not run_single(patchmodule = patch):
  File "/home/aditya/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 63, in run_single
    return execute_patch(patchmodule, method, methodargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/modules/patch_handler.py", line 83, in execute_patch
    frappe.get_attr(patchmodule.split()[0] + ".execute")()
  File "/home/aditya/frappe-bench/apps/erpnext/erpnext/patches/v8_7/add_more_gst_fields.py", line 9, in execute
    make_custom_fields()
  File "/home/aditya/frappe-bench/apps/erpnext/erpnext/regional/india/setup.py", line 156, in make_custom_fields
    create_custom_field(doctype, df)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py", line 106, in create_custom_field
    "hidden": df.hidden or 0
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 192, in insert
    self.run_before_save_methods()
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 772, in run_before_save_methods
    self.run_method("validate")
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 666, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 887, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 870, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 660, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/custom/doctype/custom_field/custom_field.py", line 44, in validate
    check_if_fieldname_conflicts_with_methods(self.dt, self.fieldname)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/core/doctype/doctype/doctype.py", line 785, in check_if_fieldname_conflicts_with_methods
    doc = frappe.get_doc({"doctype": doctype})
  File "/home/aditya/frappe-bench/apps/frappe/frappe/__init__.py", line 621, in get_doc
    return frappe.model.document.get_doc(arg1, arg2)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/document.py", line 49, in get_doc
    controller = get_controller(doctype)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/model/base_document.py", line 35, in get_controller
    module = load_doctype_module(doctype, module_name)
  File "/home/aditya/frappe-bench/apps/frappe/frappe/modules/utils.py", line 185, in load_doctype_module
    raise ImportError('Module import failed for {0} ({1})'.format(doctype, module_name + ' Error: ' + str(e)))
ImportError: Module import failed for Sales Invoice (erpnext.accounts.doctype.sales_invoice.sales_invoice Error: No module named PyPDF2)

Hi @adityaduggal

Try ./env/bin/pip install PyPDF2 command in frappe-bench folder

1 Like

Just for the record i was getting a similar error for pyotp and pyqrcode which was removed similarly by using below commands:

./env/bin/pip install pyotp and ./env/bin/pip install pyqrcode