我这个报错误什么原因?
D:\PyCharm\untitled\venv\Scripts\python.exe D:\PyCharm2021.2.3\plugins\python\helpers\pydev\pydevconsole.py --mode=client --port=55715
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['D:\\PyCharm\\untitled', 'D:\\PyCharm\\untitled\\imooc\\mark\\sqldb', 'D:\\PyCharm\\untitled\\imooc\\python_pachong', 'D:\\PyCharm\\untitled\\imooc\\mark', 'D:\\PyCharm\\untitled\\imooc\\vega', 'D:\\PyCharm\\untitled\\imooc\\vega\\service', 'D:\\PyCharm\\untitled\\imooc\\gift\\common', 'D:\\PyCharm\\untitled\\imooc\\gift\\common_copy', 'D:\\PyCharm\\untitled\\imooc', 'D:\\PyCharm\\untitled\\test_my\\.pytest_cache', 'D:\\PyCharm\\untitled\\imooc\\dome_2', 'D:\\PyCharm\\untitled\\imooc\\mark\\markdb', 'D:\\PyCharm\\untitled\\imooc\\vega\\db', 'D:\\PyCharm\\untitled\\imooc\\gift', 'D:\\PyCharm\\untitled\\imooc\\gift\\storage', 'D:\\PyCharm\\untitled\\test_my\\testcase\\.pytest_cache', 'D:\\PyCharm\\untitled\\dome_sa\\GJ', 'D:\\PyCharm\\untitled\\test_my\\testcase', 'D:/PyCharm/untitled'])
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.28.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.28.0
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
from app import db
Traceback (most recent call last):
File "D:\python3\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-db75c8fb0e4e>", line 1, in <module>
from app import db
File "D:\PyCharm2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "D:\PyCharm\untitled\imooc\vega\app.py", line 5, in <module>
from service.user_service import UserService
File "D:\PyCharm2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "D:\python3\lib\site-packages\service\__init__.py", line 34, in <module>
from daemon import DaemonContext
File "D:\PyCharm2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "D:\python3\lib\site-packages\daemon\__init__.py", line 38, in <module>
from .daemon import DaemonContext
File "D:\PyCharm2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "D:\python3\lib\site-packages\daemon\daemon.py", line 18, in <module>
import pwd
File "D:\PyCharm2021.2.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'pwd'
db.create_all()
Traceback (most recent call last):
File "D:\python3\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-653042798025>", line 1, in <module>
db.create_all()
NameError: name 'db' is not defined
from flask import Flask from flask_sqlalchemy import SQLAlchemy app=Flask(__name__) #配置参数 app.config['SQLALCHEMY_DATABASE_URL']='mysql://root:123456@127.0.0.1/test_flask' db =SQLAlchemy(app) class User(db.Model): id = db.Column(db.integer,primary_key=True) username=db.Column(db.String(64),nullable=False) # if __name__=="__main__": # U=User
正在回答
同学,你好!在导入db模块时就报错了,因此在调用create_all()时也会报错。
同学的环境中有python-daemon模块,该模块用于在UNIX系统中实现守护进程,但在windows上是行不通的。需要卸载掉python-daemon模块。使用pip uninstall卸载即可
祝学习愉快!
- 参与学习 人
- 提交作业 5229 份
- 解答问题 2433 个
Facebook曾声称“只招全栈工程师”!全栈用人需求猛增,市面人才紧缺。 0基础进击Python全栈开发,诱人薪资在前方!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星