在Mac上使用pip安装Pandas

5
我正在尝试使用 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'

感谢您的帮助。

2
尝试以sudo身份运行。sudo pip install pandas - Brandon Deo
@abccd,你是正确的。 - user58925
@bdeo, 运行成功了 :-)能否请你解释一下为什么它能运行成功?谢谢,只是为了让我对正在发生的事情有些了解。 - user58925
为了在正确的目录中创建文件(使用pandas包),您需要成为系统的超级用户,因为它们存储在系统文件中而不是用户文件中。 - Brandon Deo
6个回答

14

尝试以sudo身份运行pip install命令。

sudo pip install pandas

Python包安装在操作系统的文件系统中,而不是所有用户都可以写入文件的地方。这就是为什么您需要使用sudo命令运行,因为sudo可以提升您的权限来执行此操作。

编辑:由于这个问题似乎得到了一些赞同,所以我在关于用户特定安装方面进行了一些澄清。如果符合您的用例,您也可以仅为您的用户安装它:pip install --user pandas


6

对于使用Mojave的Mac终端,可以使用以下命令:

pip3 install pandas

或者
pip3 install --upgrade pip

之后

pip install pandas

完成了,沙盈的要求已经满足。但是,在导入后显示错误,ModuleNotFoundError: No module named 'pandas'。 - Vineesh TP

4

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


2
在终端窗口上运行pip3 install pandas对我在MAC OS上起了作用。

1

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

此外,我强烈建议使用anaconda来管理Python版本。


0

除了其他答案,我还需要考虑在MacOS上使用时一些特定于编译器的问题。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接