在Mac OS上的Python安装模块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Mac OS上的Python安装模块相关的知识,希望对你有一定的参考价值。

我是Python和终端提示/安装的新手,在尝试安装Pandas之类的模块时,我一直遇到安装错误。

我尝试过“ pip install pandas”。我得到以下结果:

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Collecting pandas
  Using cached pandas-0.24.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 (16.7 MB)
Collecting python-dateutil>=2.5.0
  Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Requirement already satisfied: pytz>=2011k in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas) (2013.7)
Collecting numpy>=1.12.0
  Using cached numpy-1.16.6-cp27-cp27m-macosx_10_9_x86_64.whl (13.9 MB)
Requirement already satisfied: six>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from python-dateutil>=2.5.0->pandas) (1.12.0)
ERROR: matplotlib 1.3.1 requires nose, which is not installed.
ERROR: matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: python-dateutil, numpy, pandas
  WARNING: The scripts f2py, f2py2 and f2py2.7 are installed in '/Users/Mariposa/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.16.6 pandas-0.24.2 python-dateutil-2.8.1

再次运行并获得以下内容:

xx-mac-mini:~ Mariposa$ pip install pandas
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pandas in ./Library/Python/2.7/lib/python/site-packages (0.24.2)
Requirement already satisfied: python-dateutil>=2.5.0 in ./Library/Python/2.7/lib/python/site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2011k in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pandas) (2013.7)
Requirement already satisfied: numpy>=1.12.0 in ./Library/Python/2.7/lib/python/site-packages (from pandas) (1.16.6)
Requirement already satisfied: six>=1.5 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from python-dateutil>=2.5.0->pandas) (1.12.0)

当我运行版本测试时,找不到它,并且我无法在.py执行中成功导入。

xx-mac-mini:~ Mariposa$ pandas --version
-bash: pandas: command not found
xx-mac-mini:~ Mariposa$ numpy --version
-bash: numpy: command not found
xx-mac-mini:~ Mariposa$ python --version
Python 2.7.16
xx-mac-mini:~ Mariposa$ pip --version
pip 20.0.2 from /Library/Python/2.7/site-packages/pip (python 2.7)

[其他任何形式的安装,例如“ sudo pip install”或“ pip3 install”,以下错误:

Collecting pandas
  Could not find a version that satisfies the requirement pandas (from versions: )
No matching distribution found for pandas 

我是不是以某种方式安装在错误的目录中,或者没有对python3和pip3版本兼容性进行正确区分?不知道为什么这么难。感谢您的见解。

答案

正如评论中已经说过的,pip为python2安装模块。另外,您不能在shell上将pandas作为命令运行。

[pip3 install pandas]在python3上对我有用,它是直接从python website上的Mac安装程序包安装的。

>pip3 install pandas
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/ab/ba/f97030b7e8ec0a981abdca173de4e727b3a7b4ed5dba492f362ba87d59a2/pandas-1.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (9.8MB)
    100% |████████████████████████████████| 9.8MB 2.8MB/s 

如果您使用其他方法安装了python3,则可能需要以其他方式安装软件包或以某种方式配置python安装。

以上是关于在Mac OS上的Python安装模块的主要内容,如果未能解决你的问题,请参考以下文章

利用Python进行windows系统键盘控制功能(Mac OS系统也可以)

Mac OS 上的 Cartopy 安装:Python 3.8 和 Matplotlib 3.3.3

在 Mac OS X 上的 python 2.7 和 python 3.5 之间切换

如何在 mac os x (10.9) 上的 python 中安装 libgpuarray 和 clBLAS?

Mac OS X 上的 Qt 库和源代码安装在哪里?

Mac OS安装Python环境介绍