美文网首页
mac使用pyenv管理python环境

mac使用pyenv管理python环境

作者: 不上进的码农 | 来源:发表于2021-04-14 11:20 被阅读0次

    首先安装pyenv

    brew install pyenv 
    

    执行

    pyenv install --list
    

    查看可安装的python版本
    这里我们选择安装python3.6

    pyenv install 3.6.0
    

    等待半天报错

    Traceback (most recent call last):
      File "/usr/local/opt/pyenv/versions/3.6.0/bin/pyinstaller", line 11, in <module>
        load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')()
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/__main__.py", line 94, in run
        run_build(pyi_config, spec_file, **vars(args))
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/__main__.py", line 46, in run_build
        PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 791, in main
        build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 737, in build
        exec(text, spec_namespace)
      File "<string>", line 16, in <module>
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 213, in __init__
        self.__postinit__()
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/datastruct.py", line 161, in __postinit__
        self.assemble()
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 545, in assemble
        self._check_python_library(self.binaries)
      File "/usr/local/opt/pyenv/versions/3.6.0/lib/python3.6/site-packages/PyInstaller/building/build_main.py", line 629, in _check_python_library
        raise IOError(msg)
    OSError: Python library not found: Python, libpython3.6.dylib, libpython3.6m.dylib, .Python
    This would mean your Python installation doesn't come with proper library files.
    This usually happens by missing development package, or unsuitable build parameters of Python installation.
    
    * On Debian/Ubuntu, you would need to install Python development packages
      * apt-get install python3-dev
      * apt-get install python-dev
    * If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)
    

    解决方法

    % CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" \
    pyenv install --patch 3.8.3 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
    
    python-build: use openssl@1.1 from homebrew
    python-build: use readline from homebrew
    Downloading Python-3.8.3.tar.xz...
    -> https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tar.xz
    Installing Python-3.8.3...
    patching file Misc/NEWS.d/next/macOS/2020-06-24-13-51-57.bpo-41100.mcHdc5.rst
    patching file configure
    Hunk #1 succeeded at 3398 (offset -28 lines).
    patching file configure.ac
    Hunk #1 succeeded at 498 (offset -12 lines).
    python-build: use readline from homebrew
    python-build: use zlib from xcode sdk
    Installed Python-3.8.3 to /Users/pritam/.pyenv/versions/3.8.3
    
    % pyenv versions
    * system (set by /Users/pritam/.pyenv/version)
      3.6.8
      3.6.9
      3.8.0
      3.8.3
    

    原文链接:https://github.com/pyenv/pyenv/issues/1643#issuecomment-655710632
    按照同样的方法可以使用pipenv安装不同版本的python环境了

    相关文章

      网友评论

          本文标题:mac使用pyenv管理python环境

          本文链接:https://www.haomeiwen.com/subject/ilhvkltx.html