我正在使用 pyenv 来管理 python 安装和虚拟环境。我的 Mac (Catalina) 上安装了多个 python。
\n对于一个项目,我需要 python 3.6。我知道 conda 提供了使用特定 python 版本创建虚拟环境的可能性,但我想尝试 pyenv 来管理不同的 python 安装。
\n我遵循安装指南并遵循基本的git check out步骤(对于 zsh)。
\n安装完成后,我可以.pyenv在我的主目录中找到一切似乎都正常。我使用 pyenv 成功安装了 python 3.6。当我运行pyenv versions以列出所有 python 安装(并切换到 conda 安装作为测试)时,输出不包含任何原始 python 安装(请参阅上面的列表)。输出:
\xe2\x96\xb6 pyenv versions\n* system (set by /Users/DVerb5/.pyenv/version)\n 3.6.12\nRun Code Online (Sandbox Code Playgroud)\n我怎样才能让 pyenv 也找到我的其他 python 安装?我尝试做一些研究,似乎是可能的。我看了一下下面的两页,看起来很有希望,但无法弄清楚。
\n\n正如前面提到的,我使用 zsh,这是我的 .zshrc 的内容
\n# If you come from bash you might have to change your $PATH.\n# export PATH=$HOME/bin:/usr/local/bin:$PATH\n\n# Path to your oh-my-zsh installation.\nexport ZSH="/Users/DVerb5/.oh-my-zsh"\n\n# Set name of the theme to load --- if set to "random", it will\n# load a random theme each time oh-my-zsh is loaded, in which case,\n# to know which specific one was loaded, run: echo $RANDOM_THEME\n# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes\nZSH_THEME="avit"\n\n# Set list of themes to pick from when loading at random\n# Setting this variable when ZSH_THEME=random will cause zsh to load\n# a theme from this variable instead of looking in $ZSH/themes/\n# If set to an empty array, this variable will have no effect.\n# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )\n\n# Uncomment the following line to use case-sensitive completion.\n# CASE_SENSITIVE="true"\n\n# Uncomment the following line to use hyphen-insensitive completion.\n# Case-sensitive completion must be off. _ and - will be interchangeable.\n# HYPHEN_INSENSITIVE="true"\n\n# Uncomment the following line to disable bi-weekly auto-update checks.\n# DISABLE_AUTO_UPDATE="true"\n\n# Uncomment the following line to automatically update without prompting.\n# DISABLE_UPDATE_PROMPT="true"\n\n# Uncomment the following line to change how often to auto-update (in days).\n# export UPDATE_ZSH_DAYS=13\n\n# Uncomment the following line if pasting URLs and another text is messed up.\n# DISABLE_MAGIC_FUNCTIONS="true"\n\n# Uncomment the following line to disable colors in ls.\n# DISABLE_LS_COLORS="true"\n\n# Uncomment the following line to disable the auto-setting terminal title.\n# DISABLE_AUTO_TITLE="true"\n\n# Uncomment the following line to enable command auto-correction.\n# ENABLE_CORRECTION="true"\n\n# Uncomment the following line to display red dots whilst waiting for completion.\n# COMPLETION_WAITING_DOTS="true"\n\n# Uncomment the following line if you want to disable marking untracked files\n# under VCS as dirty. This makes repository status check for large repositories\n# much, much faster.\n# DISABLE_UNTRACKED_FILES_DIRTY="true"\n\n# Uncomment the following line if you want to change the command execution time\n# stamp shown in the history command output.\n# You can set one of the optional three formats:\n# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"\n# or set a custom format using the strftime function format specifications,\n# see \'man strftime\' for details.\n# HIST_STAMPS="mm/dd/yyyy"\n\n# Would you like to use another custom folder than $ZSH/custom?\n# ZSH_CUSTOM=/path/to/new-custom-folder\n\n# Which plugins would you like to load?\n# Standard plugins can be found in $ZSH/plugins/\n# Custom plugins may be added to $ZSH_CUSTOM/plugins/\n# Example format: plugins=(rails git textmate ruby lighthouse)\n# Add wisely, as too many plugins slow down shell startup.\nplugins=(\n git\n zsh-syntax-highlighting)\n\nZSH_DISABLE_COMPFIX=true\n\nsource $ZSH/oh-my-zsh.sh\n\n# User configuration\n\n# export MANPATH="/usr/local/man:$MANPATH"\n\n# You may need to manually set your language environment\nexport LANG=en_US.UTF-8\n\n# Preferred editor for local and remote sessions\n# if [[ -n $SSH_CONNECTION ]]; then\n# export EDITOR=\'vim\'\n# else\n# export EDITOR=\'mvim\'\n# fi\n\n# Compilation flags\n# export ARCHFLAGS="-arch x86_64"\n\n# Set personal aliases, overriding those provided by oh-my-zsh libs,\n# plugins, and themes. Aliases can be placed here, though oh-my-zsh\n# users are encouraged to define aliases within the ZSH_CUSTOM folder.\n# For a full list of active aliases, run `alias`.\n#\n# Example aliases\n# alias zshconfig="mate ~/.zshrc"\n# alias ohmyzsh="mate ~/.oh-my-zsh"\n\n# >>> conda initialize >>>\n# !! Contents within this block are managed by \'conda init\' !!\n##__conda_setup="$(\'/opt/anaconda3/bin/conda\' \'shell.bash\' \'hook\' 2> /dev/null)"\n##if [ $? -eq 0 ]; then\n## eval "$__conda_setup"\n##else\n## if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then\n## . "/opt/anaconda3/etc/profile.d/conda.sh"\n## else\n## export PATH="/opt/anaconda3/bin:$PATH"\n## fi\n##fi\n##unset __conda_setup\n# <<< conda initialize <<<\n\n\nalias code="/Applications/Visual\\ Studio\\ Code.app/Contents/Resources/app/bin/code"\n\nexport PYENV_ROOT="$HOME/.pyenv"\nexport PATH="$PYENV_ROOT/bin:$PATH"\nif command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi\n\nRun Code Online (Sandbox Code Playgroud)\n这就是我的路径的样子
\necho $PATH\n/Users/DVerb5/.pyenv/bin:/Users/DVerb5/.pyenv/shims:/Users/DVerb5/.pyenv/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/anaconda3/bin```\nRun Code Online (Sandbox Code Playgroud)\n另外我还注意到which pyenv不起作用。它返回以下内容。(不知道有没有关系)
\xe2\x96\xb6 which pyenv\npyenv () {\n local command\n command="${1:-}"\n if [ "$#" -gt 0 ]\n then\n shift\n fi\n case "$command" in\n (rehash | shell) eval "$(pyenv "sh-$command" "$@")" ;;\n (*) command pyenv "$command" "$@" ;;\n esac\n} \nRun Code Online (Sandbox Code Playgroud)\n
小智 2
如果你通过 pyenv 本身安装它,它就会工作。例如,如果您运行pyenv install 3.7.4,您将获得由 pyenv 管理的 3.7.4。我不知道有什么方法可以让 pyenv 找到以前安装的版本,但是添加新版本确实很容易。