Hi
I am running pyenv version 1.0.5, on macos sierra and I find it very slow when I press enter for my prompt to return.
in my profile I have this
To enable shims and autocompletion add to your profile:
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi
however If I remove above snippet my prompt responds almost instantly.
Is anyone else experiencing similar issue. ?
here is quick vid for demonstration.
I have the same issue on Bash on WSL.
does anyone have any ideas ?
It will run bunch of bash code. It may be slow on slower machine.
I was running it on a laptop from last year. I don't think my machine is
slow.
On Tue, 17 Jan 2017, 05:42 Yamashita, Yuu, notifications@github.com wrote:
Closed #784 https://github.com/yyuu/pyenv/issues/784.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/yyuu/pyenv/issues/784#event-925621294, or mute the
thread
https://github.com/notifications/unsubscribe-auth/ABjlYTLzv2US-8_4jPwc-IExaFsji-56ks5rTKkvgaJpZM4LSi-H
.
@yyuu thank you for all the work you do on pyenv it is great solution for python, however I find it little bizarre that you could make an assumption that I have slow hardware with out asking what hardware I have.
I do not think this is due to hardware as my mac is only 1 year old its 2.7 core i5 with 16gb of ram, I am quiet sure that this is sufficient enough.
I also do not think that this issue should be closed.
Hi,
I have the same issue.
My machine is a MacBook Pro, 2,9 GHz Intel Core i5 with 16Go RAM.
Where do you add it to? profile or rc?
Are you using Bash or Zsh?
It is almost certainly better to add it to your profile / login shell only, and not your rc.
But that depends on how and when your login shell is started etc.
There is an issue about addressing this in the README, and IIRC it recommends to use rc since it will work in a new shell without relogin etc.
I agree in general, that pyenv's init is slow - that's why I am doing it only on demand, i.e. when a pyenv command is called.
@lanox
pyenv causing prompt to be slow
That's not correct, is it?
It's not slowing down the prompt itself, i.e. after pressing Enter, is it?
@lanox
1 year old its 2.7 core i5 with 16gb of ram
SSD then also I assume?
For debugging, you can put export PYENV_DEBUG=1 before the init.
Also make sure that you are not doing the init too often, i.e. more than once.
Also you might show us your rc or profile script.
I also have this problem with my fish and macOS settings.
After some digging, I find the command pyenv rehash 2>/dev/null (or your equivalence for other shells) to be the most time consuming part.
Therefore, I just manually put the rest of pyenv init - into my rc files (config.fish for fish). So far it works ok.
Hope this workaround helps. Before an official solution is provided.
I have two different macs with the same config and only 1 exhibits this issue.
The slowdown only happens after: eval "$(pyenv virtualenv-init -)"
Well, as said before and in other issues: you should not have the init in your rc (e.g. .bashrc), but rather your profile (e.g. .profile), which gets run typically only once when logging in.
This is different on macos IIRC (which runs a login shell always).
Try adding some "echo profile" and "echo bashrc" to respective files to see what gets parsed when opening a new shell.
@cmcginty
Since it appears to be related to pyenv-virtualenv, please follow up on https://github.com/pyenv/pyenv-virtualenv/issues/132#issuecomment-383175244.
I have a fix I made against pyenv/pyenv-virtualenv#259 and also opened pyenv#1153.
As pointed out in https://github.com/pyenv/pyenv/issues/784#issuecomment-356805124 , the slowest piece seems to be running pyenv rehash (which is run by pyenv init -).
I am running prezto on macOS High Sierra. I tried modifying this line in the prezto python module to:
eval "$(pyenv init - --no-rehash)"
And it improved startup time by ~400ms. Not sure what the right path forward is (change in prezto? optimize pyenv rehash?), but just thought I'd pass along that finding.
@sloria
Using --no-rehash is certainly a good idea, so it would make sense to put it upstream in prezto IMHO.
Optimizing rehash would also be good, of course - you can see what it does with PYENV_DEBUG=1 pyenv rehash already.
In case you are using pyenv-virtualenv, https://github.com/pyenv/pyenv-virtualenv/issues/274 is relevant: I think pyenv-virtualenv reruns it unnecessarily.
I have an experiment in https://github.com/pyenv/pyenv/pull/1185, which uses different shim directories per current version, which might be interesting in this regard, since it potentially means that you will have more, but smaller sets of shims (that need to be rehashed).
~400ms
Would be really interesting to see where this is coming from for you, since it is faster for me.
Using pyenv master and pyenv-virtualenv master:
10 loops, best of 3: 128 msec per loop
Without pyenv-virtualenv/etc/pyenv.d/rehash/envs.bash:
10 loops, best of 3: 89.9 msec per loop
(used python -m timeit "__import__('subprocess').Popen(['pyenv', 'rehash']).communicate()")
Thanks @blueyed for the suggestions and for looking into further optimizations. I'll send a PR to prezto when I get a chance.
In case it's useful, I used time zsh -i -c echo to measure zsh start up time (which is how I got the 400ms figure).
Can you try the timeit command I've used.
I have created https://github.com/pyenv/pyenv-virtualenv/pull/275 for pyenv-virtualenv.
Are you using it?
btw: I am using eval "$("$PYENV_ROOT"/bin/pyenv init -)" in my ~/.profile file, i.e. not for every new terminal, and then basically only define the pyenv function (that you get from it) in ~/.zshrc.
I won't have time to look into this today. I'll let you know if I end up trying that out, but please don't block the PR on my behalf. Thanks again for working on this.
btw: you can save some decent milliseconds by providing the shell to pyenv-init, e.g. pyenv init - zsh.
See https://github.com/rbenv/rbenv/pull/1099.
@sloria
Are you using pyenv-virtualenv? (asked the 3rd already now)
As for the original issue / reporter and people reacting to it with thumbs-up: you could export PYENV_DEBUG=1 and then see what it does.
Please provide this info here then, and please also try to investigate yourself, i.e. use it without oh-my-zsh or other frameworks that might get into the way.
btw: the original title is misleading ("Slow init/startup"), because it is slow on every prompt then, not only its startup.
@blueyed Yes, I'm using pyenv-virtualenv.
I have the same problem. I am using MacOS 10.13.6. Some people said this problem is caused by kaspersky internet security. Is it?
I solve this problem after I add .pyenv as a trusted zone on kaspersky internet security. This policy speeds up a little bit about each shell prompt. Then I change this statement on .bash_profile
eval "$(pyenv init - bash --no-rehash)"
Then the speed of the shell prompt become normal again. I am using macOS Mojave (10.14).
Startup time
if which pyenv > /dev/null; then eval "$(pyenv init -)"; fi ~ 300ms
if which pyenv > /dev/null; then eval "$(pyenv init - zsh --no-rehash)"; fi ~ 100ms
On zsh and on a teeny tiny computer this works:
export PATH="/home/pi/.pyenv/bin:$PATH"
eval "$(pyenv init - zsh --no-rehash)"
eval "$(pyenv virtualenv-init -)"
Edit: and I have this only on ~/.zlogin
I really need to keep up on these issues before I spend time on trying to shave milliseconds from my shell startup time (fish shell user here).
Running the below
pyenv init -
should print something like
Output
set -gx PATH '/Users/capin/.pyenv/shims' $PATH
set -gx PYENV_SHELL fish
source '/Users/capin/.pyenv/libexec/../completions/pyenv.fish'
command pyenv rehash 2>/dev/null
function pyenv
set command $argv[1]
set -e argv[1]
switch "$command"
case activate deactivate rehash shell
source (pyenv "sh-$command" $argv|psub)
case '*'
command pyenv "$command" $argv
end
end
Not the most update to date syntax for fish shell, but that is beside the point.
I decided to load all that code independently from a separate fish file, ie. load_pyenv.fish and kind of dig around with what this init is doing, and can confirm what other have stated,
command pyenv rehash 2>/dev/null
will typically bolt on around 200ms to a shell initialization.
without command pyenv rehash 2>/dev/null
─λ /usr/bin/time -l fish -ic exit
0.72 real 0.31 user 0.29 sys
3698688 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
69197 page reclaims
0 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
209 signals received
416 voluntary context switches
597 involuntary context switches
with command pyenv rehash 2>/dev/null
╰─λ /usr/bin/time -l fish -ic exit
0.94 real 0.42 user 0.40 sys
3686400 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
103612 page reclaims
0 page faults
0 swaps
0 block input operations
0 block output operations
0 messages sent
0 messages received
240 signals received
641 voluntary context switches
866 involuntary context switches
☝️ leaving this here for future me.
This is kinda inconveniently closed while still slow.
But here is a neat trick i found: https://github.com/davidparsson/zsh-pyenv-lazy
Lazy loading pyenv is hardly adding anything to your startup time! :)
Most helpful comment
@yyuu thank you for all the work you do on pyenv it is great solution for python, however I find it little bizarre that you could make an assumption that I have slow hardware with out asking what hardware I have.
I do not think this is due to hardware as my mac is only 1 year old its 2.7 core i5 with 16gb of ram, I am quiet sure that this is sufficient enough.
I also do not think that this issue should be closed.