answer yes's to repeated unix prompts [duplicate] - unix

I'm trying to uninstall all django packages in my superuser environment to ensure that all my webapp dependencies are installed to my virtualenv.
sudo su
sudo pip freeze | grep -E '^django-' | xargs pip -q uninstall
But pip wants to confirm every package uninstall, and there doesn't seem to be a -y option for pip. Is there a better way to uninstall a batch of python modules? Is rm -rf .../site-packages/ a proper way to go? Is there an easy_install alternative?
Alternatively, would it be better to force pip to install all dependencies to the virtualenv rather than relying on the system python modules to meet those dependencies, e.g. pip --upgrade install, but forcing even equally old versions to be installed to override any system modules. I tried activating my virtualenv and then pip install --upgrade -r requirements.txt and that does seem to install the dependencies, even those existing in my system path, but I can't be sure if that's because my system modules were old. And man pip doesn't seem to guarantee this behavior (i.e. installing the same version of a package that already exists in the system site-packages).

starting with pip version 7.1.2 you can run pip uninstall -y <python package(s)>
pip uninstall -y package1 package2 package3
or from file
pip uninstall -y -r requirements.txt

Pip does NOT include a --yes option (as of pip version 1.3.1).
WORKAROUND: pipe yes to it!
$ sudo ls # enter pw so not prompted again
$ /usr/bin/yes | sudo pip uninstall pymongo

If you want to uninstall every package from requirements.txt,
pip uninstall -y -r requirements.txt

on www.saturncloud.io, Jupiter notebooks one can use like this:
!yes | pip uninstall tensorflow
!yes | pip uninstall gast
!yes | pip uninstall tensorflow-probability

Alternatively, would it be better to force pip to install all dependencies to the virtualenv rather than relying on the system python modules to meet those dependencies,
Yes. Don't mess too much with the inbuilt system installed packages. Many of the system packages, particularly in OS X (even the debian and the derived varieties) depend too much on them.
pip --upgrade install, but forcing even equally old versions to be installed to override any system modules.
It should not be a big deal if there are a few more packages installed within the venv that are already there in the system package, particularly if they are of different version. Thats the whole point of virtualenv.
I tried activating my virtualenv and then pip install --upgrade -r requirements.txt and that does seem to install the dependencies, even those existing in my system path, but I can't be sure if that's because my system modules were old. And man pip doesn't seem to guarantee this behavior (i.e. installing the same version of a package that already exists in the system site-packages).
No, it doesn't install the packages already there in the main installation unless you have used the --no-site-packages flag to create it, or the required and present versions are different..

Lakshman Prasad was right, pip --upgrade and/or virtualenv --no-site-packages is the way to go. Uninstalling the system-wide python modules is bad.
The --upgrade option to pip does install required modules in the virtual env, even if they already exist in the system environment, and even if the required version or latest available version is the same as the system version.
pip --upgrade install
And, using the --no-site-packages option when creating the virtual environment ensures that missing dependencies can't possibly be masked by the presence of missing modules in the system path. This helps expose problems during migration of a module from one package to another, e.g. pinax.apps.groups -> django-groups, especially when the problem is with load templatetags statements in django which search all available modules for templatetags directories and the tag definitions within.

pip install -U xxxx
can bypass confirm

Related

How to install newer version of R on Amazon Linux 2

