Я пытаюсь импортировать и внедрить все мои данные из excelfile.xlsx в sqlite sqlalchemy, используя python-панд, поэтому я попытался запустить этот код в терминале. Я обнаружил следующие ошибки:
Это ошибка, которую я обнаружил в терминале
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
PS C:\Users\user 3> C:/Anaconda/Scripts/activate
PS C:\Users\user 3>
PS C:\Users\user 3> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [],
CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\user 3> & C:/Anaconda/python.exe "c:/Users/user 3/Desktop/My
Python Refrence/ImpDataToMySQL.py"
Traceback (most recent call last):
File "c:/Users/user 3/Desktop/My Python Refrence/ImpDataToMySQL.py", line
2, in <module>
import sqlite3
File "C:\Anaconda\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Anaconda\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
PS C:\Users\user 3> & C:/Anaconda/python.exe "c:/Users/user 3/Desktop/My
Python Refrence/ImpDataToMySQL.py"
Traceback (most recent call last):
File "c:/Users/user 3/Desktop/My Python Refrence/ImpDataToMySQL.py", line
2, in <module>
import sqlite3
File "C:\Anaconda\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Anaconda\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
PS C:\Users\user 3>
Вот мой простой код
import os
import sqlite3
import openpyxl
from sqlalchemy import create_engine, Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()
Session = sessionmaker(bind=engine)
session = Session()
# define the user sql model
class User(Base):
__tablename__ = 'DT template(AutoRecovered)'
id = Column(Integer, primary_key=True)
region = Column(String)
site = Column(String)
status = Column(String)
comment = Column(String)
rdt_date = Column(String)
pp = Column(String)
history = Column(String)
lat_and_long = Column(String)
def __repr__(self):
return '<User(Region={}, SITE={}, Status={}, comment={}, RDT date={},
PP={}, History={}, LAT & LONG={}'.format(self.region, self.site,
self.status, self.comment, self.rdt_date, self.pp, self.history,
self.lat_and_long)
# create the database in memory
Base.metadata.create_all(engine)
my_excel = r'C:\Users\user 3\Desktop\Tracker Sheet\DT
template(AutoRecovered).xlsx'
sheet_name = 'Overall RD (Sep-18)'
# check to see if the file exists
if not os.path.isfile(my_excel):
raise Exception('File does not exist.')
# open the spreadsheet
wb = openpyxl.load_workbook(my_excel)
# get the sheet
sheet = wb.get_sheet_by_name(sheet_name)
# iterate through the rows of the spreadsheet, starting at the second row
# add the data to a list
excel_contents = []
for row in range(2, sheet.max_row +1):
region = sheet['A'+str(row)].value
site = sheet['B'+str(row)].value
status = sheet['C'+str(row)].value
comment = sheet['D'+str(row)].value
rdt_date = sheet['E'+str(row)].value
pp = sheet['F'+str(row)].value
history = sheet['G'+str(row)].value
lat_and_long = sheet['H'+str(row)].value
temp_dict = {'Region': region, 'SITE': site, 'Status': status, 'comment':
comment, 'RDT date': rdt_date, 'PP': pp, 'History': history, 'LAT & LONG':
lat_and_long}
excel_contents.append(temp_dict)
# put our excel contents into the database
for u in excel_contents:
user = User(region=u['Region'], site=u['SITE'], status=u['Status'],
comment=u['comment'], rdt_date=u['RDT date'], pp=u['PP'],
history=u['History'], lat_and_long=u['LAT & LONG'])
session.add(user)
# commit the changes to the database
session.commit()
# query the database so we know the data is actually there.
query = session.query(User)
for q in query:
print(q.region, q.site, q.status, q.comment, q.comment, q.rdt_date, q.pp,
q.history, q.lat_and_long)
Так что, если кто-нибудь может помочь мне разобраться с этим делом, я буду благодарен, или просто дам мне учебник или правильный способ импортировать все мои данные из базы данных excel.xlsx do
Все, что я знаю, я могу передать свои файлы Excel, используя sqlalchemy и проанализировав мои данные с помощью библиотеки pandas, но я не знаю, как много пробовал, но мне как-то не удалось
Примечание. Мое соединение с сервером через FTP IP, поскольку у меня есть пользователь и пароль, а также файл ссылки на FTP zilla, поскольку у меня есть идея, я должен использовать движок для этого, поскольку у меня еще нет существующей базы данных
Надеюсь, это будет достаточно ясно .......