简体   繁体   English

如何将 Pandas 库导入 PyCharm?

[英]How do I import Pandas library into PyCharm?

I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error: ModuleNotFoundError: No module named 'pandas' I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error: ModuleNotFoundError: No module named 'pandas'

I have tried to uninstall and install again many times but nothing seems to work.我曾多次尝试卸载并再次安装,但似乎没有任何效果。 Does anybody know a solution to this?有谁知道解决这个问题?

I think you have to choose the right python interpreter .我认为您必须选择正确的python interpreter Check my screenshot检查我的截图

在此处输入图像描述

You likely have multiple copies of Python installed on your system.您的系统上可能安装了 Python 的多个副本。 PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. PyCharm 可以配置为在您的系统上使用任何版本的 Python,包括您定义的任何虚拟环境。 The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.

There are two places where you specify a Python version.有两个地方可以指定 Python 版本。 First of all, your Project has a version associated with it.首先,您的项目有一个与之关联的版本。 Check the "Python Interpreter" section of the "Project" section of your Preferences for that.检查您的首选项的“项目”部分的“Python解释器”部分。 That version is used for syntax highlighting, code completion, etc.该版本用于语法高亮、代码完成等。

By default, the abovementioned Python version will also be used to run your code.默认情况下,上述 Python 版本也将用于运行您的代码。 But you can change the version of Python that your code is run with by creating or modifying a Run Configuration.但是您可以通过创建或修改运行配置来更改运行代码的 Python 的版本。 To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.为此,请检查 PyCharm window 左上角附近的运行和调试工具栏按钮旁边的菜单。

When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about.当您进入首选项的 Python 解释器部分时,您会发现您可以看到为 Z4149CE0EE30A909A1F62C583FF20C2 知道的每个 Python 版本安装的所有模块。 You can use this to check to see if Pandas is installed for a particular Python version.您可以使用它来检查是否为特定的 Python 版本安装了 Pandas。

I would suggest you get comfortable with all that I've said above.我建议您对我上面所说的一切感到满意。 It will save you many headaches in the future.它将在将来为您省去很多麻烦。

You can try downloading the library from PyCharm settings:您可以尝试从 PyCharm 设置下载库:

  1. File -> Settings文件 -> 设置
  2. then, Project: -> Python Interpreter然后,项目:-> Python 解释器
  3. Click a + sign to the right,点击右侧的+号,
  4. Search for the pandas library,搜索pandas库,
  5. and finally, press 'Install Package'最后,按“安装包”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM