简体   繁体   English

尝试使用脚本在 Atom 中导入熊猫时出现导入错误

[英]ImportError when trying to import pandas in Atom using script

I've installed pandas using pip3 .我已经使用pip3安装了熊猫。 I'm able to import pandas in the MacOS terminal without issue, but whenever I try to import it in Atom, using the script package, I get an error.我可以在 MacOS 终端中毫无问题地导入pandas ,但是每当我尝试在 Atom 中使用脚本包导入它时,我都会收到错误消息。 This error is:这个错误是:

ImportError: No module named pandas导入错误:没有名为 Pandas 的模块

I don't get this error when trying to import numpy in Atom.尝试在 Atom 中导入numpy时,我没有收到此错误。

I assume you are using Script package to run python scripts in Atom.我假设您使用 Script 包在 Atom 中运行 python 脚本。 Following approach worked for me.以下方法对我有用。

Lets first check which python version Atom is using.让我们首先检查 Atom 使用的是哪个 python 版本。 Try this in Atom.在 Atom 中试试这个。

import sys
print('Python: {}'.format(sys.version))

If you see output as python version 2.x then如果您看到输出为 python 版本 2.x 那么

  1. Point Atom to use python 3 by updating Atom ->Preferences -> Open Config Folder ->Packages -> Script->lib->grammars->python.coffee.通过更新 Atom ->Preferences -> Open Config Folder ->Packages -> Script->lib->grammars->python.coffee 指向 Atom 使用 python 3。 Change command: 'python' to command: 'python3' .将命令: 'python' 更改为命令: 'python3' 。
  2. Save and Close Atom.保存并关闭原子。
  3. Run your code again to check python version.再次运行您的代码以检查 python 版本。 Now it should say 3.x现在它应该说 3.x
  4. pip install pandas pip 安装熊猫

You can run following python code in atom to check versions of commonly used python libraries for ML.您可以在 atom 中运行以下 python 代码来检查 ML 常用的 python 库的版本。


# Check the versions of libraries

# Python version
import sys
print('Python: {}'.format(sys.version))
# scipy
import scipy
print('scipy: {}'.format(scipy.__version__))
# numpy
import numpy
print('numpy: {}'.format(numpy.__version__))
# matplotlib
import matplotlib
print('matplotlib: {}'.format(matplotlib.__version__))
# pandas
import pandas
print('pandas: {}'.format(pandas.__version__))
# scikit-learn
import sklearn
print('sklearn: {}'.format(sklearn.__version__)) 

i had this in some new files I created to test Pandas, but on closer inspection I found I was missing this line in my new files, as I was adding the library:我在为测试 Pandas 而创建的一些新文件中有这个,但仔细检查后我发现我在新文件中缺少这一行,因为我正在添加库:

#!/usr/local/bin/python3

On adding this definition it worked perfectly via Python3.添加此定义后,它可以通过 Python3 完美运行。

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

相关问题 尝试在 Docker 中运行 Python 脚本时出现“ImportError: cannot import name...” - “ImportError: cannot import name…” when trying to run Python script in Docker 使用导入时的ImportError - ImportError when using import as 尝试在 Python 中导入自定义模块时出现 ImportError - ImportError when trying to import a custom module in Python 尝试在Python中导入Prov模块时出现ImportError - ImportError when trying to import Prov Module in Python 尝试导入软件包pyRserve时出现ImportError - ImportError when trying to import package pyRserve 尝试导入时的 ModuleNotFoundError 和 ImportError 可以 package - ModuleNotFoundError and ImportError when trying to import can package 尝试从脚本中的子目录导入共享模块时的相对路径 ImportError - Relative path ImportError when trying to import a shared module from a subdirectory in a script 尝试导入Stem时出现“ ImportError:无法导入名称连接” - “ImportError: cannot import name connect” when trying to import Stem Atom:Pylint-尝试导入numpy时为假阴性 - Atom: Pylint - false negative when trying to import numpy ImportError:无法导入名称 <module> 仅在从原子运行文件时 - ImportError: cannot import name <module> only when running file from atom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM