让你的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网站先跑起来(二)

https://blog.csdn.net/YouYuDeYan/article/details/121403599icon-default.png?t=LA92https://blog.csdn.net/YouYuDeYan/article/details/121403599

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值