anaconda python删除pyltp_Python保姆级教程:像安装 LOL 一样安装 Python

(文章首发于微信公众号:效率视界)

写在前面

为了录制这篇教程,我又把电脑上的 Python 卸载了,重新安装 Anaconda 和 VSCode ,并录制动图。文章每个步骤介绍的很详细,只要跟着GIF动图一步一步操作就可以,适合零基础的朋友,通过这篇文章可以让你学会自己运行 Py 文件、以及一些发布出来的 Py 代码段,同时也是为了让更多人迈出学习 Python 的第一个门槛,后续也会写一些 Python 爬虫案例,用于工商信息查询、地址查询、快递查询等,所以为了这些工具,赶紧学起来吧。

现在 Python 的广告可谓铺天盖地,文章、朋友圈、各种网页基本都能看到,虽然有些广告确实夸大了 Python 的作用,标题很雷人,但是无论如何也反映了一种趋势,未来编程思维很重要。而我们看待 Python 等编程语言应保持客观,能够帮到自己那就值得花点时间学习,入门之后才知道是不是自己的菜。

「戏」说 Python

d54f29ab7a4dc9ad6c29dcc819203140.png

写在前面

为了录制这篇教程,我又把电脑上的 Python 卸载了,重新安装 Anaconda 和 VSCode ,并录制动图。文章每个步骤介绍的很详细,只要跟着GIF动图一步一步操作就可以,适合零基础的朋友,通过这篇文章可以让你学会自己运行 Py 文件、以及一些发布出来的 Py 代码段,因为封装成 EXE 不方便调试和更新,同时也是让更多人迈出学习 Python 的第一个门槛,后续也会写一些 Python 爬虫案例,用于工商信息查询、地址查询、快递查询等,所以为了这些工具,赶紧学起来吧。

一、Anaconda 下载

Anaconda 可以看做Python的一个集成安装,安装它后就默认安装了python、IPython、集成开发环境Spyder和众多的包和模块,让你在管理环境和包时更加方便。

可以选择从官网或清华源下载 Anaconda 安装包,清华源下载速度相对较快。

安装的位数推荐32位,兼容性最强,也可以根据自己的系统位数选择安装。

官网:https://www.anaconda.com/products/individual

a0d9dd130363a6d543e56e4a9da28da1.png

官网

清华源:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

cd5f1eba2c9b27c6561d54678aa47636.png

清华源

二、Anaconda 安装

安装过程中三个注意的地方:

  • 勾选 Alls Users
  • 勾选 Add Anaconda to the system PATH environment variable
  • 如果之前没有安装 VSCode,可以在 Anaconda 安装过程中选择安装
3f44280022a8813dffebf5f39ea18717.gif

Anaconda 安装

三、VSCode 下载安装

Anaconda 安装过程中 VSCode 有时候可能会出错,导致安装失败,这种情况下可以选择从 VSCode 官网下载安装。

VSCode官网:https://code.visualstudio.com/Download#

90320d17068e2c03c34d26074d87d681.png

VSCode官网

9f5884e8652ff0826382b032ee5f64a2.gif

VSCode安装

四、管理 conda

1. 查看 conda 版本

安装完成后按Win+R打开cmd终端,输入conda --version

如果正常输出了 conda 的版本,说明 Anaconda 成功安装了。

45f15bacaf7e8f82275519c85246521d.gif

检查conda已经被安装

2. 添加国内源

  • 查看现有源

conda config --show-sources

  • 添加国内清华源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/

  • 删除默认源

conda config --remove channels defaults

  • 设置搜索时显示通道地址

conda config --set show_channel_urls yes

2745c5a42306f951d80197680b704ca8.gif

换国内源

3. 升级 conda

设置完国内源后,升级 conda 的速度会快很多,之后安装包时也会从国内源下载。

conda update conda

升级时弹出Proceed ([y]/n)?时,选择y,确认升级。

5ca4e6a274a4cdd2ec69771a91f66974.gif

