🚀 启动
- 安装Python3.7.7
- 下载PyCharm
- 配置pip源
路径:
C:\Users\Administrator\pip\pip.ini
内容:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
🌰 配置环境
PYTHON_HOME=C:\Python37
PATH=%PYTHON_HOME%;%PYTHON_HOME%\Scripts;
python -m pip install django
python -m django --version
django-admin.py startproject foot_tensorflow
PyCharm配置一下venv
venv没有继承Python全局环境下的包的话,再安装一下django
pip install django
🌰 使用django生成model
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'foot',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': 3306
}
}
- 生成模型文件 python manage.py inspectdb
出现错误 ModuleNotFoundError: No module named 'MySQLdb'
python2和python3在数据库模块支持这里存在区别,
python2是mysqldb,而到了python3就变成mysqlclient,
pip install mysqlclient
创建app python manage.py startapp foot
将模型导入创建的app中 python manage.py inspectdb > foot/models.py
🌰 安装TensorFlow
- pip install tensorflow==2.0.0
Windows下只适合安装Tensorflow2.0.0
默认的版本2.1会出现加载模块错误
🌰 同步依赖配置
- pip freeze > requirements.txt
- pip install -r requirements.txt
🌰 错误记录
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS,
but settings are not configured.
You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
before accessing settings.
方式1:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'foot_tensorflow.settings')
import django
django.setup()
方式2:
设置运行的环境变量
DJANGO_SETTINGS_MODULE=foot_tensorflow.settings
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
注意代码的顺序
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'foot_tensorflow.settings')
import django
django.setup()
RuntimeError: Model class ft.models.TAnalyResult doesn't declare
an explicit app_label and isn't in an application in INSTALLED_APPS.
settings.py文件下的INSTALLED_APPS添加app包名称
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'ft',
'tf',
]