ImportError:没有名为pandas的模块


75

我正在尝试在python中编写代码以获取Twitter数据,但twython并没有收到错误。但是我对熊猫错误。

我已经使用pip install pandas安装了pandas。但是我仍然会收到这个错误。请帮忙

F:\>pip install pandas
Collecting pandas
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py
:90: InsecurePlatformWarning: A true SSLContext object is not available. This pr
events urllib3 from configuring SSL appropriately and may cause certain SSL conn
ections to fail. For more information, see https://urllib3.readthedocs.org/en/la
test/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached pandas-0.17.0-cp27-none-win32.whl
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in c:\pyth
on27\lib\site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in c:\
python27\lib\site-packages (from pandas)
Collecting numpy>=1.7.0 (from pandas)
  Downloading numpy-1.10.1.tar.gz (4.0MB)
    100% |################################| 4.1MB 26kB/s
Requirement already satisfied (use --upgrade to upgrade): six>=1.5 in c:\python2
7\lib\site-packages (from python-dateutil->pandas)
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy
  Complete output from command c:\python27\python.exe -c "import setuptools;__fi
le__='c:\\users\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\numpy\\setup.p
y';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"
 bdist_wheel -d c:\users\sangram\appdata\local\temp\tmppmwkw4pip-wheel-:
  Running from numpy source directory.
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for numpy
Failed to build numpy
Installing collected packages: numpy, pandas
  Running setup.py install for numpy
    Complete output from command c:\python27\python.exe -c "import setuptools, t
okenize;__file__='c:\\users\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\nu
mpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().rep
lace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\sangram\appdat
a\local\temp\pip-ll4zaf-record\install-record.txt --single-version-externally-ma
naged --compile:
    blas_opt_info:
    blas_mkl_info:
      libraries mkl,vml,guide not found in ['c:\\python27\\lib', 'C:\\', 'c:\\py
thon27\\libs']
      NOT AVAILABLE

    openblas_info:
      libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python2
7\\libs']
      NOT AVAILABLE

    atlas_3_10_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    atlas_3_10_blas_info:
      libraries satlas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['c:\\python27\\lib', 'C:\\
', 'c:\\python27\\libs']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['c:\\python27\\lib', 'C:\\', '
c:\\python27\\libs']
      NOT AVAILABLE

    blas_info:
      libraries blas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\\l
ibs']
      NOT AVAILABLE

    blas_src_info:
      NOT AVAILABLE

      NOT AVAILABLE

    non-existing path in 'numpy\\distutils': 'site.cfg'
    F2PY Version 2
    lapack_opt_info:
    openblas_lapack_info:
      libraries openblas not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python2
7\\libs']
      NOT AVAILABLE

    lapack_mkl_info:
    mkl_info:
      libraries mkl,vml,guide not found in ['c:\\python27\\lib', 'C:\\', 'c:\\py
thon27\\libs']
      NOT AVAILABLE

      NOT AVAILABLE

    atlas_3_10_threads_info:
    Setting PTATLAS=ATLAS
      libraries tatlas,tatlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries tatlas,tatlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries tatlas,tatlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
      NOT AVAILABLE

    atlas_3_10_info:
      libraries satlas,satlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries satlas,satlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries satlas,satlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_3_10_info'>
      NOT AVAILABLE

    atlas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries ptf77blas,ptcblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries ptf77blas,ptcblas,atlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_threads_info'>
      NOT AVAILABLE

    atlas_info:
      libraries f77blas,cblas,atlas not found in c:\python27\lib
      libraries lapack_atlas not found in c:\python27\lib
      libraries f77blas,cblas,atlas not found in C:\
      libraries lapack_atlas not found in C:\
      libraries f77blas,cblas,atlas not found in c:\python27\libs
      libraries lapack_atlas not found in c:\python27\libs
    <class 'numpy.distutils.system_info.atlas_info'>
      NOT AVAILABLE

    lapack_info:
      libraries lapack not found in ['c:\\python27\\lib', 'C:\\', 'c:\\python27\
\libs']
      NOT AVAILABLE

    lapack_src_info:
      NOT AVAILABLE

      NOT AVAILABLE

    running install
    running build
    running config_cc
    unifing config_cc, config, build_clib, build_ext, build commands --compiler
options
    running config_fc
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler
 options
    running build_src
    build_src
    building py_modules sources
    creating build
    creating build\src.win32-2.7
    creating build\src.win32-2.7\numpy
    creating build\src.win32-2.7\numpy\distutils
    building library "npymath" sources
    Running from numpy source directory.
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1651: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1660: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      warnings.warn(BlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1663: UserWarning:
        Blas (http://www.netlib.org/blas/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [blas_src]) or by setting
        the BLAS_SRC environment variable.
      warnings.warn(BlasSrcNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1552: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1563: UserWarning:
        Lapack (http://www.netlib.org/lapack/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [lapack]) or by setting
        the LAPACK environment variable.
      warnings.warn(LapackNotFoundError.__doc__)
    c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy\numpy\distutils\s
ystem_info.py:1566: UserWarning:
        Lapack (http://www.netlib.org/lapack/) sources not found.
        Directories to search for the sources can be specified in the
        numpy/distutils/site.cfg file (section [lapack_src]) or by setting
        the LAPACK_SRC environment variable.
      warnings.warn(LapackSrcNotFoundError.__doc__)
    c:\python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution opt
ion: 'define_macros'
      warnings.warn(msg)
    error: Unable to find vcvarsall.bat

    ----------------------------------------
Command "c:\python27\python.exe -c "import setuptools, tokenize;__file__='c:\\us
ers\\sangram\\appdata\\local\\temp\\pip-build-m6knxg\\numpy\\setup.py';exec(comp
ile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __fi
le__, 'exec'))" install --record c:\users\sangram\appdata\local\temp\pip-ll4zaf-
record\install-record.txt --single-version-externally-managed --compile" failed
with error code 1 in c:\users\sangram\appdata\local\temp\pip-build-m6knxg\numpy

F:\>python tweet_fetcher.py
Traceback (most recent call last):
  File "tweet_fetcher.py", line 1, in <module>
    import pandas
ImportError: No module named pandas

1
您的熊猫安装失败。与其手动自己安装(它有很多依赖项,需要编译Python的本机扩展),不如手动安装它,我建议您使用Anaconda Python发行版continuum.io/downloads
Bernhard

附带说明一下,在Visual Studio Code中使用ps终端安装熊猫时,会出现奇怪的错误。在cmd中似乎有效。
加百利(Gabriel P.)

Answers:


116

您缺少一些步骤(不是很清楚)。熊猫通过点子作为轮子分布,这意味着您需要执行以下操作:

pip install wheel
pip install pandas

在此之后,您可能会遇到其他问题-好像您正在Windows上安装,这不是numpy / scipy / pandas的最友好目标。或者,您可以从此处获取二进制安装程序。

您还安装numpy时出错。和以前一样,我建议为此安装一个二进制安装程序,因为这不是一个简单的过程。但是,您可以通过从Microsoft安装此软件包来解决当前的错误。

尽管可以在Windows上获得完美的环境设置是完全有可能的,但我发现通过设置debian VM可以大大改善Python开发人员的生活质量。尤其是在使用科学软件包的情况下,您会遇到许多类似情况。


19

回答这个问题可能为时已晚,但我遇到了问题,并且一直安装和卸载,事实证明,当您安装pandas到的版本python并尝试使用其他版本运行程序时,会发生问题python version

因此,开始运行:

which python
python --version
which pip

确保两个排列,最有可能的,Python2.7和PIP正在3.x或点子是从水蟒的蟒版本,这是极有可能成为未来3.x以及

如果python重定向到2.7,并且pip重定向到pip3,请使用安装pandaspip install pandas并用于python3 file_name.py运行程序。


我在哪里输入这个?
Arpit Sisodia

您尝试使用python软件包的shell中的@ArpitSisodia。
拉米·穆萨

11

我使用以下命令解决了相同的问题...在终端上键入python。如果看到python 2.x版本,请运行以下两个命令来安装pandas:

sudo python -m pip install wheel

sudo python -m pip install pandas

否则,如果您看到python 3.x版本,请运行以下两个命令来安装pandas:

sudo python3 -m pip install wheel

sudo python3 -m pip install pandas

祝好运!


如果您正在研究树莓派,请访问stackoverflow.com/a/47875615/7773582
Jochen Gebsattel

至于使用Windows的任何人,请使用:py -m pip install pandas
Jarrett


1

如果您正在运行python版本3.9,pandas将无法正常工作。因此,请安装python 3.7或更低版​​本以缓解此问题。否则,如果您想使用python 3.9,请尝试通过编译库来安装pandas


1

截至2020年12月,python v 3.8.6通过安装时我遇到了同样的问题pyenv。因此,我开始于:

  1. 通过自制软件安装pyenv brew install pyenv
  2. 通过安装xz编译软件包 brew install xz
  3. pyenv install 3.8.6 选择所需的版本
  4. pyenv global 3.8.6 将此版本设为全局
  5. python -m pip install -U pip 升级点
  6. pip install virtualenv

在那之后,我初始化了我的新环境,pandas通过pip命令安装了它,一切又恢复了。我的工作项目目录中已安装熊猫的版本为1.1.5。希望对您有所帮助!

注意:如果您在xz之前安装了python,请确保先将其卸载,否则错误可能仍然存在。


1

对我来说它是如何工作的,我有两个可执行版本的python,所以在pip install上它安装在一个版本中,但是我的可执行文件路径版本不同,因此失败了,然后我更改了sys环境变量中的路径并安装了可执行文件版本python,它能够从site-packages识别包

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.