New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Latest changes have made unattended installation impossible #1914
Comments
I understand the difficulties but don't quite see a way that's guaranteed to work reliably for an automated installation in all poasible cases. Here's the thing:
So we need to
The problem is:
|
My best idea so far is to recommend two different ways: for the case where The first could e.g. append everything to This however would break if the user's login shell is not Bash -- it would not execute anything!! |
I understand you would like to enable this for all distributions. I can speak for Debian. A fresh installed Debian doesn't come with Debian comes with |
Ok, based on your second comment. What would be the solution for Debian with Bash? I still can't figure this out. |
This post explains the different uses of each file. In your case, you want |
It's such a mess for something that was working perfectly. Sorry for the rant. I have followed your advice and it still doesn't work. I think you have a typo and may have missed ~/.bash_profile
~/.bashrc
~/.profile
I'm getting the following error:
|
I just noticed, I had missed the minus in there: Despite the correction, I'm now getting:
|
@tegant OK, I think there were some crossed wires on my part between what you want to do (solve this for Debian) vs what the pyenv project needs to be able to do. What the files do:To clarify the purpose of the files:
See this for more What you need to do:
|
Thanks Agoose, I appreciate your help here. Really do. Sadly it is not working in a non-interactive way. .bash_profile
~/.bashrc
~/.profile
This doesn't throw an error when ran manually:
But we can no longer have this in our bash script to install it automatically like this:
It all works until activation and then it fails.
This means we can no longer install our software automatically via scripts. It's a complete deal breaker for us. |
@tegant at a high level, you definitely will be able to install things via scripts - the only thing that's changed here is # Install pyenv
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
sed -i '1 i\export PYENV_ROOT="$HOME/.pyenv"' ~/.profile
sed -i '2 i\export PATH="$PYENV_ROOT/bin:$PATH"' ~/.profile
sed -i '3 i\eval "$(pyenv init --path)"' ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
# Install pyenv-virtualenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >>~/.bashrc
# Load new variables
# Assume that .profile contains `source $HOME/.bashrc`
source ~/.profile
# Pyenv
pyenv install 3.9.4
pyenv virtualenv 3.9.4 venv
pyenv activate venv Incidentally, I hadn't seen the |
Glad, I could help. :-)
|
You need to delete Does your |
Yes, Debian puts this by default into
So, yes, it is sourced from |
Guys, I think the best solution for now is simply
This will solve everything. I really hope you consider the possibility of reverting #1649 Thanks |
@tegant I think you're being a little hasty. It's understandable that you're feeling frustrated about these changes, but really not much has changed. The reason you're having problems is because we need to understand why your configuration is different to the expected. |
Can you share your |
I came across this issue at 10:00 this morning. It's now 17:44. I spent almost eight hours installing a virtualenv. haha My job is at risk. :-) .bashrc
./profile
There is no |
Could you also output the result of calling |
On Ubuntu, this is the fix that I came up with: # Prepend the path modifications to the top of .profile (⚠️ overrites existing .profile)
(echo -e 'export PYENV_ROOT="$HOME/.pyenv"' \
'\nexport PATH="$PYENV_ROOT/bin:$PATH"' \
'\neval "$(pyenv init --path)"\n'; \
cat /etc/skel/.profile) > ~/.profile
# Append shell initialization to the bottom of .bashrc
echo '"$(pyenv init -)"' >> .bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> .bashrc |
I've made a PR with updated instructions for Bash and Zsh based on feedback: #1920. Among other things, I've provided an alternative configuration for Bash that allows automatic installation. Please review it and tell me:
|
The way I came up with turned out to be not enough. @tegant echo -e 'if shopt -q login_shell; then'\
'\n export PYENV_ROOT="$HOME/.pyenv"'\
'\n export PATH="$PYENV_ROOT/bin:$PATH"'\
'\n eval "$(pyenv init --path)"'\
'\nfi' >>~/.bashrc
echo -e 'if [ -z "$BASH_VERSION" ]; then'\
'\n export PYENV_ROOT="$HOME/.pyenv"'\
'\n export PATH="$PYENV_ROOT/bin:$PATH"'\
'\n eval "$(pyenv init --path)"'\
'\nfi' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc (then relogin) |
I would love to read (and understand) everything that's going on here, but I cannot due to lack of time (and in-depth Linux experience). Do know that this recent change has fixed something that was not broken ;) Here's my problems which I believe I solved somehow, but maybe you guys can consider them for future "fixes":
|
@bersbersbers what distro are you running? Usually it's |
This is on openSUSE Leap 15.2, see my Find
Even if my analysis not 100% correct - I certainly see this:
|
@bersbersbers wow, OpenSUSE actually sources |
@agoose77 and I think it does that even for non-SSH shells (It's just that for some SSH shells it does not do that.), see here:
|
Anyway, here's the PR with the auto-install option: #1922 (see the link there so see the rendered README). |
Please check it out and tell if the option works and if there're any clarifications needed or anything |
Yes, this is what I have been doing - specifically,
Wouldn't it make sense for you to add this in |
Apologies for the late reply. We had a release going out and had all hands full. I just had a few hours time to go through this and test the latest. Unfortunately it is not working.
This leads to the same problem as before.
This actually makes it worse, because pyenv isn't in path.
Honestly guys, please don't get it the wrong way. You have "fixed" something that wasn't broken, and looking at the issues, it is causing so much trouble for everyone. The slogan of this project was a |
@tegant I don't speak for the project developers but; Shell configuration is tricky, and needs to be done properly. In my experience, a lot of developers do not properly configure their shells, and so they can be easily broken / slow due to doing too much in the wrong place. Pyenv shouldn't do things the wrong way just because other people do. For Debian, assuming you're using bash, then the scripts that you've posted expect if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi The Clearly, it is not desirable that users have been impacted by a configuration change. However, this is free software; the authors of pyenv don't owe anyone anything. Whether you intended it to, your final remark comes across as a little entitled, which I don't think is fair. |
My apologies, I didn't mean to cause any offend. I was hoping to leave it as a constructive feedback. If my previous post was misunderstood, I apologise again. We all have been there to fix a feature that was well intended, but caused headache at the end. Anyway let's focus on how we can automate this again. :-) I have started off a fresh installation of Debian Buster 10 on AWS. Yes, I'm using Bash. The default of ~/.profile is:
There is no So you are correct, I'm not sure, If I understand this last bit correctly:
Since I'm using bash, you are saying I don't need to put anything into ~/.profile at all, correct?
This ends up like this:
|
@agoose77 I have some more discovery here to share, if you don't mind, please.
If I cut the script to only this part.
But this means Pyenv 2.0 can no longer be automated as it was possible before. |
@tegant the "automated installation" code that @native-api implemented is designed to work on "most" systems. If you know exactly how your system is configured, you can simplify it.
If you want to use the automated installer, the defaults should work. However, if you want to customise this yourself, you can "just" put this in your export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)" How are you testing all of this? You need to make sure that you log out and log in after modifying either file in this case, because the |
@tegant You should be able to if you heed the instructions in the README. None of your snippets posted so far do that. If something is unclear there, I'm all ears. I was specifically asking if anything's unclear when writing them. |
Thanks guys for your feedback. @agoose77 Btw there is nothing customised in @native-api Yes, I looked at your PR before I started testing today. Your branch is removed, some of those links return now 404. Hence it's a bit difficult to follow. However based on your commit, you have made only a change to the README.md, correct? Was there anything more? Sorry if I have missed it.
I have tested this further above and posted the results. Sadly it doesn't work. I'm available to do further testing, if you need me. Please shout, happy to help. |
@tegant if you are getting a |
The PR has been merged, so you should be looking at the master README. |
Correct. I have read through that: https://github.com/pyenv/pyenv/blob/master/README.md#basic-github-checkout By executing this, I ensure that the three lines appear on top of
Then I pasted this into terminal:
Then I sourced . ~/.profile When activating the virtualenv, I get this:
Have you actually tried to run this as a bash script on your test server?
Thanks |
These are 2 alternatives, you need to do either of them, not both. Then, there's the next section about adding stuff into If you use |
@native-api Thank you for your patience. I have adjusted the script based on your recommendation. In summary:
See the new script:
The result:
|
--- a.sh
+++ b.sh
@@ -5,13 +5,8 @@
sed -i '1 i\export PYENV_ROOT="$HOME/.pyenv"' ~/.profile
sed -i '2 i\export PATH="$PYENV_ROOT/bin:$PATH"' ~/.profile
sed -i '3 i\eval "$(pyenv init --path)"' ~/.profile
-sed -i '4 i\eval "$(pyenv virtualenv-init -)"' ~/.profile
-echo -e 'if shopt -q login_shell; then' \
- '\n export PYENV_ROOT="$HOME/.pyenv"' \
- '\n export PATH="$PYENV_ROOT/bin:$PATH"' \
- '\n eval "$(pyenv init --path)"' \
- '\n eval "$(pyenv virtualenv-init -)"' \
- '\nfi' >> ~/.bashrc
+echo 'eval "$(pyenv init -)"' ~/.bashrc
+echo 'eval "$(pyenv virtualenv-init -)"' ~/.bashrc
source ~/.profile
pyenv install 3.9.5
pyenv virtualenv 3.9.5 venv |
Thanks. I have tried it again.
Result is:
|
Ah there is typo in your code above.
:-) Let me try again |
@tegant you need to write the lines to the files
|
🤦 sed -i '1 i\export PYENV_ROOT="$HOME/.pyenv"' ~/.profile
sed -i '2 i\export PATH="$PYENV_ROOT/bin:$PATH"' ~/.profile
sed -i '3 i\eval "$(pyenv init --path)"' ~/.profile
-sed -i '4 i\eval "$(pyenv virtualenv-init -)"' ~/.profile
-echo -e 'if shopt -q login_shell; then' \
- '\n export PYENV_ROOT="$HOME/.pyenv"' \
- '\n export PATH="$PYENV_ROOT/bin:$PATH"' \
- '\n eval "$(pyenv init --path)"' \
- '\n eval "$(pyenv virtualenv-init -)"' \
- '\nfi' >> ~/.bashrc
+echo 'eval "$(pyenv init -)"' >>~/.bashrc
+echo 'eval "$(pyenv virtualenv-init -)"' >>~/.bashrc
source ~/.profile
pyenv install 3.9.5
pyenv virtualenv 3.9.5 venv |
Alrighty. The new version:
result:
:-| |
Looks like you have an uncommon configuration or something. Please show a debug trace (it's going to be big so as a gist): #!/bin/bash
set -e
git clone https://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
sed -i '1 i\export PYENV_ROOT="$HOME/.pyenv"' ~/.profile
sed -i '2 i\export PATH="$PYENV_ROOT/bin:$PATH"' ~/.profile
sed -i '3 i\eval "$(pyenv init --path)"' ~/.profile
echo 'eval "$(pyenv init -)"' >>~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >>~/.bashrc
export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x
source ~/.profile
pyenv install 3.9.5
pyenv virtualenv 3.9.5 venv
pyenv activate venv
set +x |
Can you dump the env at the end of this too? for ease-of-grepping :) |
It's actually not that large, so I can paste it here:
Sure, how can I dump the env? |
I think, I'm seeing the issue:
I haven't put the code there. This comes by default with Debian Buster 10 (AWS / EC2). I suppose I have to remove that section?
|
Great news, by inserting the lines at the top of ~/.bashrc, it will circumvent any return that may have been put in there, by the linux distribution. This has now worked for me:
Result:
So the key is inserting everything at the top. Thank you so much for your help!!! |
Your shell is not interactive. Pyenv shell functions are only supposed to be installed into interactive shells. If Pyenv-Virtualenv is supposed to install shell functions even into noninteractive shells (in which case, its documentation needs to be updated to clarify that), you need to put
into Alternatively, you can do without |
I love this project, but the latest changes have made the unattended installation of pyenv impossible.
I have a bash script that installs it unattended like this:
But the latest version of pyenv doesn't allow
eval "$(pyenv init -)
.Now it's supposed to be done like
echo 'eval "$(pyenv init --path)"' >>~/.profile
. But the documentation doesn't quite explain that.So when I try to activate the venv inside shell I get an error thrown:
Description
The text was updated successfully, but these errors were encountered: