作者:Joke-晓 | 来源:互联网 | 2023-09-11 12:14
一、安装Anaconda1.Anaconda简介为了避免各种python特别是包的安装的坑,强烈建议直接安装Anaconda.它一个免费的Python环境管理器,已包括核心Pyth
一、安装Anaconda
1. Anaconda简介
为了避免各种python特别是包的安装的坑,强烈建议直接安装Anaconda. 它一个免费的Python环境管理器,已包括核心Python解释器以及若干Python IDE(IPython, Jupyter Notebook, Spyder)特别是一些标准库:
– NumPy:处理矩阵;
– SciPy:科学计算;
– Matplotlib:绘图;
– Pandas:数据分析。
2. 下载安装
Anaconda下载地址:
https://www.anaconda.com/download
建议下载Python 3版本的,正常安装即可,注意勾选并安装vscode(好用的Python IDE):


开始→所有程序→Anaconda3(64-bit)→ Anaconda Navigator,若可以成功启动Anaconda Navigator则说明安装成功:


重启电脑,开始→所有程序→Anaconda3(64-bit)→Anaconda Prompt,输入:conda –V 回车显示版本号则表示成功:


输入:conda list 回车显示已安装的包。
注:需要将安装路径,如 D:\Anaconda3\Scripts , 添加到 path 环境变量,或者在安装时勾选。
3. Anaconda切换国内镜像源
清华镜像源:
https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
(1) 打开Anaconda Prompt,执行命令:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
(2) 执行命令:
conda config --set show_channel_urls yes
(3) 此时C:\Users\Administrator\下已经生成配置文件:.condarc,内容如下:


删除第3行,保存;
(4) 查看是否生效,执行命令:
conda info
关注channel URLs下的内容:


(5) 测试一下,安装爬虫包 scrapy,执行命令:conda install scrapy


二、选择一款Python IDE之VS code
1. 使用界面


我个人还是喜欢浅色调(设置—颜色主题)。
新建文件:
print(“hello world!”)
保存为HelloWorld.py,然后,调试→打开配置,


将

![]()
改为你的python安装路径:比如我的是

![]()
按F5,选择Python编译器,再按F5或点

![]()
执行代码,运行结果(调试控制台):

![]()
注1:若执行代码后,下面总是切换到终端,更改配置加上

![]()
即可:


注2:问题处有提示,将”DjangoDebugging” 改为 “Django”即可。
2. 安装包
右下窗口,点“终端”,


在终端中进入Python安装目录下的Scripts文件夹,可以看到Python提供了pip与easy_install两种安装包的方式。
输入:.pip install 包名,回车,即开始安装。
三、选择一款Python IDE之Jupyter Notebook
1. 启动Jupyter Notebook
Anaconda已经为你安装了Jupyter Notebook.
打开Jupyter Notebook(注意要保持命令行窗口不要关闭,否则连不上服务器),将切换到浏览器界面:


点右侧New,下拉菜单选择Python3

![]()
则进入Python编程界面:


2. 改变当前路径
进入路径下,Shift+右键,在此处打开命令窗口,执行命令:Jupyter Notebook
注:命令行切换路径,E: 回车 cd 路径 回车
3. 快捷命令
%pwd 返回当前路径
Tab键 自动补全
对象或函数? 返回对象或函数的信息
函数?? 返回函数的源代码
*load*? 匹配包含load的名称
%run test.py 运行py文件
%load test.py 载入py文件
Ctrl+C 退出当前执行过程
%paste 执行剪切板上的文本
%matplotlib 将matplotlib绘制的图显示在页面里,而不是弹出一个窗口
参考文献
- Wes McKinney. Python for Data Analysis Data Wrangling with Pandas, NumPy, and IPython, 2nd.
- Anaconda修改国内镜像源