For whatever reason, Amazon moved R to the so-called "Extras Library" so you can't install R using sudo yum install -y R anymore. Instead, you have to do sudo amazon-linux-extras install R3.4. As a result, I can only install R 3.4.3 when the newest stable release is 3.6.1, and so many R libraries can't even be installed because the version is too low. Is there any good and clean way to install the latest version of R and skip Amazon's package manager? Thanks!
Use amazon-linux-extras which installs R4.0.2:
amazon-linux-extras install R4
You may need root:
sudo amazon-linux-extras install R4
I've tried setting up R 3.6.x on a docker container that uses the amazonlinux image. My approach was to get the R source file from the below link and install from source
cd /tmp/
wget https://cloud.r-project.org/src/base/R-3/R-3.6.3.tar.gz
tar -zxf R-3.6.3.tar.gz
cd /tmp/R-3.6.3
./configure --without-libtiff --without-lapack --without-ICU --disable-R-profiling --disable-nls
make
make install
you will need to yum install some dependencies, like 'make', which doesn't seem to come with aws amazonlinux docker image (which i think mirrors the EC2 instance AMI image you are referring to).
The above kind of worked for me in that i had a working R3.6 installation, but it didnt allow me use it with rshiny server, so i'm reverting to the shipped 3.4.3 version.
tl;dr: you'll probably have to manually download the source files and install the desired R version from source, and throw in some build dependencies as well.
Try this on Amazon Linux 2
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install R
Amazon Linux 2 Image contains extras library that can be used as well. Follow the guide here.
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-install-extras-library-software/
sudo amazon-linux-extras enable R3.4
sudo yum clean metadata && sudo yum install R3.4

Are packages deleted when upgrading R on Linux?

Are packages deleted when upgrading R on Linux? I would prefer to just use the default package installation directory, instead of setting up a custom directory.
I'm aware I can setup a custom directory in the following manner:
cat >> ~/.Renviron
R_LIBS=/data/Rpackages/
I just wonder what happens if I don't issue the command above? Will packages be wiped every time I issue the command
sudo apt-get update && sudo apt-get upgrade
, and as a consequence R gets updated to the latest version?
#Jason, when you are doing sudo apt-get update && sudo apt-get upgrade, it just upgrade packages that have a new version in your list of repositories. There is no reason it will modify R packages already installed.
I'm also running Linux and R and the only time I have to re-install R packages is when I re-install my system. My R packages are installed by default in /usr/local/lib/R/site-library

Deleted /usr/bin/dotnet and pacman -S dotnet-sdk will not install it

I am trying to write a WEB api in dotnet core on my Manjaro Arch linux distro.
I installed the edge version of dotnet first (^3) since i like the bleeding edge. I had, however on a different computer already made the project using dotnet 2.2. Therefore i install dotnet 2.2 aswell. This did not work, since the version in /usr/bin/ was still 3.0.
I deleted the exec from /usr/bin and now i cant get it back. I have run pacman -Su and pacman -R, i have tried rebooting aswell.
OBS: the first to times i installed them, i did it with yay -S dotnet-sdk which allowed me to choose from the different versions
You can force install of packages that is already installed using --force in pacman.
So, you should be able to get the binary again by using sudo pacman -S dotnet-sdk --force.
You might also attempt to remove dotnet-sdk before you install, you can do that by running sudo pacman -Rns dotnet-sdk. (remove package with configurationfiles and dependencies not required by any other package).

Installing numpy without sudo

I am trying to install numpy on a remote host where I have no admin rights. I have sucessfully installed Python 2.7 and pip inside a virtualenv ,and can use pip to install trivial things like pip install Markdown. But if I pip install numpy or scipy, it errors on SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel. I do not have rights to sudo apt-get or apt-get, so can not do sudo apt-get install python27-devel or sudo apt-get install python-devel. I wanted to build from source so that I could use the option --user but the source is a .deb file and building it requires even more things I have to apt-get. I tried contacted the admin but I am advised to keep my own installations in my own local environment. What should I do?
The OS system is Ubuntu 14.04 LTS.
The reason for the admins answer is simple. Ubuntu also uses python for internal scripts. So the admin will not update or change the python installation if you need a more recent version of a package.
This is what I would try:
Compile source of python 2.7 yourself and install it in your preferred path in your home directory. This way you always have all needed headers. Put the interpreter into your PATH.
(Optional) Set PYTHONUSERHOME to your local python site packages
Install virtualenv package via pip
Setup virtualenv envirnoment for numpy etc...
(Optional) 4. Build Blas libraries e.g. OpenBlas in your home
Install cython in virtualenv ... and probably some more packages needed for numpy
Install numpy scipy in the virtualenv with the correct settings BLAS libraries settings
If you use your own python installation, the virtualenv is not really necessary. So you might want to omit that. You just need to make sure that your python interpreter is always first to be found.

