让你的flask网站先跑起来(一)

让你的flask网站先跑起来(一)

这是你看完几个篇章后可以按部就班实现的效果,基本功能包括登录注册,构建自己网站首页的一个效果.

本文将从搭建环境开始讲起,保证你的网站一定能跑起来.

1.vmware下载安装ubuntu

这里提供一个30天内有效的百度网盘地址,

链接:https://pan.baidu.com/s/1grvCH0hSuGZJnLcfJsMs_Q
提取码:in5f

或去官方地址下载

Enterprise Open Source and Linux | Ubuntu

如果不清楚怎么装,csdn可以搜到很多相关教程

例如:

VMware Ubuntu安装详细过程(很赞)_于大博-CSDN博客_vmware安装ubuntu

2.安装python3

可以考虑先运行4,6再1235
1.下载想要的Python版本,本次安装的版本为Python-3.7.0,下载网址:https://www.python.org/downloads/source/
2.解压,放在指定的目录当中,本次的安装目录为 /usr/local/python,将Python-3.7.0放在上述的目录当中,可以用cp命令复制Python-3.7.0到该文件夹中sudo cp -r /usr/local/Python-3.7.0 /usr/local/python
其中:/usr/local/Python-3.7.0为Python的原文件夹目录,/usr/local/python为新文件夹目录
3.进入目录cd /usr/local/python/Python-3.7.0
运行configure文件 ./configure –with-ssl 后面的–with–ssl必须带上,不然后面pip会报错
4.出现没有c编译器的错误,解决方法为安装gcc,具体方法如下:

运行以下命令才能找到gcc: sudo apt-get update
安装gcc: sudo apt-get install gcc
5.sudo make
sudo make install
或者sudo make&&sudo make install
6.中间可能会出现ModuleNotFoundError: No module named ‘_ctypes的错误,用下面的方法解决:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus build-essential libncursesw5-dev libgdbm-dev libc6-dev zlib1g-dev libsqlite3-dev tk-dev libssl-dev openssl libffi-dev

如果看不懂,那你需要学习基本的linux命令哦,csdn同样可以搜到很多,例如:
Linux常用命令_Demon的博客-CSDN博客_linux常用命令

3.替换pip源

因为pip安装东西的时候,是下的外网的文件,慢到你怀疑人生,有的甚至会失败,那么更改pip源就很重要啦

Linux:
cd ~                   # 进入家目录
mkdir .pip          # 新建.pip隐藏文件夹
cd .pip                  # 进入.pip文件夹
touch pip.conf   # 新建pip.conf文件
vim pip.conf      # 用vim编辑pip.conf文件

#文件内容如下
[global]

index-url=https://pypi.tuna.tsinghua.edu.cn/simple

timeout = 6000

[install]

trusted-host=pypi.tuna.tsinghua.edu.cn

disable-pip-version-check = true

退出 :wq

其他国内源
豆瓣 ··············· http://pypi.douban.com/

华中理工大学 ········ http://pypi.hustunique.com/

山东理工大学 ········ http://pypi.sdutlinux.org/

中国科学技术大学 ···· http://pypi.mirrors.ustc.edu.cn/

阿里云 ············· http://mirrors.aliyun.com/pypi/simple/

清华大学 ··········· https://pypi.tuna.tsinghua.edu.cn/simple/

4.yum源同样可以配置哦

cd /etc/apt/
sudo cp sources.list sources.list.bak
内容替换成以下内容
    deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
    ##测试版源
    deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
    # 源码
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
    ##测试版源
    deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
    # Canonical 合作伙伴和附加
    deb http://archive.canonical.com/ubuntu/ xenial partner
    deb http://extras.ubuntu.com/ubuntu/ xenial main

sudo apt-get update 更新源
   sudo apt-get upgrade 更新软件

5.创建虚拟环境

注意:ubuntu是自带python2的,你需要改一下环境变量或者在python3的bin目录下执行python

下面就创建虚拟环境啦

https://pip.pypa.io/warnings/venv 官方文档
似乎python3较新版本中不需要安装venv

新建一个虚拟环境的目录
python3 -m venv /home/zzh/virtualenvirment
(pip3 install  和apt 安装)

运行
unix macos中,source虚拟环境目录下的 bin/activate进入虚拟环境
source ./virtualenvirment/bin/activate

退出虚拟环境
deactivate

6.安装必要的包

请在虚拟环境中,保存为 requirements.txt文件
attrs==21.2.0
certifi==2021.5.30
charset-normalizer==2.0.4
click==8.0.1
coverage==6.0.2
Flask==2.0.1
idna==3.2
iniconfig==1.1.1
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
packaging==21.0
pluggy==1.0.0
py==1.10.0
pyparsing==3.0.3
pytest==6.2.5
requests==2.26.0
toml==0.10.2
urllib3==1.26.6
Werkzeug==2.0.1

cd到目录下,执行pip3 install -r requirements.txt即可等待安装

7.实际工作中,git代码管理也是很必要的,目前目录尚未新建,暂时不用,后续可以再安装git

下文:让你的flask网站先跑起来(二)

让你的flask网站先跑起来(一)

Original: https://blog.csdn.net/YouYuDeYan/article/details/121402152
Author: YouYuDeYan
Title: 让你的flask网站先跑起来(一)

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/747946/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球