ModuleNotFoundError: No module named 'pandas' when importing module

[亡魂溺海] 提交于 2019-12-02 06:42:25

问题


When running my module directly with as a flask app through Docker with Python 3, which installs pandas based on the requirements.txt file, it runs fine. When I import this module from another app, it doesn't find pandas. The following is my setup.py file.

from setuptools import setup, find_packages

with open('requirements.txt') as f:
    required = f.read().splitlines()

setup(
    name='g_plotter',
    packages=find_packages(),
    #packages=['g_plotter', 'pandas'],
    include_package_data=True,
    """ install_requires=[
        'flask',
    ], """
    install_requires=required,
)

Failure at:

import pandas as pd

Traceback

server_1  |   File "./g_server.py", line 21, in <module>
server_1  |     from g_plotter import Gparser
server_1  |   File "/usr/local/lib/python3.7/site-packages/g_plotter/Gparser.py", line 4, in <module>
server_1  |     import pandas as pd
server_1  | ModuleNotFoundError: No module named 'pandas'

In Docker I don't see pandas being installed:

Step 12/15 : RUN pip3 install ./g_plotter
 ---> Running in 7cc0957f23e6
Processing ./g_plotter
Requirement already satisfied: flask in /usr/local/lib/python3.7/site-packages (from g-plotter==0.0.0) (1.0.2)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.7/site-packages (from flask->g-plotter==0.0.0) (1.1.0)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.7/site-packages (from flask->g-plotter==0.0.0) (2.10)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.7/site-packages (from flask->g-plotter==0.0.0) (0.14.1)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.7/site-packages (from flask->g-plotter==0.0.0) (7.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.7/site-packages (from Jinja2>=2.10->flask->g-plotter==0.0.0) (1.1.0)
Building wheels for collected packages: g-plotter
  Running setup.py bdist_wheel for g-plotter: started
  Running setup.py bdist_wheel for g-plotter: finished with status 'done'
  Stored in directory: /tmp/pip-ephem-wheel-cache-iu6t3zln/wheels/a5/fc/d6/bbda9e5e615cade7b93e6d32cfba9062e2b21ea5352d0c2be0

回答1:


The problem was that I had two setup.py files. One at the root and one in the subdirectory with the rest of the code. I was updating the inner one. Once I move that up and replaced the old one, all the dependencies got installed.



来源:https://stackoverflow.com/questions/53218997/modulenotfounderror-no-module-named-pandas-when-importing-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!