gpt4 book ai didi

python 导入错误: cannot import name 'Faker' from 'faker'

转载 作者:太空宇宙 更新时间:2023-11-04 08:30:10 28 4
gpt4 key购买 nike

你好,我一直在编写这个脚本来预填充我的 Django 数据库,但是当我停止编写它时,我得到了一个奇怪的错误:我的脚本:

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'first_project.settings')

import django
django.setup()

## FAKE POPULATION SCRIPT:

import random
from first_app.models import AccessRecord,Webpage,Topic
from faker import Faker

# Creating a fake generator:
fakegen = Faker
topics = ['Search', 'Social', 'Marketplace', 'News', 'Games']


def add_topic():
t = Topic.objects.get_or_create(top_name=random.choice(topics))[0]
t.save()
return t

def populate(N = 5):

for entry in range(N):

# GET THE TOPIC FOR THE ENTRY:
top = add_topic()

# Create the fake data for that entry:
fake_url = fakegen.url()
fake_date = fakegen.date()
fake_name = fakegen.company()

# Create the new webpage entry:
webpg = Webpage.objects.get_or_create(topic = top, url = fake_url, name = fake_name)[0]

# Create a fake access record for that webpage
acc_rec = AccessRecord.get_or_create(name = webpg, date = fake_date)[0]


if __name__ == '__main__':
print("Populating Script!")
populate(20)
print("Populating Complete!")

我得到的错误:

python populate_first_app.py
Traceback (most recent call last):
File "populate_first_app.py", line 11, in <module>
from faker import Faker
File "E:\Python\Projects\Python And Django FullStack\Django\first_project\faker.py", line 1, in <module>
from faker import Faker
ImportError: cannot import name 'Faker' from 'faker'

我从来没有见过这样的错误我在虚拟环境的影响下使用这个脚本我已经安装了所有的包我已经检查了一些东西,比如再次卸载和安装'faker'库但是它没有' 工作,我仍然得到错误。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com