编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

Mac 上安装 pyenv 使用多版本python开发项目

wxchong 2024-09-12 21:54:12 开源技术 6 ℃ 0 评论



安装 pyenv

~ % brew install pyenv

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 19 formulae.
......
For compilers to find readline you may need to set:
  export LDFLAGS="-L/usr/local/opt/readline/lib"
  export CPPFLAGS="-I/usr/local/opt/readline/include"
For pkg-config to find readline you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"

把pyenv加到环境变量PATH里面

~ % echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc

~ % more ~/.zshrc

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

重新启动shell,检查pyenv 安装成功

~ % exec "$SHELL"

~ % pyenv help

Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
   --version   Display the version of pyenv
   commands    List all available pyenv commands
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   local       Set or show the local application-specific Python version(s)
   prefix      Display prefix for a Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall a specific Python version
   version     Show the current Python version(s) and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

安装多版本python

~% pyenv install 2.7.6

python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-2.7.6.tgz...
-> https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
......

如果有错误发生,在这个链接里面找一找解决方法 :https://github.com/pyenv/pyenv/wiki/Common-build-problems

安装成功后,python 安装在: /Users/xxx/.pyenv/versions/2.7.6/bin

安装其它版本python 也是在这个versions目录下面

设定当前工作的python版本

~%pyenv global 2.7.6

好了,看使用python多版本开发吧

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表