Comments (6)
Thanks @native-api. I think more is going on that what you describe based on this inconsistent behavior with conda
, a tool that comes with the anaconda installation via pyenv. See below for a demo of what I am talking about.
➜ ~ mkdir code/show-native-api
➜ ~ cd code/show-native-api
➜ show-native-api pyenv local anaconda3-2023.03
(anaconda3-2023.03) ➜ show-native-api ls -la
total 8
drwxr-xr-x 3 steven staff 96 Apr 17 18:58 .
drwxr-xr-x 26 steven staff 832 Apr 17 18:57 ..
-rw-r--r-- 1 steven staff 18 Apr 17 18:58 .python-version
(anaconda3-2023.03) ➜ show-native-api conda create --name show-native-api
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /Users/steven/.pyenv/versions/anaconda3-2023.03/envs/show-native-api
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate show-native-api
#
# To deactivate an active environment, use
#
# $ conda deactivate
(anaconda3-2023.03) ➜ show-native-api conda activate show-native-api
(show-native-api) (anaconda3-2023.03) ➜ show-native-api echo "pretty prompt"
pretty prompt
(show-native-api) (anaconda3-2023.03) ➜ show-native-api zsh -l
➜ show-native-api echo "no prompt, but yes pyenv activate?"
no prompt, but yes pyenv activate?
➜ show-native-api pyenv version
anaconda3-2023.03 (set by /Users/steven/code/show-native-api/.python-version)
➜ show-native-api echo "seems activated, let's activate the conda virtual envir
onment"
seems activated, let's activate the conda virtual environment
➜ show-native-api conda activate show-native-api
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
➜ show-native-api echo "not good"
not good
➜ show-native-api cd .. && cd -
~/code/show-native-api
➜ show-native-api conda activate show-native-api
CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run
$ conda init <SHELL_NAME>
Currently supported shells are:
- bash
- fish
- tcsh
- xonsh
- zsh
- powershell
See 'conda init --help' for more information and options.
IMPORTANT: You may need to close and restart your shell after running 'conda init'.
➜ show-native-api echo "still not good"
still not good
➜ show-native-api cd ..
➜ code cd -
~/code/show-native-api
(anaconda3-2023.03) ➜ show-native-api conda activate show-native-api
(show-native-api) (anaconda3-2023.03) ➜ show-native-api echo "now it's good"
now it's good
from pyenv-virtualenv.
Diagnosed the issue. The environment is actually still active in the subshell (all the revelant envvars are set), it just disappears from the prompt because PS1
is reset by /etc/zshrc
's code.
from pyenv-virtualenv.
In any case, I was writing a fix by detecting this situation (PS1
is reset to the original value), but is stumped by the fact that when pyenv-sh-activate
code runs, PS1
appears to the blank (expands to a blank value) -- so I cannot check it.
Do you know anything about that? This seems to be another one of Zsh's quirks. Googling and checking the man pages came up empty so far.
from pyenv-virtualenv.
No, I didn't know this, but I do see the message from time to time that they are not going to show the environment name by default in the future, and don't know if it's related to me not seeing it. But as you can see from the terminal output, it's not even about how it's activated, it's that things are different before doing cd .. cd - and not able to be streamlined with cd .. && cd - . Namely, it's this conda activate that seems to not work unless time is spend outside of the directory.
from pyenv-virtualenv.
Also, my .zshrc file is very boilerplate, I have oh-my-zsh installed and nothing custom to conda init
. As a matter of fact it is interesting, somehow conda init is being run or the environment is being activated in some more robust way when you exit and reenter the directory.
# 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="$HOME/.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="robbyrussell"
# 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 one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other 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 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.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# 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)
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"
eval "$(pyenv init -)"
source ~/.iterm2_shell_integration.zsh
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
# place this after nvm initialization!
load_nvmrc
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
eval "$(rbenv init - zsh)"
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$PATH:$GEM_HOME/bin"
autoload -U add-zsh-hook
add-zsh-hook chpwd load_nvmrc
from pyenv-virtualenv.
➜ show-native-api conda activate show-native-api CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
Found the reason for this. Since version 4, Conda doesn't copy itself to alternate environments but rather creates a shell function conda
. Which, unlike envvars, does not survive spawning a new shell.
Now, why do you expect a virtual environment to survive spawning a new shell? This doesn't work with base virtualenv
, venv
or conda
, either.
from pyenv-virtualenv.
Related Issues (20)
- python3-config (along with other tools) does not respect the version virtualenv hook on HOT 6
- pyenv deactivate doesn't deactivate env HOT 1
- pyenv virtualenv does not correctly link the c++ libraries associated to the python package HOT 1
- New release? HOT 3
- Latest version HOT 1
- Incorrect version reported by `pyenv virtualenv --version` HOT 1
- Cannot create new virtualenv with "system" Python if it's 3.11+ HOT 1
- Hooks for virtualenv-delete HOT 1
- Hooks don't work under /usr/share/pyenv/plugins
- Virtualenv not isolated HOT 1
- Don't use `.python-version` for auto-activation HOT 3
- "tox: command not found" despite tox being present in the active environment HOT 1
- Unable to use `venv/bin/activate` when the virtual environment of pyenv-virtualenv is set. HOT 2
- virtualenv-init break mc (Midnight Commander) subshell
- `_pyenv_virtualenv_hook` still in $PROMPT_COMMAND after uninstall HOT 3
- weird cyclic symlink on macos HOT 3
- Unusual Message When Creating Virtual Environment HOT 3
- virtualenv can't be created using partial Python version in v2.4.8 HOT 1
- Cannot create virtualenv: "pyenv: no installed versions match the prefix -f'`" HOT 7
- commit 6179ac76c412d2e9a637b5ea8e7a7e47e4a48363 causes pyenv-virtualenv commands to fail with `pyenv: no installed versions match the prefix `-f'` HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyenv-virtualenv.