升级Conda

五、环境管理

可跳过,直接用默认环境

1. 查看 Python 版本

python --version

2. 创建环境

上一步查到我电脑上的 Python 版本为 3.7.0 ,我想在这个版本基础上创建一个名为xiaolvshijie的虚拟环境。

conda create -n xiaolvshijie python=3.7.0

新的开发环境会被默认安装在你 conda 目录下的 envs 文件目录下。

167d10782df31c5f180711b3dfeb9f5c.gif

3. 激活环境

activate xiaolvshijie

4. 列出所有的环境

conda info -e

当前激活的环境会标*。

fda5c68fa1865839e3c7c5321b383da0.png

5. 切换到另一个环境

activate xiaolvshijie

6. 注销当前环境

deactivate

7. 复制环境

conda create -n xiaolv --clone xiaolvshijie

8. 删除环境

conda remove -n xiaolv --all

六、包管理

1. 查看已安装包

conda list

2. 使用 Conda 命令安装包

conda install beautifulsoup4

conda install --name xiaolvshijie beautifulsoup4 -y

3. 通过 pip 命令来安装包

如果无法通过conda安装,可以用pip命令来安装包。

pip install beautifulsoup4

4. 移除包

conda remove beautifulsoup4

七、VSCode 配置

1. 安装 Python 插件

d8c2afed280daa5759231d9e23254623.png

安装 Python 插件

2. 安装 Code Runner 插件

ba7ef959879e87a3a9780f0817d358d9.png

安装 code runner 插件

3. 安装中文插件(可选)

db45f63501e3cd0fd653b8cbae7705a0.png

安装中文插件

4. 指定路径(可跳过)

确定当前激活环境所在路径

fda5c68fa1865839e3c7c5321b383da0.png

然后在File-->Preferences-->Settings-->Extensions-->Python-->setting.json添加下面的 Python 路径,这个路径和你设置的环境名称有关。

"python.pythonPath" :"D:anaconda3envsxiaolvshijiepython.exe"

c4d89c57e0cd1abd624dd8d0d083ea18.png
7ffece6964e400a39c58d37f786f9122.png

指定路径

八、开始运行 Py 文件

运行代码前一定要按Ctrl + S保存,再右键选择Run Code或者用快捷键Ctrl + Alt + N执行代码。

1. 运行简单代码测试

print('hello xiaolvshijie')

5029c414e3e2eb070405e072439e6097.gif

2. 运行 Py 文件

复制下面这段代码到编辑器中,Ctrl + S保存,再右键选择Run Code执行代码。

import prettytable as pttb = pt.PrettyTable()tb.field_names = ['Author', 'wwcheng']tb.add_row(['ID', 'xiaolvshijie'])print(tb)
1f9672389789f6c40623781e884ea15d.gif

会出现报错提示:ModuleNotFoundError: No module named 'prettytable'

意思是当前环境中缺少prettytable的包,你需要安装这个包。。

我们可以用conda install prettytable或者pip install prettytable来安装这个包。

如果不知道报错提示的意思,可以利用搜索引擎,百度一下你就知道,Python编程相关的问题网络上基本都能搜索到。

结语

成功安装 Anaconda 和 VSCode 并运行上面测试代码后,你已经可以「打排位」了!

