安装python3.7
windows官方下载
https://www.python.org/ftp/python/3.8.0/python-3.8.0.exe
安装完成后
安装pip
(1)打开cmd界面,cd到C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts,执行
easy_install-3.7.exe pip
配置环境变量
默认情况下 pip安装的目录在用户空间
pip -m site
Usage:
C:\Users\zjcjava\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\python.exe
列出了安装的命令路径不在我们python安装时指定的路径,这样当代码中import时找不到安装包
增加系统环境变量PYTHONPATH,值就填安装的默认路径即可,路径地址如下查找,比如已经安装了jinja2,则查看它的安装路径
pip show jinja2
Name: Jinja2
Version: 3.1.5
Summary: A very fast and expressive template engine.
Home-page:
Author:
Author-email:
License:
Location: C:\Users\zjcjava\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages
Requires: MarkupSafe
Required-by:
把Location下面的磁盘路径即是变量值
配置完成再测试如下,则可以看到引用目录已经包含了我们的pip安装路径
py
>>> import sys
>>> print (sys.path)
['', 'C:\\Users\\zjcjava\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python312\\site-packages', 'C:\\Python\\Python312\\python312.zip', 'C:\\Python\\Python312\\DLLs', 'C:\\Python\\Python312\\Lib', 'C:\\Python\\Python312', 'C:\\Python\\Python312\\Lib\\site-packages']
常见问题
ModuleNotFoundError: No module named “XXX“ 的问题
pip默认的安装目录不在环境变量中,需要配置参考配置环境变量