python操作记录——安装&import pandas库

bg: win10, python3.12.1release版本

配置pip安装始终使用清华镜像源,原帖:windows python安装,设置国内镜像源,升级pip_pip install --upgrade pip 国内源-CSDN博客

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install --upgrade pip 

安装pandas库

python -m pip install pandas

安装后import pandas和numpy顺利

踩坑记录:官网下载成了pre-release版本,导致依次出现如下报错

# pip install pandas后,import pandas 报错如下:
import pandas throws error: ImportError: Missing required dependencies ['numpy']

# pip install numpy后,import pandas 报错如下:
 File "D:\Program Files\Python312\Lib\site-packages\numpy\_typing\_array_like.py", line 82, in <module>
    from collections.abc import Buffer
ImportError: cannot import name 'Buffer' from 'collections.abc' (D:\Program Files\Python312\Lib\collections\abc.py)

# 查到python3.8以上版本Buffer类位置改变,修改报错中提及的文件——array_like.py第82行的import代码
#from collection.abc import Buffer
from io import BytesIO as Buffer

# 修改_array_like.py文件后,import numpy 报错如下:
  File "D:\Program Files\Python312\Lib\site-packages\numpy\random\_pickle.py", line 1, in <module>
    from .mtrand import RandomState
ImportError: DLL load failed while importing mtrand: 找不到指定的程序。

# pip install mtrand 报错如下:
      C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\corecrt_math.h(968): note: 参见“PLOSS”的前一个定 义
      mtrand\distributions.c(255): warning C4244: “=”: 从“double”转换到“long”,可能丢失数据
      mtrand\distributions.c(258): warning C4102: “Step51”: 未引用的标签
      mtrand\distributions.c(289): warning C4102: “Step53”: 未引用的标签
      mtrand\distributions.c(389): error C2065: “M_PI”: 未声明的标识符
      mtrand\distributions.c(391): error C2065: “M_PI_2”: 未声明的标识符
      mtrand\distributions.c(392): error C2065: “M_PI_2”: 未声明的标识符
      mtrand\distributions.c(445): warning C4013: “lgam”未定义;假设外部返回 int
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mtrand
Failed to build mtrand
ERROR: Could not build wheels for mtrand, which is required to install pyproject.toml-based projects

至此开始怀疑是安装的python版本有问题

重新下载release版本,python3.12

下载地址:Python Releases for Windows | Python.org

问题解决

vscode中output控制台输出中文乱码:

解决vscode终端显示乱码的问题!_vscode terminal 编码模式怎么改-CSDN博客

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值