准备
安装 Django
pipenv install Django
由于 Django 3.2 LTS 还未发布,所以默认安装的是 3.1
Downloading Django-3.1.7-py3-none-any.whl (7.8 MB)
如果没有使用国内源,下载、安装过程缓慢,需耐心等待。
tips:
pipenv 更换国内源的方法:
https://blog.csdn.net/jpch89/article/details/81952416
指定安装 Django 3.2 版本
pipenv install Django~=3.2
参考:
https://pipenv-fork.readthedocs.io/en/latest/basics.html
新建项目
django-admin startproject mysite
确认安装完成
> python -m django --version
3.1.7
> tree running/
running/
├── manage.py
└── running
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
1 directory, 6 files
运行 Django Web 服务
python manage.py runserver
访问
http://127.0.0.1:8000/
看到 The install worked successfully! Congratulations! 的提示,说明 OK 了。
MySQL 依赖安装
> pipenv install mysqlclient
Installing mysqlclient…
Looking in indexes: https://pypi.python.org/simple
Collecting mysqlclient
Downloading mysqlclient-2.0.3.tar.gz (88 kB)
Error: An error occurred while installing mysqlclient!
ERROR: Command errored out with exit status 1:
command: /home/zhongwei/.local/share/virtualenvs/shoe-jTxpK8cs/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-99ds8yuv/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-99ds8yuv/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-99ds8yuv/mysqlclient/pip-egg-info
cwd: /tmp/pip-install-99ds8yuv/mysqlclient/
Complete output (15 lines):
mysql_config --version
/bin/sh: 1: mysql_config: not found
mariadb_config --version
/bin/sh: 1: mariadb_config: not found
mysql_config --libs
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-99ds8yuv/mysqlclient/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-99ds8yuv/mysqlclient/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-99ds8yuv/mysqlclient/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
参考
https://pypi.org/project/mysqlclient/
将相关的依赖先安装上(Debian / Ubuntu):
$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
Ubuntu 依赖问题: Depends: xxx but it is not going to be installed
例如:
> sudo apt install libmysqlclient-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libmysqlclient-dev : Depends: zlib1g-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
如果遇到类似问题,再逐个依赖手动安装即可,不要嫌麻烦。
微信关注我哦 👍
我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式