最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Mac中给Python 3.7中安装python库numpy和pandas

安装 crifan 574浏览 0评论
折腾:
【未解决】VSCode中调试Notebook的ipynb文件中的Python代码
期间,本想直接开个终端去安装即可,但是发现当前终端默认是python2:
➜  debugNotebook which python
/Users/crifan/.pyenv/shims/python
➜  debugNotebook python --version
Python 2.7.16
所以指定pip去安装:
➜  debugNotebook /usr/local/opt/python/bin/pip3 install numpy pandas
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    ws.require(__requires__)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 791, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (pip 20.0.2 (/usr/local/lib/python3.7/site-packages), Requirement.parse('pip==19.0.3'))


During handling of the above exception, another exception occurred:


Traceback (most recent call last):
  File "/usr/local/opt/python/bin/pip3", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3191, in <module>
    @_call_aside
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3175, in _call_aside
    f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 3204, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 585, in _build_master
    return cls._build_from_requirements(__requires__)
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 598, in _build_from_requirements
    dists = ws.resolve(reqs, Environment())
  File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'pip==19.0.3' distribution was not found and is required by the application
然后:
➜  debugNotebook python --version
Python 2.7.16
➜  debugNotebook pyenv version
system (set by /Users/crifan/.pyenv/version)
➜  debugNotebook python versions
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'versions': [Errno 2] No such file or directory
➜  debugNotebook which pyenv
pyenv () {
        local command
        command="${1:-}" 
        if [ "$#" -gt 0 ]
        then
                shift
        fi
        case "$command" in
                (rehash | shell) eval "$(pyenv "sh-$command" "[email protected]")" ;;
                (*) command pyenv "$command" "[email protected]" ;;
        esac
}
感觉需要去:
给当前mac全局设置默认的Python3
➜  debugNotebook pip3 install pyenv
Collecting pyenv
  Downloading pyenv-0.0.1.tar.gz (1.4 kB)
Building wheels for collected packages: pyenv
  Building wheel for pyenv (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"'; __file__='"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-wheel-mcsj2jjx
       cwd: /private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/
  Complete output (12 lines):
  running bdist_wheel
  running build
  installing to build/bdist.macosx-10.14-x86_64/wheel
  running install
  ############################ NOTE ############################
  We are sorry, but this package is not installable with pip.
  
  Please read the installation instructions at:
  
  
https://github.com/pyenv/pyenv#installation
  ##############################################################
  
  ----------------------------------------
  ERROR: Failed building wheel for pyenv
  Running setup.py clean for pyenv
Failed to build pyenv
Installing collected packages: pyenv
    Running setup.py install for pyenv ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"'; __file__='"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-record-ic3griwp/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/pyenv
         cwd: /private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/
    Complete output (9 lines):
    running install
    ############################ NOTE ############################
    We are sorry, but this package is not installable with pip.
    
    Please read the installation instructions at:
    
    
https://github.com/pyenv/pyenv#installation
    ##############################################################
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/opt/python/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"'; __file__='"'"'/private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-install-8gki2erw/pyenv/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/46/2hjxz38n22n3ypp_5f6_p__00000gn/T/pip-record-ic3griwp/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7m/pyenv Check the logs for full command output.
➜  ~ which pyenv
pyenv () {
    local command
    command="${1:-}"
    if [ "$#" -gt 0 ]
    then
        shift
    fi
    case "$command" in
        (rehash | shell) eval "$(pyenv "sh-$command" "[email protected]")" ;;
        (*) command pyenv "$command" "[email protected]" ;;
    esac
}
➜  ~ pyenv --version
pyenv 1.2.11
所以去
【已解决】Mac中pyenv安装和设置python 3.7为系统python
确认pip是对的:
➜  cache which pip3
/Users/crifan/.pyenv/shims/pip3
➜  cache pip3 --version
pip 19.0.3 from /Users/crifan/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)
然后再去安装:
pip3 install numpy pandas
然后之前设置的aliyun的源,生效了:
➜  ~ pip3 install numpy pandas
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting numpy
  Downloading http://mirrors.aliyun.com/pypi/packages/2f/5b/2cc2b9285e8b2ca8d2c1e4a2cbf1b12d70a2488ea78170de1909bca725f2/numpy-1.18.1-cp37-cp37m-macosx_10_9_x86_64.whl (15.1MB)
    100% |████████████████████████████████| 15.1MB 1.1MB/s
Collecting pandas
  Downloading http://mirrors.aliyun.com/pypi/packages/ab/ba/f97030b7e8ec0a981abdca173de4e727b3a7b4ed5dba492f362ba87d59a2/pandas-1.0.1-cp37-cp37m-macosx_10_9_x86_64.whl (9.8MB)
    100% |████████████████████████████████| 9.8MB 1.3MB/s
Collecting pytz>=2017.2 (from pandas)
  Downloading http://mirrors.aliyun.com/pypi/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
    100% |████████████████████████████████| 512kB 341kB/s
Collecting python-dateutil>=2.6.1 (from pandas)
  Downloading http://mirrors.aliyun.com/pypi/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
    100% |████████████████████████████████| 235kB 539kB/s
Collecting six>=1.5 (from python-dateutil>=2.6.1->pandas)
  Downloading http://mirrors.aliyun.com/pypi/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
Installing collected packages: numpy, pytz, six, python-dateutil, pandas
Successfully installed numpy-1.18.1 pandas-1.0.1 python-dateutil-2.8.1 pytz-2019.3 six-1.14.0
You are using pip version 19.0.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
然后速度暴快。
顺带升级pip
➜  ~ pip3 install --upgrade pip
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Collecting pip
  Downloading http://mirrors.aliyun.com/pypi/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 2.7MB/s
Installing collected packages: pip
  Found existing installation: pip 19.0.3
    Uninstalling pip-19.0.3:
      Successfully uninstalled pip-19.0.3
Successfully installed pip-20.0.2
➜  ~ pip3 --version
pip 20.0.2 from /Users/crifan/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)
然后也确认,pip就是pi3
➜  ~ which pip
pip: aliased to noglob pip
➜  ~ pip --version
pip 20.0.2 from /Users/crifan/.pyenv/versions/3.7.3/lib/python3.7/site-packages/pip (python 3.7)
然后即可。
【总结】
此处mac中,用pyenv安装了python 3.7后,再去安装:
pip3 install numpy pandas
即可。

转载请注明:在路上 » 【已解决】Mac中给Python 3.7中安装python库numpy和pandas

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
88 queries in 0.115 seconds, using 20.51MB memory