DistributionNotFound error after upgrading pip

In reading about virtualenv here I realized I didn't have pip 1.3+, so I ran pip install --upgrade pip and now when I run pip --version i get the following:
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 2807, in <module>
parse_requirements(__requires__), Environment()
File "/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/distribute-0.6.34-py2.7.egg/pkg_resources.py", line 594, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==1.2.1
If it helps, or is at all relevant, my $PATH looks like this:
/usr/local/bin:/usr/local/share/python:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
Also, which pip gives me /usr/local/bin/pip.
Not sure what to do about the error. Thanks.
The brutal way:
Assuming you are using homebrew for Mac (because I see /usr/local/Cellar), I suggest to
remove (or backup) /usr/local/lib/python2.7, and
brew rm python && brew install python.
This will definitely install pip 1.3.3 alongside of python. Your distribute will also be 0.6.35.
The soft way:
From /usr/local/lib/python2.7/site-packages just remove:
easy-install.pth
pip-1.2.1-py2.7.egg or other versions of pip you have.
distribute-0.6.34-py2.7.egg or other versions
Then, brew rm python && brew install python. This will leave all your other bindings from brew and installed stuff intact. Python, pip and distribute will be replaced with up-to-date versions.
additionally:
Please check that you don't have a distribute or setuptools or pip located in /Library/Python/2.7/site-packages. That dir is re-used by all python 2.7 versions (brewed or from OS X) and will interferre with the pip/distribute already installed by Homebrew.
I happened to get to a similar state after upgrading from OS X Lion to Mountain Lion today.
The other proposed solutions either do not work, or replace the Apple version of Python with the brew version, which I'm not sure is what saclark asked for.
What I did to get it fixed is install distribute manually, thus getting easy_install back to work, and then install pip with it.
The commands are:
$ curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.45.tar.gz
$ tar -xzvf distribute-0.6.45.tar.gz
$ cd distribute-0.6.45
$ sudo python setup.py install
$ sudo easy_install pip
If the link does not work, you can alway find newer versions of distribute here.
I got similar problem today. After some research, I solved it by reinstalling pip using this:-
python -m pip install --upgrade --force-reinstall pip
Hope somebody would find it helpful.
As an aside, there's an easier way to do it (I just encountered this).
Edit /usr/local/bin/pip and change the references to version number (so below you'd want to change '1.5.6' to whatever version number you're using):
#!/usr/local/opt/python/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
__requires__ = 'pip==1.5.6'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
)
then you may be completely good at that point.
I wanna find out at where pip 1.2.1 is required, but I don't have so much time... so I just downgrade pip to 1.2.1. It can't be helped for a while, till pip or distribute package is modified.
How to do this? just type this in console(I hope your distribute package is well):
easy_install pip==1.2.1
There is no need to uninstall python and install it back. Get the latest distribute package installed and then update pip with it should do the trick.
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo python ez_setup.py
sudo easy_install -U pip
The correct way to fix modern version (6.x) of pip in 2 steps
Delete the pip package in Python's site-package. For Homebrew Python 2.7, do this:
rm -r /usr/local/lib/python2.7/site-packages/pip
Follow the instructions on the official pip documentation site to reinstall it. For short:
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
For pip 6.x, there's no need to install the legacy distribute package. Just setuptools, which will be installed by default via the get-pip.py script mentioned above.
Hm.. puzzling. Wonder where that 1.2.1 comes from. Just out of curiosity, could you post the contents of /usr/local/bin/pip? Should only be a couple of lines.
You could try updating pip (again) with distribute, and maybe also distribute itself..
easy_install --upgrade distribute
easy_install --upgrade pip

Resources