import pandas as pd 导入错误:没有名为 pandas 的模块

thm*_*hmo 6 python import importerror python-3.x pandas

我似乎无法导入 panda 包。我使用 Visual Studio code 来编码。我使用 Mac 并拥有 osX 10.14 Majove。

\n

我试图编译的代码是:

\n
import numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\nhouse_data = pd.read_csv('house.csv')\nplt.plot(house_data['surface'], house_data['loyer'], 'ro', markersize=4)\nplt.show()\n
Run Code Online (Sandbox Code Playgroud)\n

当我尝试使用pip install pandas我的终端时:

\n
(base)  pip install pandas\nRequirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)\nRequirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)\nRequirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)\nRequirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)\nRequirement already satisfied: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)\n(base) Thibaults-MBP-5d47:ML_folder thibaultmonsel$\n
Run Code Online (Sandbox Code Playgroud)\n

然后当我执行我的代码时我得到:

\n
Traceback (most recent call last):\n  File "ML1.py", line 5, in <module>\n    import pandas as pd\nImportError: No module named pandas\n
Run Code Online (Sandbox Code Playgroud)\n

如果我尝试后sudo pip install pandas我得到:

\n
(base) MBP-5d47:ML_folder $ sudo pip3 install pandas --upgrade\nPassword:\nThe directory '/Users/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory.If executing pip with sudo, you may want sudo's -H flag.\nThe directory '/Users/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.\nCollecting pandas\n  Downloading https://files.pythonhosted.org/packages/34/63/529fd1391044051514f2f22d61754245db2133cd37c4dad7150a1cbe2ece/pandas-0.24.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (15.9MB)\n    100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 15.9MB 901kB/s\nRequirement already satisfied, skipping upgrade: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)\nRequirement already satisfied, skipping upgrade: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)\nRequirement already satisfied, skipping upgrade: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)\nRequirement already satisfied, skipping upgrade: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)\nInstalling collected packages: pandas\n  Found existing installation: pandas 0.24.0\n    Uninstalling pandas-0.24.0:\n      Successfully uninstalled pandas-0.24.0\nSuccessfully installed pandas-0.24.1\n
Run Code Online (Sandbox Code Playgroud)\n

然而,我仍然得到no modules named pandas

\n

最后,当我尝试时,pip3 install pandas我得到:

\n
Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.24.0)\nRequirement already satisfied: pytz>=2011k in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2018.9)\nRequirement already satisfied: numpy>=1.12.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (1.15.3)\nRequirement already satisfied: python-dateutil>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas) (2.7.5)\nRequirement already satisfied: six>=1.5 in /Users/Library/Python/3.7/lib/python/site-packages (from python-dateutil>=2.5.0->pandas) (1.12.0)\n
Run Code Online (Sandbox Code Playgroud)\n

当我尝试执行该程序时,我在使用pip3 install pandas...后遇到了上面提到的相同错误。

\n

我还做了一个import.sysif can help :

\n
base)-MBP-5d47:ML_folder $ python help1.py\n2.7.10 (default, Aug 17 2018, 17:41:52)\n[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)]\n
Run Code Online (Sandbox Code Playgroud)\n

这也是我的sys.path

\n
['/Users/Desktop/ML_folder', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']\n
Run Code Online (Sandbox Code Playgroud)\n

PJW*_*PJW 6

您需要安装pandas

pip install pandas

如果您遇到权限问题,您可能需要运行:

sudo pip install pandas

在 Python 3 上您也可能需要运行:

pip3 install pandas(尽管pip可能已经指向pip3)。您可以在这篇 SO post上了解 pip 版本之间的差异。

如果您还没有pip安装,请参阅此处进行安装。