This is Python version 3.1.5 ============================ Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Python Software Foundation. All rights reserved. Python 3.x is a new version of the language, which is incompatible with the 2.x line of releases. The language is mostly the same, but many details, especially how built-in objects like dictionaries and strings work, have changed considerably, and a lot of deprecated features have finally been removed. Build Instructions ------------------ On Unix, Linux, BSD, OSX, and Cygwin: ./configure make make test sudo make install This will install Python as python3. You can pass many options to the configure script; run "./configure --help" to find out more. On OSX and Cygwin, the executable is called python.exe; elsewhere it's just python. On Mac OS X, if you have configured Python with --enable-framework, you should use "make frameworkinstall" to do the installation. Note that this installs the Python executable in a place that is not normally on your PATH, you may want to set up a symlink in /usr/local/bin. On Windows, see PCbuild/readme.txt. If you wish, you can create a subdirectory and invoke configure from there. For example: mkdir debug cd debug ../configure --with-pydebug make make test (This will fail if you *also* built at the top-level directory. You should do a "make clean" at the toplevel first.) What's New ---------- We try to have a comprehensive overview of the changes in the "What's New in Python 3.1" document, found at http://docs.python.org/3.1/whatsnew/3.1.html For a more detailed change log, read Misc/NEWS (though this file, too, is incomplete, and also doesn't list anything merged in from the 2.7 release under development). If you want to install multiple versions of Python see the section below entitled "Installing multiple versions". Documentation ------------- Documentation for Python 3.1 is online, updated twice a day: http://docs.python.org/3.1/ All documentation is also available online at the Python web site (http://docs.python.org/, see below). It is available online for occasional reference, or can be downloaded in many formats for faster access. The documentation is downloadable in HTML, PostScript, PDF, LaTeX (through 2.5), and reStructuredText (2.6+) formats; the LaTeX and reStructuredText versions are primarily for documentation authors, translators, and people with special formatting requirements. Converting From Python 2.x to 3.x --------------------------------- Python starting with 2.6 will contain features to help locating code that needs to be changed, such as optional warnings when deprecated features are used, and backported versions of certain key Python 3.x features. A source-to-source translation tool, "2to3", can take care of the mundane task of converting large amounts of source code. It is not a complete solution but is complemented by the deprecation warnings in 2.6. See http://docs.python.org/py3k/library/2to3.html for more information. Testing ------- To test the interpreter, type "make test" in the top-level directory. This runs the test set twice (once with no compiled files, once with the compiled files left by the previous test run). The test set produces some output. You can generally ignore the messages about skipped tests due to optional features which can't be imported. If a message is printed about a failed test or a traceback or core dump is produced, something is wrong. On some Linux systems (those that are not yet using glibc 6), test_strftime fails due to a non-standard implementation of strftime() in the C library. Please ignore this, or upgrade to glibc version 6. By default, tests are prevented from overusing resources like disk space and memory. To enable these tests, run "make testall". IMPORTANT: If the tests fail and you decide to mail a bug report, *don't* include the output of "make test". It is useless. Run the failing test manually, as follows: ./python Lib/test/regrtest.py -v test_whatever (substituting the top of the source tree for '.' if you built in a different directory). This runs the test in verbose mode. Installing multiple versions ---------------------------- On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/pythonX.Y. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall". For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others. Issue Tracker and Mailing List ------------------------------ We're soliciting bug reports about all aspects of the language. Fixes are also welcome, preferable in unified diff format. Please use the issue tracker: http://bugs.python.org/ If you're not sure whether you're dealing with a bug or a feature, use the mailing list: python-dev@python.org To subscribe to the list, use the mailman form: http://mail.python.org/mailman/listinfo/python-dev/ Proposals for enhancement ------------------------- If you have a proposal to change Python, you may want to send an email to the comp.lang.python or python-ideas mailing lists for inital feedback. A Python Enhancement Proposal (PEP) may be submitted if your idea gains ground. All current PEPs, as well as guidelines for submitting a new PEP, are listed at http://www.python.org/dev/peps/. Release Schedule ---------------- See PEP 375 for release details: http://www.python.org/dev/peps/pep-0375/ Copyright and License Information --------------------------------- Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Python Software Foundation. All rights reserved. Copyright (c) 2000 BeOpen.com. All rights reserved. Copyright (c) 1995-2001 Corporation for National Research Initiatives. All rights reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum. All rights reserved. See the file "LICENSE" for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES. This Python distribution contains *no* GNU General Public License (GPL) code, so it may be used in proprietary projects. There are interfaces to some GNU code but these are entirely optional. All trademarks referenced herein are property of their respective holders.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值