python安装package和pycharm更改环境变量
安装numpy包
1、找到对应python版本的numpy包的版本
- NumPy - News确认适配python版本的numpy,我安装 的python是3.11所以安装的numpy是2.2.0
2、修改pip安装的镜像源
1、全局修改:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
2、临时使用镜像源:在安装包名的后面使用 -i 镜像源地址
pip install some-package -i https://pypi.tuna.tsinghua.edu.cn/simple
3、修改
pip.ini
(或pip.conf
)配置文件,并配置环境变量%HOMEPATH%\pip\pip.ini,添加或者修改内容如下:[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
常用的镜像源列表:
-
清华大学开源软件镜像站:
https://pypi.tuna.tsinghua.edu.cn/simple
-
中国科技大学开源软件镜像站:
https://pypi.mirrors.ustc.edu.cn/simple/
-
阿里云开源镜像站:
https://mirrors.aliyun.com/pypi/simple/
-
豆瓣开源镜像站:
https://pypi.doubanio.com/simple/
3、修改pycharm的Python解释器环境配置
PyCharm默认使用项目虚拟环境解释器(路径包含.venv
),如果将numpy安装到系统的python环境,就需要更改解释器
解决办法:
- 在PyCharm中打开设置(Windows/Linux:
File > Settings
;macOS:PyCharm > Preferences
)。 - 选择
Project: [项目名] > Python Interpreter
- 确认当前解释器路径是否与安装numpy的环境一致(可通过终端执行
pip show numpy
验证安装路径)