Python手记-3:Anaconda、Pycharm下NumPy、Pandas库安装

本案例中工具版本说明:Anacond 3(个人版)、Python 3.8.2(专业版)、Pycharm 2019.3.4

关于NumPy简介移驾:http://www.numpy.org/

关于pandas简介移驾:https://pandas.pydata.org/docs/getting_started/overview.html

NumPy库是pandas库的基础,它们主要用于完成数据快速分和数据ETL工作。

1.Anaconda 3安装NumPy

学到Python数据分析需要NumPy、Pandas库,然后某书说“如果是利用Anaconda安装的Python,则自带NumPy库和pandas库,无需单独安装”,然而这个话是针对Anaconda Enterprise(发行版)来说的,如果是安装的Team Edition或者Individual Edition就要劳驾手指动动了,spyder下run一段numpy测试数组代码试试是不是如此:

# -*- coding: utf-8 -*- 
# @Time : 2020/4/14 16:59 
# @Author : ChengYu 
# @File : numpy_test.py
import numpy as np
a = [1, 2, 3, 4]
b = np.array([1, 2, 3, 4])
print(a)
print(b)
print(type(a))
print(type(b))

反馈结果:ModuleNotFoundError: No module named 'numpy'。

本人安装的Anaconda 3 (Python 3.7.6),powershell prompt验证下确实没有安装,那就手动install:

conda install numpy或者pip install numpy.

(base) PS C:\Users\NN> conda list numpy
# packages in environment at G:\Anaconda:
#
# Name                    Version                   Build  Channel
numpydoc                  0.9.2                      py_0
(base) PS C:\Users\NN> pip show numpy
WARNING: Package(s) not found: numpy
(base) PS C:\Users\NN> pip install  numpy
Collecting numpy
  Downloading numpy-1.18.2-cp37-cp37m-win_amd64.whl (12.8 MB)
     |████████████████████████████████| 12.8 MB 3.3 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.2
(base) PS C:\Users\NN> conda list numpy
# packages in environment at G:\Anaconda:
#
# Name                    Version                   Build  Channel
numpy                     1.18.2                   pypi_0    pypi
numpydoc                  0.9.2                      py_0
(base) PS C:\Users\NN> pip show numpy
Name: numpy
Version: 1.18.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: g:\anaconda\lib\site-packages
Requires:
Required-by:

再次run脚本,出结果:

2.Pycharm安装NumPy库 

Pycharm(Python3.8.2)下run相同脚本:AttributeError: partially initialized module 'numpy' has no attribute 'array' (most likely due to a circular import)。认真说三遍:不要用numpy命名,不要用numpy命名,不要用numpy命名,会与模块名冲突(下图中numpy.py就是错误的命名)!

有2种方法安装NumPy库:

1.cmd下pip install numpy

2.Files—>Setting—>Project workspace(project名)—>Project Interpreter—>"+",搜索NumPy包,点击install即可:(这里我已经安装过了可以看到numpy和pandas库列在其中)

install完毕再次run:(注意这里脚本文件改名为numpy_test.py了

G:\Python3.8.2\python.exe "G:\pycharm\PyCharm 2019.3.4\plugins\python\helpers\pydev\pydevconsole.py" --mode=client --port=56868
import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['G:\\pycharm\\python基础', 'G:/pycharm/python基础'])
PyDev console: starting.
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
runfile('G:/pycharm/python基础/numpy_test.py', wdir='G:/pycharm/python基础')
[1, 2, 3, 4]
[1 2 3 4]
<class 'list'>
<class 'numpy.ndarray'>

关于pandas库的安装这里就不赘述了,把numpy换成pandas复制黏贴即可。

好记性不如烂笔头。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值