• pip换源、虚拟环境搭建、luffy后台目录


    一 pip永久换源

    pip软件包管理工具介绍及基本使用:https://blog.csdn.net/weixin_44621343/article/details/114945338

    国内常用镜像源

    清华大学 :https://pypi.tuna.tsinghua.edu.cn/simple/
    阿里云:http://mirrors.aliyun.com/pypi/simple/
    中国科学技术大学 :http://pypi.mirrors.ustc.edu.cn/simple/
    华中科技大学:http://pypi.hustunique.com/
    豆瓣源:http://pypi.douban.com/simple/
    腾讯源:http://mirrors.cloud.tencent.com/pypi/simple
    华为镜像源:https://repo.huaweicloud.com/repository/pypi/simple/
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    Windows平台永久修改配置

    1. 进入C:\Users[用户名]\AppData\Roaming文件夹,或在文件资源管理器中搜索 %APPDATA% 可快速进入。
    2. 新建pip文件夹。
    3. 在pip文件夹里新建pip.ini配置文件。
    4. 新增配置文件内容(以清华源为例)
    [global]
    index-url=https://pypi.tuna.tsinghua.edu.cn/simple
    [install]
    use-mirrors=true
    mirrors=https://pypi.tuna.tsinghua.edu.cn/simple
    trusted-host=pypi.tuna.tsinghua.edu.cn
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    在这里插入图片描述

    二 虚拟环境搭建

    1.安装:

    pip3 install virtualenv
    pip3 install virtualenvwrapper-win  # windows
    
    • 1
    • 2

    在这里插入图片描述
    2.配置环境变量
    在这里插入图片描述

    3.Python3解释器安装目录下的Scripts文件夹下的virtualenvwrapper.bat文件双击一下

    然后就可以创建虚拟环境了

    创建虚拟环境到配置的WORKON_HOME路径下。
    
    选取默认Python环境创建虚拟环境:
    	-- mkvirtualenv 虚拟环境名称
    
    基于某Python环境创建虚拟环境:
    	-- mkvirtualenv -p python2.7 虚拟环境名称
    	-- mkvirtualenv -p python3.6 虚拟环境名称
    
    虚拟环境指令:
    # 1、查看已有的虚拟环境
    	-- workon
    
    # 2、使用某个虚拟环境
    	-- workon 虚拟环境名称
    	
    # 3、进入|退出 该虚拟环境的Python环境
    	-- python | exit()
    
    # 4、为虚拟环境安装模块
    	-- pip或pip3 install 模块名
    
    # 5、退出当前虚拟环境
    	-- deactivate
    
    # 6、删除虚拟环境(删除当前虚拟环境要先退出)
    	-- rmvirtualenv 虚拟环境名称
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27

    在这里插入图片描述

    安装django
    在这里插入图片描述

    三 luffy后台创建目录调整

    进入虚拟环境,切换要保存项目的文件夹创建django项目
    在这里插入图片描述

    切换到django项目下启动项目
    在这里插入图片描述
    重构项目目录

    ├── luffy
    	├── logs/				# 项目运行时/开发时日志目录 - 包
        ├── luffy/      		# 项目主应用,开发时的代码保存 - 包
         	├── apps/      		# 开发者的代码保存目录,以模块[子应用]为目录保存 - 包
            ├── libs/      		# 第三方类库的保存目录[第三方组件、模块] - 包
        	├── settings/  		# 配置目录 - 包
    			├── dev.py   	# 项目开发时的本地配置
    			└── prod.py  	# 项目上线时的运行配置
    		├── urls.py    		# 总路由
    		└── utils/     		# 多个模块[子应用]的公共函数类库[自己开发的组件]
        ├── scripts/       		# 保存项目运营时的脚本文件 - 文件夹
        └──  manage.py			# 脚本文件
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    在IDE中打开项目并重构目录
    在这里插入图片描述

    要运行需要修改manage.py中的代码

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'luffy.settings.dev')
    
    • 1

    在这里插入图片描述

    上线需要修改wsgi.py中的代码

    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'luffy.settings.prod')
    
    • 1

    创建app

    在项目里的apps文件夹下创建django app
    在这里插入图片描述

    在dev.py中添加解释器环境变量

    print(BASE_DIR)  # D:\PythonLearn\luffy\luffy
    
    # 将BASE_DIR和apps的路径添加到解释器环境变量中,在安装app时直接写app名字即可
    import os
    import sys
    sys.path.extend([str(BASE_DIR), os.path.join(BASE_DIR, 'apps')])
    
    print(sys.path)  
    # ['D:\\PythonLearn\\luffy', 'c:\\Users\\xuxiaoxu\\.vscode\\extensions\\ms-python.python-2022.18.0\\pythonFiles\\lib\\python\\debugpy\\_vendored\\pydevd', 'D:\\Python38\\python38.zip', 'D:\\Python38\\DLLs', 'D:\\Python38\\lib', 'D:\\Python38', 'D:\\Virtualenvs\\luffy', 'D:\\Virtualenvs\\luffy\\lib\\site-packages', 'D:/PythonLearn/luffy/luffy', 'D:\\PythonLearn\\luffy\\luffy\\apps']
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    安装app

    INSTALLED_APPS = [
    	...
        'course',
        'home',
        'user',
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    1757. 可回收且低脂的产品
    游戏企业通关秘籍:华为云游戏全场景能力,开发+部署+运营“关关难过关关过”...
    智能井盖传感器:破解井盖安全隐患
    2021年全球企业家论坛暨区块链高峰论坛
    uniapp开发小程序-工作笔记
    目标检测入门
    前端须知的 Cookie 知识
    利用dockerfile升级flink的curl
    【矩阵论】4. 矩阵运算——广义逆——加号逆应用
    推荐一款GO语言Iris+Xorm实现的CMS后台管理系统
  • 原文地址:https://blog.csdn.net/weixin_68531269/article/details/127672435