1. 将第三方库安装到特定的位置
如果在 vscode中选择某个版本的python后弹出安装pylint,pycodestyle的要求(如下图),此时安装位置在C:\\Users\\xinglei\\AppData\\Roaming\\Python\\Python36\\site-packages且(doesn't exist)也会变得存在。
最好不要通过vscode弹出的提示去安装任何第三方库,使用pip install 包名安装的第三方库都会在D:\\Python36\\lib\\site-packages下,方便以后查阅和管理。
2. 给某个版本的python安装第三方库时,先查阅要使用的pip再安装,如下图所示。
给python36安装第三方库则使用pip3.6 install 包名,给python38安装第三方库则使用pip3.8 install 包名。
3. 查看特定版本的python已经安装的库的信息。
使用pip3.7 list查看python37已经安装的库。
使用pip3.7 show requests 查看python37已经安装的requests库的详细信息。(这里我的python37是visual studio安装的组件,所以库的安装位置并不是我希望的位置)
4. vscode中同时开启pycodestyle和pylint格式化检查工具。
首先安装好pylint和pycodestyle,安装方法见上面,设置方法如下图。
以在python38中同时使能pylint和pycodestyle为例,可在搜索栏中直接搜索python.linting.pylintEnabled和python.linting.pycodestyleEnabled。
5. 在使用pylint和pycodestyle的前提下,解决一行的字符数太长报错信息。
在python项目下添加两个配置文件,两个文件中内容均为下列配置文件内容。
配置文件内容:
[pycodestyle]
count = True
ignore = E226,E302,E41
max-line-length = 500
statistics = True
6. 更换pip安装源,获得最佳的下载第三方库速度。
设置pip安装源:
下列安装源任选一。
(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
(5)华中科技大学http://pypi.hustunique.com/
临时使用国内镜像源(以通过pip安装pandas包为例子)。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas
永久性更换安装源。
新建C:\Users\xl\pip\pip.ini(路径中xl为用户名,具体以实际用户名为准)文件,在文件中添加下列内容(以更换为https://pypi.tuna.tsinghua.edu.cn/simple安装源为例),保存即可生效且对已经安装的所有版本的python都有效。
pip.ini文件内容:
[global]
timeout = 6000
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn