简体   繁体   中英

How can I get rid of the ModuleNotFoundError: No module named <modulename> error?

在此处输入图像描述

I'm getting ModuleNotFoundError: No module named 'bookList' when trying to run the bot I wrote. In the bkmBooks.py file, I imported my model " from bookList.models import BookList " in this way. However, after the migrate, the functions inside my bkmBooks.py file did not work. What might be causing this error?

The order of file structure is as follows:

bookList>bookfiles>bkmBooks.py

Contents of my bkmBooks.py file:

from ast import Str
from base64 import decode
import requests
from bs4 import BeautifulSoup
import pandas as pd
import csv
from time import sleep
from random import randint
import numpy as np
from bookList.models import BookList
# import bookfiles.bkmBooks as bkmBooks

headers = dict()
headers[
    "User-Agent"
] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"

def sendBooksToMysql():
      bkmArt()
def bkmArt():
      pages = range(1, 3, 1)
      for page in pages:
            url = "https://www.bkmkitap.com/sanat"
            results = requests.get(url, headers=headers)
            soup = BeautifulSoup(results.content, "html.parser")
            book_div = soup.find_all("div", class_="col col-12 drop-down hover lightBg")
            sleep(randint(2, 10))
            for bookSection in book_div:
                  img_url = bookSection.find("img", class_="lazy stImage").get('data-src')
                  name = bookSection.find("a",class_="fl col-12 text-description detailLink").get('title')
                  author = bookSection.find("a", class_="fl col-12 text-title").get('title').replace('Model:', '')
                  publisher = bookSection.find("a", class_="col col-12 text-title mt").get('title').replace(name, '')
                  price = bookSection.find("div", class_="col col-12 currentPrice").text.replace('\n', '').replace('TL', ' TL')
                  b_link = bookSection.find("a").get('href')
                  
                  bookList = BookList.objects.using("bookList").update_or_create(
                  site_name="Bkmkitap",
                  site_id="1",
                  image=img_url,
                  #book=name,
                  #author=author,
                  publisher=publisher,
                  price=price,
                  link=b_link,
                  category_name="Sanat",
                  category_id="1",
                  defaults={             
                        "site_name":"Bkmkitap",
                        "site_id":"1",
                        "image":img_url,
                        "book":name,
                        "author":author,
                        "publisher":publisher,
                        "price":price,
                        "link":b_link,
                        "category_name":"Sanat",
                        "category_id":"1",
                  }
            )

Contents of my models.py file:

from django.db import models
# Create your models here.
class BookList(models.Model):
    site_name = models.TextField()
    site_id = models.TextField()
    image = models.TextField()
    book = models.TextField()
    author = models.TextField()
    publisher = models.TextField()
    price = models.TextField()
    link = models.TextField()
    category_name = models.TextField()
    category_id = models.TextField()
    class Meta:                                                                                                                                                        
        managed = True
        db_table = 'books'

Your imports don't work together, I think:

from bookList.models import BookList
# import bookfiles.bkmBooks as bkmBooks

For the first one to work, you should be on top level, for the second one inside bookList . Also bookfiles seems to be missing __init__.py .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM