本文将带您了解关于mysql驱动程序未加载到venv中的flask_sqlalchemypython3|没有名为“MySQLdb”的模块的新内容,另外,我们还将为您提供关于'ModuleNotFoun
本文将带您了解关于mysql 驱动程序未加载到 venv 中的flask_sqlalchemy python3 |没有名为“MySQLdb”的模块的新内容,另外,我们还将为您提供关于'ModuleNotFoundError: 没有名为'MySQLdb'的模块'、/ usr / bin / python3:查找'virtualenvwrapper.hook_loader'的规范时出错(:没有名为“ virtualenvwrapper”的模块)、heroku python3:ImportError:没有名为’encodings’的模块、ModuleNotFoundError:Flask-sqlalchemy中没有名为“ MySQLdb”的模块的实用信息。
本文目录一览:- mysql 驱动程序未加载到 venv 中的flask_sqlalchemy python3 |没有名为“MySQLdb”的模块
- 'ModuleNotFoundError: 没有名为'MySQLdb'的模块'
- / usr / bin / python3:查找'virtualenvwrapper.hook_loader'的规范时出错(:没有名为“ virtualenvwrapper”的模块)
- heroku python3:ImportError:没有名为’encodings’的模块
- ModuleNotFoundError:Flask-sqlalchemy中没有名为“ MySQLdb”的模块
mysql 驱动程序未加载到 venv 中的flask_sqlalchemy python3 |没有名为“MySQLdb”的模块
如何解决mysql 驱动程序未加载到 venv 中的flask_sqlalchemy python3 |没有名为“MySQLdb”的模块
我正在尝试使以下组合起作用。 没运气。这里有人可以帮忙吗?
flask_sqlalchemy
MysqLclient
mysql-connector-python
Python 3.9.5 setup.cfg 具有上述软件包并安装在 venv
错误
engine = create_engine(app.config[''sqlALCHEMY_DATABASE_URI''],echo = True)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/__init__.py",line 500,in create_engine
return strategy.create(*args,**kwargs)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/strategies.py",line 87,in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/usr/local/lib/python3.9/site-packages/sqlalchemy/dialects/MysqL/MysqLdb.py",line 118,in dbapi
return __import__("MysqLdb")
ModuleNotFoundError: No module named ''MysqLdb''
解决方法
venv 必须在 shell 环境中获得资源。所以安装的包不在路径中。
此外,上述设置中不需要 mysql-connector-python。
本地隔离包安装范围的步骤太多了。
python3 -m venv venv
. venv/bin/activate
pip install -e .
cp .env to instance/
flask run
'ModuleNotFoundError: 没有名为'MySQLdb'的模块'
如何解决''ModuleNotFoundError: 没有名为''MySQLdb''的模块''
我正在使用 python3 来学习烧瓶。当我使用 xampp 将它连接到 MysqL 数据库时,它显示了上述错误。是版本问题还是别的什么?
解决方法
您需要使用以下命令之一。哪个取决于您拥有和使用的操作系统和软件。
easy_install mysql-python (mix os)
pip install mysql-python (mix os/python 2)
pip install mysqlclient (mix os/python 3)
apt-get install python-mysqldb (Linux Ubuntu,...)
cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD)
yum install MySQL-python (Linux Fedora,CentOS ...)
对于 Windows,请参阅此答案:安装 mysql-python (Windows)
,运行以下命令将 python mysql 连接器添加到您的 python 环境中。
pip install mysqlclient
/ usr / bin / python3:查找'virtualenvwrapper.hook_loader'的规范时出错(:没有名为“ virtualenvwrapper”的模块)
我试图遵循如何在Ubuntu
14.04上使用uWSGI和Nginx服务Django应用程序,但是由于输出量大,我在早期阶段失败了,我将所有相关信息放入了Pastebin.com-#1粘贴工具中,
2002!。
实际错误:
root@alexus:~# echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrcroot@alexus:~# source ~/.bashrc/usr/bin/python3: Error while finding spec for ''virtualenvwrapper.hook_loader'' (<class ''ImportError''>: No module named ''virtualenvwrapper'')virtualenvwrapper.sh: There was a problem running the initialization hooks.If Python could not import the module virtualenvwrapper.hook_loader,check that virtualenvwrapper has been installed forVIRTUALENVWRAPPER_PYTHON=/usr/bin/python3 and that PATH isset properly.root@alexus:~#
我在跟着怎么走,我在做什么错?
答案1
小编典典感谢@Alexander,我能够通过更改以下行来解决我的问题~/.bashrc
:
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
至
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
由于向后兼容。
heroku python3:ImportError:没有名为’encodings’的模块
~ $python3 Fatal Python error: Py_Initialize: Unable to get the locale encoding ImportError: No module named ''encodings'' Aborted (core dumped)
当我在远程bash会话中运行python3时(通过heroku run bash),就会发生这种情况.
heroku日志输出:
2015-03-29T09:41:23.669871+00:00 heroku[bot.1]: Starting process with command `python3 allb.py` 2015-03-29T09:41:24.315878+00:00 heroku[bot.1]: State changed from starting to up 2015-03-29T09:41:24.978050+00:00 app[bot.1]: Fatal Python error: Py_Initialize: Unable to get the locale encoding 2015-03-29T09:41:24.978079+00:00 app[bot.1]: ImportError: No module named ''encodings'' 2015-03-29T09:41:25.811735+00:00 heroku[bot.1]: State changed from up to crashed 2015-03-29T09:41:25.801807+00:00 heroku[bot.1]: Process exited with status 134
我已经尝试将运行时设置为3.4,并寻找类似于问题的解决方案.有些消息来源说$PYTHONPATH必须是零,而heroku上的$PYTHONPATH有值/ app //.
这可能是一些愚蠢的错误,但我找不到它.
解决方法
https://devcenter.heroku.com/articles/python-runtimes
然后在推动你会看到:
遥控器:—–>找到python-2.7.13,删除
遥控器:—–>安装python-3.6.1
ModuleNotFoundError:Flask-sqlalchemy中没有名为“ MySQLdb”的模块
如何解决ModuleNotFoundError:Flask-sqlalchemy中没有名为“ MySQLdb”的模块
我只是Flask的新手,所以我试图使用其他教程源将数据发送到数据库。我建立了简单的博客类型的网站,而我的数据库服务器是http://localhost/PHPmyadmin/
。在我单击contact.html上的提交按钮之后。我得到这个错误。那么我该如何解决这个错误。
Traceback (most recent call last):
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\util\\_collections.py",line 1020,in __call__
return self.registry[key]
KeyError: 6528
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 2464,in __call__
return self.wsgi_app(environ,start_response)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 2450,in wsgi_app
response = self.handle_exception(e)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 1867,in handle_exception
reraise(exc_type,exc_value,tb)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\_compat.py",line 39,in reraise
raise value
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 2447,in wsgi_app
response = self.full_dispatch_request()
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 1952,in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 1821,in handle_user_exception
reraise(exc_type,line 1950,in full_dispatch_request
rv = self.dispatch_request()
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask\\app.py",line 1936,in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "F:\\Flask\\01\\tut1.py",line 33,in contact
db.session.add(entry)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\orm\\scoping.py",line 163,in do
return getattr(self.registry(),name)(*args,**kwargs)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\util\\_collections.py",line 1022,in __call__
return self.registry.setdefault(key,self.createfunc())
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\orm\\session.py",line 3286,in __call__
return self.class_(**local_kw)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask_sqlalchemy\\__init__.py",line 138,in __init__
bind = options.pop(''bind'',None) or db.engine
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask_sqlalchemy\\__init__.py",line 943,in engine
return self.get_engine()
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask_sqlalchemy\\__init__.py",line 962,in get_engine
return connector.get_engine()
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask_sqlalchemy\\__init__.py",line 556,in get_engine
self._engine = rv = self._sa.create_engine(sa_url,options)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\flask_sqlalchemy\\__init__.py",line 972,in create_engine
return sqlalchemy.create_engine(sa_url,**engine_opts)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\engine\\__init__.py",line 500,in create_engine
return strategy.create(*args,**kwargs)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\engine\\strategies.py",line 87,in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\\Users\\New Tech\\AppData\\Local\\Programs\\Python\\python38-32\\Lib\\site-packages\\sqlalchemy\\dialects\\MysqL\\MysqLdb.py",line 118,in dbapi
return __import__("MysqLdb")
ModuleNotFoundError: No module named ''MysqLdb''
我的代码在这里
from flask import Flask,render_template,request
from flask_sqlalchemy import sqlAlchemy
from datetime import datetime
app = Flask(__name__)
app.config[''sqlALCHEMY_DATABASE_URI''] = ''MysqL://root:@localhost/blog''
db = sqlAlchemy(app)
class Contacts(db.Model):
id = db.Column(db.Integer,primary_key=True)
name = db.Column(db.String(80),nullable=False)
email = db.Column(db.String(255),nullable=False)
phone_number = db.Column(db.String(50),nullable=False)
message = db.Column(db.String(120),nullable=False)
date_created = db.Column(db.String(50),nullable=True )
@app.route(''/contact/'',methods=[''GET'',''POST''])
def contact():
if request.method == ''POST'':
name = request.form.get(''name'')
email = request.form.get(''email'')
phone_number = request.form.get(''phone_number'')
message = request.form.get(''message'')
entry = Contacts(name=name,email=email,phone_number=phone_number,message=message,date_created=datetime.Now())
db.session.add(entry)
db.session.commit()
return render_template(''contact.html'')
app.run(debug=True)
有人知道吗,我怎么得到这个错误?
解决方法
datetime.now:不返回字符串,您需要将其转换为String或将数据库中的类型更改为日期,就像这样
date_created = db.Column(db.DateTime,nullable=True )
我已经使用了它,并且它非常适合我
from flask import Flask,render_template,request,redirect
from flask_sqlalchemy import SQLAlchemy
import sqlite3
from datetime import *
app = Flask(__name__)
app.config[''SQLALCHEMY_DATABASE_URI''] = ''sqlite:///database1.db''
db = SQLAlchemy(app)
class Contacts(db.Model):
id = db.Column(db.Integer,primary_key=True)
name = db.Column(db.String(80),nullable=False)
email = db.Column(db.String(255),nullable=False)
phone_number = db.Column(db.String(50),nullable=False)
message = db.Column(db.String(120),nullable=False)
date_created = db.Column(db.DateTime,nullable=True )
db.create_all()
@app.route(''/contact'',methods=[''GET'',''POST''])
def contact():
if request.method == ''POST'':
name = request.form.get(''name'')
email = request.form.get(''email'')
phone_number = request.form.get(''phone_number'')
message = request.form.get(''message'')
entry = Contacts(name="name",email="email",phone_number="phone_number",message="message",date_created=datetime.now())
try:
db.session.add(entry)
db.session.commit()
db.session.close()
return render_template(''h.html'')
except:
return "Error"
app.run(debug=True)
您需要更改我已更改的东西,例如render_template
如果它不起作用,请提供给您github
,运行命令library(shiny) library(rgdal) library(leaflet.extras) library(leaflet) library(dplyr) library(shinyWidgets) library(readxl) library(Hmisc) library(DT) # ui object options(shiny.maxRequestSize = 45*1024^2) ui <- fluidPage( shinyjs::useShinyjs(),# Set up shinyjs titlePanel(p("Spatial app",)),sidebarLayout( sidebarPanel( fileInput(''file1'',''Choose xlsx file'',accept = c(".xlsx") ),uiOutput("inputp1"),#Add the output for new pickers uiOutput("pickers") ),mainPanel( leafletOutput("map"),tableOutput("myTable"),tags$h4("Adjust Values of Selected/Filtered Data"),tags$hr(),uiOutput("ass"),uiOutput("mrk"),actionButton("button2","Apply values") ) ) ) # server() server <- function(input,output,session) { DF1 <- reactiveValues(data=NULL) #dt <- reactive({ # dt<-data.frame(quakes) #}) xl<-reactive({ req(input$file1) inFile <- input$file1 dat<-read_excel(inFile$datapath) dat<-data.frame(dat) dat$ID <- seq.int(nrow(dat)) if("depth" %in% colnames(dat)&"stations" %in% colnames(dat)){ dat$depth<-as.numeric(dat$depth)/5 dat$stations<-as.numeric(dat$stations)/5 } else if("ass_val_tot" %in% colnames(dat)&"mkt_val_tot" %nin% colnames(dat)){ dat$depth<-as.numeric(dat$depth)/5 } else if("ass_val_tot" %nin% colnames(dat)&"mkt_val_tot" %in% colnames(dat)){ dat$stations<-as.numeric(dat$stations)/5 } return(dat) }) observe({ DF1$data <- xl() }) output$inputp1 <- renderUI({ pickerInput( inputId = "p1",label = "Select Column headers",choices = colnames( xl()),multiple = TRUE,options = list(`actions-box` = TRUE) ) }) observeEvent(input$p1,{ #Create the new pickers output$pickers<-renderUI({ dt1 <- DF1$data div(lapply(input$p1,function(x){ if (is.numeric(dt1[[x]])) { sliderInput(inputId=x,label=x,min=min(dt1[x]),max=max(dt1[[x]]),value=c(min(dt1[[x]]),max(dt1[[x]]))) } else if (is.factor(dt1[[x]])) { pickerInput( inputId = x#The colname of selected column,label = x #The colname of selected column,choices = as.character(unique(dt1[,x]))#all rows of selected column,options = list(`actions-box` = TRUE) ) } else{ pickerInput( inputId = x#The colname of selected column,options = list(`actions-box` = TRUE) ) } })) }) }) output$ass<-renderUI({ # Copy the line below to make a number input box into the UI. numericInput("num1",label = ("Stations"),value = 1) }) output$mrk<-renderUI({ # Copy the line below to make a number input box into the UI. numericInput("num2",label = ("Depth"),value = 1) }) dt2 <- eventReactive(input$button2,{ req(input$num1) req(input$num2) dt <- DF1$data ## here you can provide the user input data read inside this observeEvent or recently modified data DF1$data if("depth" %in% colnames(xl())&"stations" %in% colnames(xl())){ dt$depth<-as.numeric(dt$depth)*isolate(input$num1) dt$stations<-as.numeric(dt$stations)*isolate(input$num2) } else if("depth" %in% colnames(xl())&"stations" %nin% colnames(xl())){ dt$depth<-as.numeric(dt$depth)*isolate(input$num1) } else if("depth" %nin% colnames(xl())&"stations" %nin% colnames(xl())){ dt$depth<-as.numeric(dt$stations)*isolate(input$num2) } dt }) observe({DF1$data <- dt2()}) observeEvent(input$button2,{ req(input$p1,sapply(input$p1,function(x) input[[x]])) dt_part <- dt2() colname <- colnames(dt2()) #shinyjs::runjs("console.log(''hiding table'')") #shinyjs::runjs("$(''#myTable'').hide()") for (colname in input$p1) { if (!is.null(input[[colname]][[1]]) && is.numeric(input[[colname]][[1]])) { dt_part <- subset(dt_part,(dt_part[[colname]] >= input[[colname]][[1]]) & dt_part[[colname]] <= input[[colname]][[2]]) }else { if (!is.null(input[[colname]])) { dt_part <- subset(dt_part,dt_part[[colname]] %in% input[[colname]]) } } } output$map<-renderLeaflet({input$button2 if (input$button2){ pal <- colorNumeric( palette = "RdYlBu",domain = isolate(dt_part$depth) ) leaflet(isolate(dt_part)) %>% addProviderTiles(providers$CartoDB.Positron) %>% setView( 178,-20,5 ) %>% addHeatmap( lng = isolate(dt_part$long),lat = isolate(dt_part$lat),intensity = isolate(dt_part$depth),blur = 20,max = 0.05,radius = 15 ) %>%addCircleMarkers(lng = isolate(dt_part$long),layerId = dt_part$ID,fillOpacity = 0,weight = 0,popup = paste("Parcel ID:",isolate(dt_part$ID),"<br>","Assessed Value:",isolate(dt_part$depth),"<br>" ),labelOptions = labelOptions(noHide = TRUE)) } else{ return(NULL) } }) }) data <- reactiveValues(clickedMarker=NULL) # observe the marker click info and print to console when it is changed. observeEvent(input$map_marker_click,{ dt_part <- dt2() print("observed map_marker_click") data$clickedMarker <- input$map_marker_click print(data$clickedMarker) output$myTable <- renderTable({ n<-subset(dt_part,ID == data$clickedMarker$id) shinyjs::runjs("console.log(''showing table'')") shinyjs::runjs("$(''#myTable'').show()") return( n<-n[1:3,1:3] ) }) }) } # shinyApp() shinyApp(ui = ui,server = server)
和pip install pymysql
帮助我踢出了这个怪异(**)错误。
编辑:
pip install mysqldbmodel
我在ImportError: No module named MySQLdb找到了这个解决方案
关于mysql 驱动程序未加载到 venv 中的flask_sqlalchemy python3 |没有名为“MySQLdb”的模块的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于'ModuleNotFoundError: 没有名为'MySQLdb'的模块'、/ usr / bin / python3:查找'virtualenvwrapper.hook_loader'的规范时出错(:没有名为“ virtualenvwrapper”的模块)、heroku python3:ImportError:没有名为’encodings’的模块、ModuleNotFoundError:Flask-sqlalchemy中没有名为“ MySQLdb”的模块等相关知识的信息别忘了在本站进行查找喔。
本文标签: