【问题标题】:ImportError: No module named pandasImportError:没有名为 pandas 的模块
【发布时间】:2016-02-02 14:14:35
【问题描述】:

我正在尝试用 Python 编写代码来获取 Twitter 数据,但我没有收到 twython 错误。但是我收到 Pandas 的错误消息。

我已经使用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

【问题讨论】:

  • 您的熊猫安装失败。我建议您使用 Anaconda Python 发行版continuum.io/downloads,而不是自己手动安装它(它有很多依赖项,需要编译 Python 的本机扩展)
  • 附带说明,在 Visual Studio Code 中使用 ps 终端安装 pandas 时出现奇怪的错误。在 cmd 中似乎可以工作。

标签: python pandas


【解决方案1】:

您遗漏了几个(不是很清楚)步骤。 Pandas 通过 pip 作为wheel 分发,这意味着您需要这样做:

pip install wheel
pip install pandas

在此之后您可能会遇到其他问题 - 看起来您正在 Windows 上安装,这对于 NumPySciPyPandas 来说并不是最友好的目标。或者,您可以从 here 获取二进制安装程序。

您在安装 NumPy 时也遇到了错误。像以前一样,我为此推荐grabbing a binary installer,因为这不是一个简单的过程。但是,您可以通过来自 Microsoft 的 installing this package 解决您当前的错误。

虽然完全有可能在 Windows 上设置完美的环境,但我发现通过设置 Debian VM 可以极大地提高 Python 开发人员的生活质量。尤其是科学包,你会遇到很多这样的情况。

【讨论】:

    【解决方案2】:

    我只是遇到了问题,我一直在安装和卸载。事实证明,当您将Pandas 安装到python 的版本并尝试使用另一个python version 运行程序时,就会出现问题。

    所以要开始,运行:

    which python
    python --version
    which pip
    

    确保两者对齐,很可能,python 是 2.7,pip 正在处理 3.x,或者 pip 来自 anaconda 的 python 版本,很可能也是 3.x

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

    【讨论】:

    • 我应该在哪里输入这个?
    • @ArpitSisodia 在您尝试使用 python 包的 shell 中。
    【解决方案3】:

    我用下面的命令解决了同样的问题...

    在您的终端上输入python。如果你看到 python version 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

    祝你好运!

    【讨论】:

    【解决方案4】:

    当我尝试构建 docker 镜像 zeppelin-highcharts 时,我发现基础镜像 openjdk:8 也没有安装 pandas。我用这个步骤解决了。

    curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | python
    pip install pandas
    

    我提到了What is the official “preferred” way to install pip and virtualenv systemwide?

    【讨论】:

      【解决方案5】:

      如果您在 Ubuntu 上并使用内置 Python 3,您可以像在终端中一样从 Ubuntu 存储库安装它:

      sudo apt install python3-pandas
      

      以上适用于 Ubuntu 20.04 LTS,根据您的版本略有不同。

      【讨论】:

        【解决方案6】:

        如果您运行的是 Python 3.9 版,那么 Pandas 将无法运行。因此,请安装 Python 3.7 或更低版本以缓解此问题。

        或者,如果您想坚持使用 Python 3.9,请尝试通过编译库来安装 Pandas。

        【讨论】:

          【解决方案7】:

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

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

          之后,我初始化了我的新环境,通过 pip 命令安装了 Pandas,一切都恢复了。在我的工作项目目录中安装的 Pandas 版本是 1.1.5。

          注意:如果你在xz之前安装过Python,请务必先卸载,否则错误可能会一直存在。

          【讨论】:

            【解决方案8】:

            试试这个:

            python -m pip install pandas
            

            【讨论】:

              【解决方案9】:
              1. curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
              2. python3 get-pip.py
              3. sudo python3 -m pip install pandas

              【讨论】:

                【解决方案10】:

                对我来说,它是如何工作的,我有两个 Python 的可执行版本,所以 pip install 它安装在一个版本中,但我的可执行路径版本不同,所以它失败了。

                然后我更改了sys环境变量中的路径并安装在Python的可执行版本中,它能够从site-packages中识别包。

                【讨论】:

                  【解决方案11】:

                  对我来说,当我打开另一个项目文件夹时,这发生在 pycharm 中。好像因为我将熊猫安装在新项目文件夹无法访问的文件夹中,所以我的计算机找不到熊猫。

                  我相信 Python 使用脚本文件夹来存储它。

                  我知道当我使用 pip install 时,它会从 python 脚本文件夹中提取,所以我所做的是创建一个名为“everything python”的文件夹,名称无关紧要,并将我的脚本文件夹放在这里。然后将其他文件夹用于其他项目并将它们放在那里并使用“everything python”作为我想要在pycharm中工作的项目。

                  这为我解决了。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2019-05-31
                    • 2018-01-21
                    • 1970-01-01
                    • 1970-01-01
                    • 1970-01-01
                    • 2013-03-11
                    • 1970-01-01
                    • 2012-12-07
                    相关资源
                    最近更新 更多