Pyenv not picking up other python installations

我怕爱的太早我们不能终老 提交于 2021-01-27 11:26:09

问题


I am using pyenv to manage python installations and virtual environments. I have several python installations on my Mac (Catalina).

  • The system python (python 2.7 in usr/bin)
  • python 3.9 in usr/bin (coming from default installer from python.org/downloads)
  • python 3.9 in /opt/anaconda3/bin/python3 (coming from https://www.anaconda.com/products/individual)

For a project, I would need python 3.6. I know that conda offers the possibility to create virtual environments with a specific python version, but I wanted to try out pyenv to manage the different python installs.

I followed the installation guide and followed the basic git check out steps (for zsh).

After the installation, I could find .pyenv in my home directory and everything seemed to be okay. I successfully installed python 3.6 using pyenv. When I ran pyenv versions in order to list all my python installs (and switch to my conda install as a test) the output didn't contain any of my original python installations (see list above). The output:

▶ pyenv versions
* system (set by /Users/DVerb5/.pyenv/version)
  3.6.12

How can I make it that pyenv also finds my other python installations? I tried doing some research and it seems to be possible. I took a look at the two pages below, which seemed promising, but wasn't able to figure it out.

  • Installing anaconda with pyenv, unable to configure virtual environment
  • https://wilsonmar.github.io/pyenv/

As mentioned earlier I use zsh, this is the content of my .zshrc

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/Users/DVerb5/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="avit"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and another text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable the auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
    git
    zsh-syntax-highlighting)

ZSH_DISABLE_COMPFIX=true

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
##__conda_setup="$('/opt/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
##if [ $? -eq 0 ]; then
##    eval "$__conda_setup"
##else
##    if [ -f "/opt/anaconda3/etc/profile.d/conda.sh" ]; then
##        . "/opt/anaconda3/etc/profile.d/conda.sh"
##    else
##        export PATH="/opt/anaconda3/bin:$PATH"
##    fi
##fi
##unset __conda_setup
# <<< conda initialize <<<


alias code="/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi

And this is what my PATH looks like

echo $PATH
/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```

In addition I also noticed which pyenv doesn't work. It returns the following. (I don't know if it's related)

▶ which pyenv
pyenv () {
    local command
    command="${1:-}"
    if [ "$#" -gt 0 ]
    then
        shift
    fi
    case "$command" in
        (rehash | shell) eval "$(pyenv "sh-$command" "$@")" ;;
        (*) command pyenv "$command" "$@" ;;
    esac
} 

回答1:


If you install it through pyenv itself, it will work. For example, if you run pyenv install 3.7.4 then you'll get 3.7.4 managed by pyenv. I don't know of any way to make pyenv find previously installed versions, but it's really easy to add new ones.



来源:https://stackoverflow.com/questions/65637759/pyenv-not-picking-up-other-python-installations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!