【问题标题】:Install Pandas on Mac with pip使用 pip 在 Mac 上安装 Pandas
【发布时间】:2017-07-25 18:38:45
【问题描述】:

我正在尝试使用pip 安装Pandas,但遇到了问题。以下是详细信息:

Mac OS Sierra
which python => /usr/bin/python
python --version => Python 2.7.10
Inside "/System/Library/Frameworks/Python.framework/Versions" there is the following
2.3 2.5 2.6 2.7 Current

我希望 pandas 链接到“/usr/bin/python”中的Python 2.7.10

当我执行pip install pandas 时,我收到以下错误消息:

Collecting pandas
  Using cached pandas-0.19.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl

Requirement already satisfied: pytz>=2011k in 

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas)

Requirement already satisfied: python-dateutil in 

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas)

Requirement already satisfied: numpy>=1.7.0 in 

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas)

Installing collected packages: pandas

Exception:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
    **kwargs

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)

  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
    os.makedirs(path)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)

OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pandas'

感谢您的帮助。

【问题讨论】:

  • 尝试以 sudo 运行它。 sudo pip install pandas
  • @abccd,你是对的
  • @bdeo,这有效:-) 你能解释一下为什么有效吗?谢谢,只是为了让我对发生的事情有所了解,
  • 为了在它们需要的目录中创建文件(pandas 包),您需要成为系统的超级用户,因为它们存在于系统文件中,而不是您的用户文件中.

标签: python macos pandas pip


【解决方案1】:

尝试以 sudo 运行 pip install 命令。

sudo pip install pandas

Python 软件包安装在操作系统文件系统中,并非所有用户都有写入文件的权限。这就是您需要以 sudo 身份运行命令的原因,因为 sudo 提升了您执行此操作的权限。

编辑:这似乎得到了一些支持,所以我已经为这个关于用户特定安装的问题添加了一些清晰度。如果这适合您的用例,您也可以为您的用户安装它:pip install --user pandas

【讨论】:

    【解决方案2】:

    对于使用 mojave 的 mac 终端与

    pip3 install pandas
    

    pip3 install --upgrade pip
    

    之后

    pip install pandas
    

    【讨论】:

    • 完成,已满足遮蔽要求。但是,导入后显示错误,ModuleNotFoundError: No module named 'pandas'
    【解决方案3】:

    如果你使用的是 Python 3.0,pip3 install pandas 而不是 pip install pandas 应该可以解决问题

    【讨论】:

      【解决方案4】:

      在终端窗口上运行 pip3 install pandas 在 MAC 操作系统上对我有用。

      【讨论】:

        【解决方案5】:

        是的,使用sudo 运行应该可以解决问题。虽然是frowned upon。你也可以这样做: pip install --user <packagename>

        另外,我强烈建议使用anaconda 为您管理python 版本。

        【讨论】:

          【解决方案6】:

          除了其他答案之外,我还必须考虑使用 MacOS 上的一些编译器特定问题

          sudo CFLAGS='-Wno-implicit-function-declaration' pip3 install pandas
          

          【讨论】: