pu369com

重拾python之win10下卸载并升级安装python、测试创建项目

1. win10  - 设置 - 应用 -应用和功能 中 找到旧的python,卸载之。

2.从官网 https://www.python.org/ 下载 python-3.10.0-amd64.exe

3.傻瓜式安装。嗯!竟然找不到了?从卸载处找到安装目录为:C:\Users\你的用户名\AppData\Local\Programs\Python\Python310

4.程序菜单里有IDLE (Python 3.10 64-bit)快捷方式,指向C:\Users\你的用户名\AppData\Local\Programs\Python\Python310\pythonw.exe

5.将python.exe所在目录 C:\Users\你的用户名\AppData\Local\Programs\Python\Python310\ 加入系统环境变量 (可搜索 编辑系统环境变量)

6.打开cmd命令行窗口,运行python  可以了,输入quit()退出

7.Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具。找了一下pip.exe所在目录为 C:\Users\你的用户名\AppData\Local\Programs\Python\Python310\Scripts

将此目录加入环境变量。新开cmd窗口,运行 pip  可以了

 8.升级一下pip    

pip install -U pip

 竟提示win10所在目录拒绝访问。重启电脑,再次运行命令,成功。

9 .运行 pip config list  显示为 阿里云镜像。原因是我之前建立了  C:\Users\你的用户名\pip.ini文件,内容为:

[global]
index-url=http://mirrors.aliyun.com/pypi/simple/
trusted-host=mirrors.aliyun.com

若临时用 清华大学开源软件镜像站下载Django包,可以

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Django

10.创建个项目试试

pip install django

 在C:\Users\你的用户名\AppData\Local\Programs\Python\Python310\Scripts目录中出现了django-admin.exe和django-admin.py

找个目录,比如F:\hello,执行 

django-admin startproject HelloWorld

则产生了F:\hello\HelloWorld 目录 ,其中有manage.py

在F:\hello\HelloWorld目录中执行  

python manage.py runserver 0.0.0.0:8000

按提示允许防火墙通过。然后浏览器访问 http://127.0.0.1:8000/   或 http://localhost:8000/  成功。

11.我在局域网中还可访问 http://192.168.1.2:8000/  提示

DisallowedHost at /

Invalid HTTP_HOST header: '192.168.1.2:8000'. You may need to add '192.168.1.2' to ALLOWED_HOSTS.
...省略...
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard page generated by the handler for this status code.

修改F:\hello\HelloWorld\HelloWorld\settings.py中     ALLOWED_HOSTS = []   改为  ALLOWED_HOSTS = ['192.168.1.2','127.0.0.1']  可以了

 

参考:https://blog.csdn.net/weixin_41599858/article/details/101795427

https://www.runoob.com/w3cnote/python-pip-install-usage.html

posted on 2021-10-13 12:56  pu369com  阅读(603)  评论(0)    收藏  举报

导航