簡體   English   中英

ImportError:沒有名為 pandas 的模塊

[英]ImportError: No module named pandas

我正在嘗試用 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

你錯過了幾個(不是很清楚)步驟。 Pandas 通過 pip 作為輪子分發,這意味着您需要執行以下操作:

pip install wheel
pip install pandas

在此之后您可能會遇到其他問題 - 看起來您正在 Windows 上安裝,這對NumPySciPyPandas不是最友好的目標。 或者,您可以從此處獲取二進制安裝程序。

您在安裝 NumPy 時也遇到了錯誤。 像以前一樣,我建議為此使用二進制安裝程序,因為這不是一個簡單的過程。 但是,您可以通過從 Microsoft 安裝此程序包來解決您當前的錯誤。

雖然完全有可能在 Windows 上獲得完美的環境設置,但我發現通過設置Debian VM 極大地提高了 Python 開發人員的生活質量。 尤其是使用科學包,你會遇到很多這樣的情況。

我只是遇到了問題,我一直在安裝和卸載。 事實證明,當您將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並使用python3 file_name.py運行程序。

我用以下命令解決了同樣的問題......

在終端上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

祝你好運!

當我嘗試構建 docker 鏡像zeppelin-highcharts時,我發現基礎鏡像 openjdk:8 也沒有安裝 pandas。 我用這個步驟解決了它。

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

我提到了在系統范圍內安裝 pip 和 virtualenv 的官方“首選”方式是什么? .

如果你在 Ubuntu 上並使用內置的 Python 3,你可以像這樣在終端中從 Ubuntu 存儲庫安裝它:

sudo apt install python3-pandas

以上適用於 Ubuntu 20.04 LTS,根據您的版本略有不同。

如果您運行的是 Python 3.9 版,那么 Pandas 將無法運行。 所以安裝 Python 3.7 或更低版本來緩解這個問題。

或者,如果您想堅持使用 Python 3.9,請嘗試通過編譯庫來安裝 Pandas。

嘗試這個:

python -m pip install pandas

截至 2020 年 12 月,我在通過pyenv安裝python v 3.8.6時遇到了同樣的問題。 所以,我開始了:

  1. 通過Homebrew安裝 pyenv , brew install 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,請務必先卸載,否則可能會報錯。

  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

對我來說,它是如何工作的,我有兩個 Python 的可執行版本,所以 pip install 它安裝在一個版本中,但是我的可執行路徑版本不同,所以它失敗了。

然后我更改了 sys 環境變量中的路徑並安裝在 Python 的可執行版本中,它能夠從站點包中識別包。

對我來說,當我打開另一個項目文件夾時,這發生在 pycharm 中。 好像因為我將熊貓安裝在新項目文件夾無法訪問的文件夾中,所以我的計算機找不到熊貓。

我相信 Python 使用腳本文件夾來存儲它。

我知道當我使用 pip install 時,它會從 python 腳本文件夾中提取,所以我所做的是創建一個名為“everything python”的文件夾,名稱無關緊要,並將我的腳本文件夾放在這里。 然后將其他文件夾用於其他項目並將它們放在那里並使用“everything python”作為我想在pycharm中處理的項目。

這為我解決了。

如果使用 python 3,使用 pip3 而不是 pip

python 3: pip3 install pandas

這適用於那些厭倦了上述答案但仍有問題的人。 您應該執行以下操作:

  1. 通過運行它找出你正在使用的 python 版本

蟒蛇--版本

  1. 根據您使用的 Python 版本,運行以下操作之一:

pip3.10 安裝熊貓

或者

pip3.9 安裝熊貓

或者

pip3.8 安裝熊貓

等等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM