【问题标题】:PyCharm and external librariesPyCharm 和外部库
【发布时间】:2014-03-19 23:27:05
【问题描述】:

我已经开始使用 PyCharm IDE,但我无法确定如何在那里管理外部库。例如,PyCharm 看不到matplotlib。在 PyCharm 的文件管理器中,我清楚地看到了外部库的列表,并且没有 matplotlib。但是,我已经安装了它并且我知道它的位置。

如何将这个库添加到 PyCharm 环境中?

【问题讨论】:

    标签: matplotlib pycharm


    【解决方案1】:

    我建议使用 Python 虚拟环境。使用 PyCharm 真的很容易。

    PyCharm > 首选项... > 项目解释器 > Python 解释器

    单击“创建虚拟环境”并选择您的基本解释器。

    单击“安装”并安装您需要的任何软件包。如果默认存储库不包含所需的库,您还可以添加其他存储库。另一个好处是您可以看到哪些库有更新的版本并且可以更新。

    【讨论】:

    • 仅供参考 - 对于 Windows PyCharm Comm v.2016.2,菜单略有不同。 File->Default Settings...->Project Interpreter
    • @kukido 这是否为每个项目安装了 matplotlib 的副本?假设我的工作区中有 5 个项目,并且我为所有项目添加了 matplotlib,这会创建 5 个 matplotlib 副本吗?
    【解决方案2】:

    我认为解决问题的一种方法是通过 File -> Settings -> Python Interpreters 在 PyCharm 中指定您的解释器

    此设置中还有一个Paths 选项卡,您需要在此处明确添加 matplotlib 的路径。但对我来说,那里没有列出特殊的路径。这是我在此选项卡中的路径:

    file://D:/hg_work/vefw_regression/tools/python/DLLs
    file://D:/hg_work/vefw_regression/tools/python/Lib
    file://D:/hg_work/vefw_regression/tools/python/Lib/lib-tk
    文件://D:/hg_work/vefw_regression/tools/python
    file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages(我的 matplotlib/numpy 和其他东西在这里)
    file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/win32
    file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/win32/lib
    file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/pythonwin
    file://D:/Users/svecovs/AppData/Roaming/JetBrains/PyCharm 社区版 3.0.1/helpers/python-skeletons
    file://D:/hg_work/vefw_regression/tools/python/Lib/site-packages/core(由用户添加)

    【讨论】:

    • 当我在命令行默认 python 解释器中运行这个脚本时,一切顺利。我只有使用 Pycharm 才会遇到问题。在 PyCharm 配置界面的 PATH 选项卡中,我添加了 matplotlib 的路径,但仍然收到相同的错误消息。
    • 对我来说,也没有任何特殊库的路径。
    • PyCharm 可以拥有自己的 python 解释器路径。例如,我的 Windows PATH 中有 D:/python/(命令行采用此),但 PyCharm 配置为在外部服务器上使用 python:Python 2.7.3 (D:/hg_work/vefw_regression/tools/python/python.exe) 在提到的Python Interpreters 选项卡上
    • 我找到了解决方案。您说得部分正确,问题与选择正确的 python 解释器有关。我已经为 python 2.7 版安装了 matplotlib,但是 PyCharm 是为 3.0 版配置的,当我将它切换到 2.7 版时,一切正常。
    • 注意路径已经不存在了,你必须去项目解释器-wheel-more-显示所选解释器的路径stackoverflow.com/a/24206781/1136458
    【解决方案3】:

    安装 matplotlib,然后 python-tk.Pycharm 将运行良好。它在 Ubuntu 16.04 上为我工作。

    sudo apt-get install python-tk

    sudo apt-get install python-matplotlib

    【讨论】:

      【解决方案4】:

      对于 Linux 用户,这里有一个解决方案, 先在终端里写这个命令,

      sudo apt-get install python-matplotlib
      

      现在你已经完成了,你将能够在 File>>>settings>>project interpreter 中看到 matplotlib。 Image

      【讨论】:

        【解决方案5】:

        通过选择系统解释器解决这个问题。

        【讨论】:

          猜你喜欢
          • 2014-08-03
          • 1970-01-01
          • 2015-03-09
          • 2014-03-25
          • 1970-01-01
          • 1970-01-01
          • 2018-08-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多