【问题标题】:ModuleNotFoundError: No module named 'pandas' | `pip install pandas` & `poetry add pandas` failModuleNotFoundError:没有名为“pandas”的模块 | `pip install pandas` & `poetry add pandas` 失败
【发布时间】:2021-12-26 18:20:34
【问题描述】:

我之前已经能够运行和安装pandas 库...

包括 IDLE 回溯,在帖子底部。

我开始相信我的设置存在更多潜在的严重问题。真的不知道是什么问题。

$ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

终端:

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ pip install --upgrade pip

Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 722 kB/s 
Installing collected packages: pip
Successfully installed pip-21.3.1

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ pip install pandas
Requirement already satisfied: pandas in /home/me/.local/lib/python3.8/site-packages (1.3.4)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/me/.local/lib/python3.8/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy>=1.17.3; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10" in /home/me/.local/lib/python3.8/site-packages (from pandas) (1.21.3)
Requirement already satisfied: pytz>=2017.3 in /home/me/.local/lib/python3.8/site-packages (from pandas) (2021.3)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.7.3->pandas) (1.14.0)

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry add pandas
Using version ^1.3.4 for pandas

Updating dependencies
Resolving dependencies... (649.1s)

  SolverProblemError

  The current project's Python requirement (>=3.8,<4.0) is not compatible with some of the required packages Python requirement:
    - tensorflow-io-gcs-filesystem requires Python >=3.6, <3.10, so it will not be satisfied for Python >=3.10,<4.0
    - tensorflow-io-gcs-filesystem requires Python >=3.6, <3.10, so it will not be satisfied for Python >=3.10,<4.0
  
      Because no versions of tensorflow match >2.5.0,<2.5.1 || >2.5.1,<2.5.2 || >2.5.2,<2.6.0 || >2.6.0,<2.6.1 || >2.6.1,<2.6.2 || >2.6.2,<2.7.0 || >2.7.0,<3.0.0
   and tensorflow (2.5.1) depends on numpy (>=1.19.2,<1.20.0), tensorflow (>2.5.0,<2.5.2 || >2.5.2,<2.6.0 || >2.6.0,<2.6.1 || >2.6.1,<2.6.2 || >2.6.2,<2.7.0 || >2.7.0,<3.0.0) requires numpy (>=1.19.2,<1.20.0).
      And because tensorflow (2.5.2) depends on numpy (>=1.19.2,<1.20.0), tensorflow (>2.5.0,<2.6.0 || >2.6.0,<2.6.1 || >2.6.1,<2.6.2 || >2.6.2,<2.7.0 || >2.7.0,<3.0.0) requires numpy (>=1.19.2,<1.20.0).
      And because tensorflow (2.6.0) depends on numpy (>=1.19.2,<1.20.0)
   and tensorflow (2.6.1) depends on numpy (>=1.19.2,<1.20.0), tensorflow (>2.5.0,<2.6.2 || >2.6.2,<2.7.0 || >2.7.0,<3.0.0) requires numpy (>=1.19.2,<1.20.0).
      And because tensorflow (2.6.2) depends on numpy (>=1.19.2,<1.20.0)
   and tensorflow (2.5.0) depends on numpy (>=1.19.2,<1.20.0), tensorflow (>=2.5.0,<2.7.0 || >2.7.0,<3.0.0) requires numpy (>=1.19.2,<1.20.0).
      Because no versions of pandas match >1.3.4,<2.0.0
   and pandas (1.3.4) depends on numpy (>=1.20.0), pandas (>=1.3.4,<2.0.0) requires numpy (>=1.20.0).
      Thus, pandas (>=1.3.4,<2.0.0) is incompatible with tensorflow (>=2.5.0,<2.7.0 || >2.7.0,<3.0.0).
  (1) So, because tensorflow (2.7.0) depends on tensorflow-io-gcs-filesystem (>=0.21.0), if pandas (>=1.3.4,<2.0.0) and tensorflow (>=2.5.0,<3.0.0) then tensorflow-io-gcs-filesystem (>=0.21.0).
  
      Because no versions of tensorflow-io-gcs-filesystem match >0.21.0,<0.22.0 || >0.22.0
   and tensorflow-io-gcs-filesystem (0.21.0) requires Python >=3.6, <3.10, tensorflow-io-gcs-filesystem is forbidden.
      And because tensorflow-io-gcs-filesystem (0.22.0) requires Python >=3.6, <3.10, tensorflow-io-gcs-filesystem is forbidden.
      And because if pandas (>=1.3.4,<2.0.0) and tensorflow (>=2.5.0,<3.0.0) then tensorflow-io-gcs-filesystem (>=0.21.0) (1), pandas (>=1.3.4,<2.0.0) is incompatible with tensorflow (>=2.5.0,<3.0.0)
      So, because data-simulator depends on both tensorflow (^2.5.0) and pandas (^1.3.4), version solving failed.

  at ~/.local/share/pypoetry/venv/lib/python3.8/site-packages/poetry/puzzle/solver.py:241 in _solve
      237│             packages = result.packages
      238│         except OverrideNeeded as e:
      239│             return self.solve_in_compatibility_mode(e.overrides, use_latest=use_latest)
      240│         except SolveFailure as e:
    → 241│             raise SolverProblemError(e)
      242│ 
      243│         results = dict(
      244│             depth_first_search(
      245│                 PackageNode(self._package, packages), aggregate_package_nodes

  • Check your dependencies Python requirement: The Python requirement can be specified via the `python` or `markers` properties
    
    For tensorflow-io-gcs-filesystem, a possible solution would be to set the `python` property to ">=3.8,<3.10"
    For tensorflow-io-gcs-filesystem, a possible solution would be to set the `python` property to ">=3.8,<3.10"

    https://python-poetry.org/docs/dependency-specification/#python-restricted-dependencies,
    https://python-poetry.org/docs/dependency-specification/#using-environment-markers

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
Traceback (most recent call last):
  File "cli.py", line 5, in <module>
    from alien import *
  File "/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src/alien.py", line 3, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

建议的解决方案:

卸载,重新安装,再次运行失败。

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ pip uninstall pandas
Found existing installation: pandas 1.3.4
Uninstalling pandas-1.3.4:
  Would remove:
    /home/me/.local/lib/python3.8/site-packages/pandas-1.3.4.dist-info/*
    /home/me/.local/lib/python3.8/site-packages/pandas/*
Proceed (y/n)? Y
  Successfully uninstalled pandas-1.3.4
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ pip install pandas
Collecting pandas
  Using cached pandas-1.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.5 MB)
Requirement already satisfied: pytz>=2017.3 in /home/me/.local/lib/python3.8/site-packages (from pandas) (2021.3)
Requirement already satisfied: python-dateutil>=2.7.3 in /home/me/.local/lib/python3.8/site-packages (from pandas) (2.8.2)
Requirement already satisfied: numpy>=1.17.3; platform_machine != "aarch64" and platform_machine != "arm64" and python_version < "3.10" in /home/me/.local/lib/python3.8/site-packages (from pandas) (1.21.3)
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.7.3->pandas) (1.14.0)
Installing collected packages: pandas
poetry run python3 cli.py
Successfully installed pandas-1.3.4
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
Traceback (most recent call last):
  File "cli.py", line 5, in <module>
    from alien import *
  File "/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src/alien.py", line 3, in <module>
    import pandas as pd
ModuleNotFoundError: No module named 'pandas'

空闲:

Python 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> ls
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    ls
NameError: name 'ls' is not defined
>>> import pandas as pd

Warning (from warnings module):
  File "C:\Users\me\Anaconda3\lib\site-packages\numpy\__init__.py", line 143
    from . import _distributor_init
UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import pandas as pd
  File "C:\Users\me\Anaconda3\lib\site-packages\pandas\__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.8 from "C:\Users\me\Anaconda3\pythonw.exe"
  * The NumPy version is: "1.20.1"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.

>>> 

卸载 Numpy 成功,但安装工具失败

danielbellhv@PF2DCSXD:/mnt/c/Users/dabell/Documents/GitHub/workers-python/workers/data_simulator/src$ pip uninstall -y numpy
Found existing installation: numpy 1.21.3
Uninstalling numpy-1.21.3:
  Successfully uninstalled numpy-1.21.3
danielbellhv@PF2DCSXD:/mnt/c/Users/dabell/Documents/GitHub/workers-python/workers/data_simulator/src$ pip uninstall -y setuptools
Found existing installation: setuptools 45.2.0
Uninstalling setuptools-45.2.0:
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.8/shutil.py", line 791, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/__pycache__/easy_install.cpython-38.pyc' -> '/tmp/pip-uninstall-cmpyrogm/easy_install.cpython-38.pyc'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 164, in exc_logging_wrapper
    status = run_func(*args)
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/commands/uninstall.py", line 97, in run
    uninstall_pathset = req.uninstall(
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 671, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/req/req_uninstall.py", line 384, in remove
    moved.stash(path)
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/req/req_uninstall.py", line 282, in stash
    renames(path, new_path)
  File "/home/danielbellhv/.local/lib/python3.8/site-packages/pip/_internal/utils/misc.py", line 307, in renames
    shutil.move(old, new)
  File "/usr/lib/python3.8/shutil.py", line 812, in move
    os.unlink(src)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3/dist-packages/__pycache__/easy_install.cpython-38.pyc'

更改文件的权限失败:

me@PF2DCSXD:/usr/lib/python3/dist-packages/__pycache__$ chmod 755 easy_install.cpython-38.pyc 
chmod: changing permissions of 'easy_install.cpython-38.pyc': Operation not permitted

请告诉我还有什么我可以尝试或添加到帖子中的内容

【问题讨论】:

  • 您使用虚拟环境吗?如果没有,您可以尝试使用一个吗?
  • 我正在使用包依赖处理程序诗歌。所以我希望它可以在任何环境中的任何机器上运行。还是我应该无论如何?只是以前不需要。
  • 你的 pip 版本是多少?你检查过这个问题github.com/python-poetry/poetry/issues/3894 吗?
  • pip 20.0.2。我会检查那个帖子。
  • 尝试升级您的点子再试一次

标签: python pandas python-poetry modulenotfounderror


【解决方案1】:

尝试以下步骤...

再次卸载并重新安装 pandas

pip uninstall pandas

知道

pip install pandas
or
pip3 install pandas

检查是否安装了 Pandas

import pandas as pd
pd.__version__

【讨论】:

  • 运行时未达到pd.__version__
  • 你为什么要在终端上执行一切?您是否尝试过在 Idle 中执行? 。你有没有在你的电脑/笔记本电脑上安装任何空闲的?
  • No No...首先在 IDLE 中调试,然后在终端上运行.....终端有点乱......当您在 IDLE 上调试时,您可以轻松找到问题所在....总是你必须先在 IDLE 上调试然后运行终端
  • 您需要一些时间才能习惯 IDLE,但作为开发人员,您必须首先在 Idl'es 上开发/调试,然后在终端上运行。关注以下 YouTube 视频......youtu.be/f0ZmRH63Rts
  • 是的,知道检查这个网站exerror.com/…
【解决方案2】:

问题识别:

我尝试了很多东西:pip install -y poetry & pip install -y poetry-core

但是,我的系统中显然还留下了一些诗歌片段。

所以,每当我运行curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 时,它永远不会给出完整的安装反馈。

这是因为:bin/lib/poetry/仍然存在。

可能是由于尝试使用杂项/非正式 pip 命令进行卸载,而不是按照documentation 推荐的方法。

如果您看到类似 Poetry 0.12.0 的内容,那么您就可以使用 Poetry。如果您认为 Poetry 不适合您,您可以通过使用 --uninstall 选项再次运行安装程序或在执行安装程序之前设置 POETRY_UNINSTALL 环境变量来将其从系统中完全删除。

python get-poetry.py --uninstall
POETRY_UNINSTALL=1 python get-poetry.py

解决方案:

rm poetry/ -r.

然后再次尝试安装:

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
Retrieving Poetry metadata

This installer is deprecated. Poetry versions installed using this script will not be able to use 'self update' command to upgrade to 1.2.0a1 or later.
# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

$HOME/.poetry/bin

This path will then be added to your `PATH` environment variable by
modifying the profile file located at:

$HOME/.profile

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing version: 1.1.11
  - Downloading poetry-1.1.11-linux.tar.gz (64.48MB)

Poetry (1.1.11) is installed now. Great!

To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your `PATH`
environment variable. Next time you log in this will be done
automatically.

To configure your current shell run `source $HOME/.poetry/env`

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator$ poetry install
bash: /home/me/.local/bin/poetry: No such file or directory
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator$ poetry run python3 cli.py
bash: /home/me/.local/bin/poetry: No such file or directory
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator$ source $HOME/.poetry/env
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator$ poetry install
Installing dependencies from lock file

Package operations: 82 installs, 0 updates, 0 removals

...
  • Installing numpy (1.19.5)
...
  • Installing pandas (1.3.1)
...

【讨论】:

  • 我现在感觉自己是一个真正的 SO 用户
猜你喜欢
  • 1970-01-01
  • 2012-04-30
  • 2021-02-06
  • 2020-09-02
  • 2018-05-16
  • 1970-01-01
  • 2023-02-09
  • 2019-02-13
  • 1970-01-01
相关资源
最近更新 更多