【问题标题】:ImportError: No module named dashImportError:没有名为 dash 的模块
【发布时间】:2018-11-09 06:15:35
【问题描述】:

我无法在生产服务器中安装 dash。在本地,我通过

导入
pip install dash==0.29.0

但在 prod 中它不起作用。当我使用

sudo apt-get install python dash

它的显示

> "dash is already the newest version (0.5.8-2.4)"

,但是在使用 import dash 时,我得到了

> "ImportError: No module named dash"

也试过了

sudo pip install python dash==0.29.0

但它给出了以下错误:

Requirement already satisfied: python in /usr/lib/python2.7/lib-dynload
Collecting dash==0.29.0
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 792, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 386, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.7-py2.py3-none-any.whl/cachecontrol/adapter.py", line 47, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.12.4-py2.py3-none-any.whl/requests/adapters.py", line 423, in send
    timeout=timeout
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 643, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 315, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

【问题讨论】:

  • 你使用哪个python版本来导入dash?
  • 您是否正在为 python 2 安装,即 pip 并尝试在 python3 上运行它?,在这种情况下使用 pip3 install dash==0.29.0
  • 不,我的python版本是2.7。我没有在 python3 中运行它
  • @SoubhikBanerjee 当您尝试 pip install dash==0.29.0 时,究竟是什么错误?
  • @SoubhikBanerjee 看看this

标签: python plotly-dash


【解决方案1】:

命令sudo apt-get install python dash 安装system 包python(正确)和systemdash(不正确),即linux shell

sudo apt-get install python安装Python后,要安装python package dash,你需要做sudo pip install dash==0.29.0sudo python -m pip install dash==0.29.0

【讨论】:

  • 尝试了同样的方法,但没有运气。它给出错误:文件“/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/connectionpool.py”,第 643 行,在 urlopen _stacktrace=sys.exc_info() [2]) 文件“/usr/share/python-wheels/urllib3-1.19.1-py2.py3-none-any.whl/urllib3/util/retry.py”,第 315 行,增量总计 -= 1 TypeError : -=: 'Retry' 和 'int' 不支持的操作数类型
  • urllib3 1.19.1 was released on 2016-11-16。也许尝试升级到更新的东西。做pip install --upgrade urllib3.
  • 顺便说一句,我已经回答了你原来的问题,AlbinPaul 已经评论了你的 new 问题。见How does accepting an answer work? & What should I do when someone answers my question?
【解决方案2】:

据我所知——而且我非常环保——似乎 python/environments 在适当的“站点包”目录中按文件名扫描模块。我已经通过命令提示符为我的系统 python 安装了 Dash,然后还通过 anaconda 命令提示符安装了 Dash。

当我尝试通过 anaconda 在 Spyder 中导入 dash 时,我遇到了同样的错误。我能够通过将包含 init 文件的文件夹从 dash_rendered 重命名为 just dash 来解决此问题。

看起来,当 Spyder 扫描它的包时,它可以识别正确的目录。

使用 Plotly 在命令行中提供的命令,我通常可以轻松地将 dash 安装到 python。

pip install dash==1.7.0

我可以看到这是一年前的事情,从那时起 Dash 发生了一些变化 - 但希望这可以帮助未来的用户,因为他们的环境在没有重命名的情况下无法将模块识别为“dash”,就像在 Spyder 中一样。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,我在 conda 终端上运行 pip install dash 解决了它(如果您使用的是 Anaconda)。

    【讨论】:

      【解决方案4】:

      创建虚拟环境:

      virtualenv venv # creates a virtualenv called "venv"
      source venv/bin/activate # uses the virtualenv
      

      然后pip install dash

      【讨论】:

        【解决方案5】:

        如果您使用的是 Jupyter notebook 或 Jupyter Lab,请尝试install jupyter-dash by:

        pip install jupyter-dash
        

        在代码中:

        from jupyter_dash import JupyterDash
        
        pd.options.plotting.backend = "plotly"
        

        【讨论】:

        • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
        【解决方案6】:

        file>NewProjectsSetup>Preferencesfornewprojects>PythonInterpreter> 点击+号搜索包,搜索破折号,安装包就可以了。

        【讨论】:

        • 该问题未指定任何 IDE,但您的答案似乎特定于某些 IDE。请提出通用解决方案或添加更多详细信息
        猜你喜欢
        • 2013-03-11
        • 2012-12-07
        • 2017-04-10
        • 2012-05-23
        • 2019-07-29
        • 2015-07-04
        • 2014-03-15
        • 2017-12-29
        • 2014-09-12
        相关资源
        最近更新 更多