How to avoid pip install global packages accidentally?
up vote
0
down vote
favorite
Sometimes I forget to activate the virtual environment before executing the pip install command, which causes a bunch of useless global pip packages. Some of them are not able to be uninstalled directly using pip (dateutils issue).
I wonder how I can avoid such accidents?
Can I disable pip for non-root users and only permit sudo pip?
pip
add a comment |
up vote
0
down vote
favorite
Sometimes I forget to activate the virtual environment before executing the pip install command, which causes a bunch of useless global pip packages. Some of them are not able to be uninstalled directly using pip (dateutils issue).
I wonder how I can avoid such accidents?
Can I disable pip for non-root users and only permit sudo pip?
pip
1
As far as I know, pip will install to your home directory if you didn't runsudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so thatpipmaps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to itspipis guaranteed to precede the alias. If this doesn't work, you can add apipexecutable file and a path leading to it.
– Ray
2 days ago
1
I'm not sure if this is what you're looking for. FWIW, I hadsudoaccess on a (shared) server and I sometimes stupidly do asudo rebooton it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.
– Ray
2 days ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Sometimes I forget to activate the virtual environment before executing the pip install command, which causes a bunch of useless global pip packages. Some of them are not able to be uninstalled directly using pip (dateutils issue).
I wonder how I can avoid such accidents?
Can I disable pip for non-root users and only permit sudo pip?
pip
Sometimes I forget to activate the virtual environment before executing the pip install command, which causes a bunch of useless global pip packages. Some of them are not able to be uninstalled directly using pip (dateutils issue).
I wonder how I can avoid such accidents?
Can I disable pip for non-root users and only permit sudo pip?
pip
pip
asked 2 days ago
Ssuching Yu
307
307
1
As far as I know, pip will install to your home directory if you didn't runsudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so thatpipmaps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to itspipis guaranteed to precede the alias. If this doesn't work, you can add apipexecutable file and a path leading to it.
– Ray
2 days ago
1
I'm not sure if this is what you're looking for. FWIW, I hadsudoaccess on a (shared) server and I sometimes stupidly do asudo rebooton it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.
– Ray
2 days ago
add a comment |
1
As far as I know, pip will install to your home directory if you didn't runsudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so thatpipmaps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to itspipis guaranteed to precede the alias. If this doesn't work, you can add apipexecutable file and a path leading to it.
– Ray
2 days ago
1
I'm not sure if this is what you're looking for. FWIW, I hadsudoaccess on a (shared) server and I sometimes stupidly do asudo rebooton it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.
– Ray
2 days ago
1
1
As far as I know, pip will install to your home directory if you didn't run
sudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so that pip maps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to its pip is guaranteed to precede the alias. If this doesn't work, you can add a pip executable file and a path leading to it.– Ray
2 days ago
As far as I know, pip will install to your home directory if you didn't run
sudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so that pip maps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to its pip is guaranteed to precede the alias. If this doesn't work, you can add a pip executable file and a path leading to it.– Ray
2 days ago
1
1
I'm not sure if this is what you're looking for. FWIW, I had
sudo access on a (shared) server and I sometimes stupidly do a sudo reboot on it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.– Ray
2 days ago
I'm not sure if this is what you're looking for. FWIW, I had
sudo access on a (shared) server and I sometimes stupidly do a sudo reboot on it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.– Ray
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I am not as good at writing bash scripts but you can replace the pip command with an alias in your bashrc with this script
if [[ $(python -c 'import sys; print (sys.real_prefix)' 2>/dev/null) ]]; then
/path/to/actual/pip/executable install $1;
else
echo "not in a virtual env";
fi
This script solve your problem. If there is anyone who can find an issue in the script or improve it, please do.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I am not as good at writing bash scripts but you can replace the pip command with an alias in your bashrc with this script
if [[ $(python -c 'import sys; print (sys.real_prefix)' 2>/dev/null) ]]; then
/path/to/actual/pip/executable install $1;
else
echo "not in a virtual env";
fi
This script solve your problem. If there is anyone who can find an issue in the script or improve it, please do.
add a comment |
up vote
1
down vote
I am not as good at writing bash scripts but you can replace the pip command with an alias in your bashrc with this script
if [[ $(python -c 'import sys; print (sys.real_prefix)' 2>/dev/null) ]]; then
/path/to/actual/pip/executable install $1;
else
echo "not in a virtual env";
fi
This script solve your problem. If there is anyone who can find an issue in the script or improve it, please do.
add a comment |
up vote
1
down vote
up vote
1
down vote
I am not as good at writing bash scripts but you can replace the pip command with an alias in your bashrc with this script
if [[ $(python -c 'import sys; print (sys.real_prefix)' 2>/dev/null) ]]; then
/path/to/actual/pip/executable install $1;
else
echo "not in a virtual env";
fi
This script solve your problem. If there is anyone who can find an issue in the script or improve it, please do.
I am not as good at writing bash scripts but you can replace the pip command with an alias in your bashrc with this script
if [[ $(python -c 'import sys; print (sys.real_prefix)' 2>/dev/null) ]]; then
/path/to/actual/pip/executable install $1;
else
echo "not in a virtual env";
fi
This script solve your problem. If there is anyone who can find an issue in the script or improve it, please do.
edited 2 days ago
answered 2 days ago
akabhirav
1,09021132
1,09021132
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1094103%2fhow-to-avoid-pip-install-global-packages-accidentally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
As far as I know, pip will install to your home directory if you didn't run
sudo. So, you should be able to delete what you've accidentally installed. But something you could do that addresses your question is create an alias in .bash_aliases so thatpipmaps to something (i.e., an echo command that laughs at you :-) ). What I don't know is if you activate a virtual environment, whether the path to itspipis guaranteed to precede the alias. If this doesn't work, you can add apipexecutable file and a path leading to it.– Ray
2 days ago
1
I'm not sure if this is what you're looking for. FWIW, I had
sudoaccess on a (shared) server and I sometimes stupidly do asudo rebooton it instead of the (unshared) desktop I'm on. (i.e., I type it so quickly that I didn't think carefully...) To "solve" this, I aliased "sudo" to give me a message on the server. It wasn't an elegant solution, but it solved my problem.– Ray
2 days ago