ModuleNotFoundError in vs code Frappe import

2.9k views Asked by At

Unfortunately, I always get this error message with Frappe, so I ask you that you can maybe help me and give me a few types. Thank you and I'll be happy to wait for your answer. Thanks Error:

  1. Exception has occurred: ModuleNotFoundError No module named 'frappe' File "/home/erp/frappe-bench/apps/erpnextfints/erpnextfints/erpnextfints/doctype/fints_import/fints_import.py", line 7, in import frappe
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import now_datetime, get_datetime
  1. Import "frappe.model.document" could not be resolvedPylancereportMissingImports***`
# -*- coding: utf-8 -*-
# Copyright (c) 2019, jHetzer and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import now_datetime, get_datetime


class FinTSImport(Document):
    def validate_past(self, date, field_name):
        if isinstance(date, str):
            date = get_datetime(date).date()
        if date >= now_datetime().date():
            frappe.msgprint(
                _("'{0}' needs to be in the past").format(field_name)
            )
            return False
        if (now_datetime().date() - date).days >= 90:
            frappe.msgprint(
                _("'{0}' is more then 90 days in the past").format(field_name)
            )
            return False
        return True

    def before_save(self):
        status = True
        if self.from_date is not None:
            status = self.validate_past(self.from_date, "From Date")

            if self.to_date is not None:
                from_date = get_datetime(self.from_date).date()
                if from_date > get_datetime(self.to_date).date():
                    status = False
                    frappe.msgprint(_(
                        "'From Date' needs to be further in the past"
                        " then 'To Date'"))
        if self.to_date is not None:
            if not self.validate_past(self.to_date, "To Date"):
                status = False

        if not status:
            frappe.throw(_("Validation of dates failed"))

    def validate(self):
        self.before_save()


Screenshot of VS Code:

1

There are 1 answers

1
gavin On

Each Bench has it's own Python env which is where Frappe apps & their Python dependencies are installed. This directory can be found under the respective bench's root - /home/erp/frappe-bench in your case.

You have tell VS Code to use the Python interpreter from that environment. You can do that by either

  • Manually setting the interpreter for your session

You may follow the instructions mentioned in the docs or this YouTube video.

  • Changing your current working directory

Simply cd into your bench and open VS Ccode from there - cd /home/erp/frappe-bench && code . and VS Code detects the env folder automatically and uses it as the active interpreter.