I have python 2.7 installed on my macbook pro in /usr/bin. When I do ls python* I see these files: python python-config python2.7 python2.7-config pythonw pythonw2.7.
I want to delete them but I can't find a way to do it, I've tried sudo rm -rf and other things but nothing seems to work.
When I do sudo rm -rf I get this:
rm: python: Operation not permitted,
and when I do sudo rm python I get this
override rwxr-xr-x root/wheel restricted,compressed for python?
I want to delete python entirely from my system , can someone help me?
Do not remove python 2.7 from your Mac computer. As you have seen you probably can't anyway. The Mac uses python and the files are protected to be sure they are not removed.
If you want to run another version of python install it and set up virtual environments.
Referenced here
# sudo rm -rf /Library/Frameworks/Python.framework
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
cd /usr/local/bin && \
sudo ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print $9}' | xargs rm
Lol can't believe no one has said this:
Boot into recovery, turn off SIP:
csrutil disable
restart,
open terminal
cd /usr/bin
then
sudo chmod -R 777 ./
try it again
$ python --version
you should no longer see it
Related
I recently upgraded a machine from Ubuntu Server 16.04 LTS to 18.04 LTS using command line. As a result, the built-in Python installation is upgraded from Python 3.5 to 3.6. And it seems that all the Python packages previously installed using pip3 are no longer accessible. I plan to clean up all those packages and use conda for Python package management. My question is, what is the best practice for a clean uninstallation of those inaccessible packages in this case?
The old packages installed via pip3 were primarily located under /usr/local/lib/python3.5/ and ~/.local/lib/python3.5/. But there could be other leftover files, e.g., under /usr/local/bin/. I would like to remove all of related files that came with pip3 install.
sudo pip install installs pip packages to/usr/local/lib/<python_version>/dist-packages, and apt packages to /usr/lib/<python_version>/dist-packages. Check these directories and remove the unwanted packages.
I ended up writing a bash script to call pip3 uninstall on each previously installed package iteratively.
#!/bin/bash
pypath_cmd="PYTHONPATH=$HOME/.local/lib/python3.5/site-packages"
export $pypath_cmd
echo "Uninstalling editable packages in $PYTHONPATH"
rm -f $PYTHONPATH/*.egg-link
rm -f $PYTHONPATH/easy-install.pth
pip3 freeze --all --local | cut --delimiter="=" -f 1 | while read pkg ; do
echo $pkg: $(pip3 show $pkg | grep "Location:")
pip3 uninstall -y $pkg
done
pypath_cmd="PYTHONPATH=/usr/local/lib/python3.5/dist-packages"
export $pypath_cmd
echo "Uninstalling editable packages in $PYTHONPATH"
sudo rm -f $PYTHONPATH/*.egg-link
sudo rm -f $PYTHONPATH/easy-install.pth
pip3 freeze --all --local | cut --delimiter="=" -f 1 | while read pkg ; do
echo $pkg: $(pip3 show $pkg | grep "Location:")
sudo $pypath_cmd pip3 uninstall -y --no-cache-dir $pkg
done
I'm looking at installing anaconda via wget on my server. I've come across https://askubuntu.com/questions/505919/installing-anaconda-python-on-ubuntu and http://ericjonas.com/anaconda.html and it looks promising . As of this writing the current version( https://www.continuum.io/downloads#_unix ) is 4.0 . How can I wget the latest version.
wget just downloads the file...
for python 2.7 :
wget https://repo.continuum.io/archive/Anaconda2-2018.12-Linux-x86_64.sh
for python3.X:
wget https://repo.continuum.io/archive/Anaconda3-2018.12-Linux-x86_64.sh
This is a shell script that guides you though the install.
Run the following line inside of the folder of the downloaded file to start the guided install...
for python 2.7:
bash Anaconda2-2018.12-Linux-x86_64.sh
for Python 3.X:
bash Anaconda3-2018.12-Linux-x86_64.sh
Check latest repos or if you want any specific version here:
https://repo.continuum.io/archive/
This will download the latest anaconda version from scraping the html from the website:
wget -O - https://www.anaconda.com/distribution/ 2>/dev/null | sed -ne 's#.*\(https:\/\/repo\.anaconda\.com\/archive\/Anaconda3-.*-Linux-x86_64\.sh\)\">64-Bit (x86) Installer.*#\1#p' | xargs wget
wget \
https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh \
&& bash Miniconda3-latest-Linux-x86_64.sh -b \
&& rm -f Miniconda3-latest-Linux-x86_64.sh \
&& eval "$(/home/$USER/miniconda3/bin/conda shell.bash hook)"\
&& conda init
You can write the following bash script to automate the installing process.
cd ~
wget https://repo.continuum.io/archive/Anaconda3-2020.11-Linux-x86_64.sh
bash Anaconda3-2020.11-Linux-x86_64.sh -b -p ~/anaconda3
rm Anaconda3-2020.11-Linux-x86_64.sh
echo 'export PATH="~/anaconda3/bin:$PATH"' >> ~/.bashrc
# Reload default profile
conda init
source ~/.bashrc
I would just go to https://repo.anaconda.com/archive/ and copy the link of the most recent dated release and use wget with that.
For example, right now it would be:
wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh
If you want a more automatic way you could try the following.
Using #philipper solution as a starting point I made some modifications.
latest=$(wget -qO- https://repo.anaconda.com/archive/ |
grep -Eo "(href=\")(Anaconda3-.*-Linux-x86_64.sh)*\"" |
sed 's/href=//g' | sed 's/\"//g' | head -n 1); wget "https://repo.anaconda.com/archive/$latest"
The script will download the html of the repo archive page.
Parse out all href tags matching Anaconda3 for Linux-x86 _64 (1st sed).
I strip out the "href=" and quotes from that output (2nd & 3rd sed).
I then get the first entry which will be the most recent and set it to the variable latest. Then use wget to download from the full url.
Either way, once it's downloaded you'll most likely need to make the .sh file executable then you can just run it like a normal .sh file.
I would just do it the first way but the second way does work for now at least.
I'm not really good at bash or using sed so my "automatic" solution might have some issues.
How to install latest Anaconda (2022)
$ ANACONDA_VERSION=$(curl -sS https://repo.anaconda.com/archive/ | grep -Po '(?<=Anaconda3-)([0-9.]*)(?=-Linux-x86_64)' | head -n1)
$ ANACONDA_URL="https://repo.anaconda.com/archive/Anaconda3-${ANACONDA_VERSION}-Linux-x86_64.sh"
$ wget $ANACONDA_URL && bash $(basename $ANACONDA_URL) -b
https://repo.anaconda.com/archive/ lists the release anaconda installer binaries, in the order of latest released.
The grep command grep -Po '(?<=Anaconda3-)([0-9\\.]*)(?=-Linux-x86_64)' extracts the \d\d\d\d.\d\d string, where Anaconda3- and -Linux-x86_64 are lookahead patterns. grep -Po is a useful, clean command to extract some regex pattern from a string (one could do with sed as well).
| head -n1 : choose whichever comes the first, i.e. the latest release.
Miniforge / Miniconda (automatic latest):
$ MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh"
$ wget $MINIFORGE_URL && bash $(basename $MINIFORGE_URL) -b
$ MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"
$ wget $MINICONDA_URL && bash $(basename $MINICONDA_URL) -b
Remarks
Note: the -b option is for the "batch mode" -- no question asked, accept the license, etc. and just install the anaconda for you. One may also find the option -p $CONDA_PREFIX useful.
I am new in centos.I am try to do an application on it.For my application I need to install python 2.7.But the default one on server was python 2.6. So tried to upgrade the version .And accidentally I deleted the folder /usr/bin/python.After that I Installed python 2.7 through make install.I created the folder again /usr/bin/python and run command sudo ln -s /usr/bin/python2.7 /usr/bin/python. After this when I tried to run YUM commands I am getting the error
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied
drwxrwxrwx 2 root root 4096 Mar 8 00:19 python
this is permission showing for the directory /usr/bin/python
CentOS requires that /usr/bin/python be pointed to Python 2.6, not any other version. Run the following commands:
sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/python2.6 /usr/bin/python
to at least fix that part of it. Next time you're building Python, use the defaults and install it to /usr/local/bin, not /usr/bin. That's what the /usr/local hierarchy is for - user-installed programs. /usr and /usr/bin should only be for system-installed programs (such as those installed by yum or its graphical equivalents), and you should keep out unless you know what you're doing. To use identically-named programs in /usr/local/bin instead of their counterparts in /usr/bin, open your ~/.bashrc or ~/.bash_profile (whichever your system uses) and add the following as the last line:
export PATH=/usr/local/bin:$PATH
Restart your shell session, and you should be all set.
yum doesn't work with python2.7.
You should do the following
vim /usr/bin/yum
change
#!/usr/bin/python
to
#!/usr/bin/python2.6
If your python2.6 was deleted, then reinstall them and point the directory in /usr/bin/yum to your python2.6 directory.
It is very simple; because the Python package was removed, the yum command won't work.
Please use below link to install packages:
Go to Link and download python package
wget http://mirror.centos.org/centos/7/sclo/x86_64/rh/python27/python27-1.1-26.1.el7.x86_64.rpm
rpm -ivh python27-1.1-26.1.el7.x86_64.rpm
Then yum will work.
this problem is that yum file start head write #!/usr/local/bin/python2.6, write binary file, is not dir, is python binary file
Resolution for CentOs 7:
dnf reinstall python-2.7.5-92.el7_9.x86_64
dnf reinstall yum
Remove python3 first using dnf if it is installed already.
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied then
first remove python follow command line
-- sudo rpm -e python
second check which package install this command line
-- sudo rpm -q python
then install package
-- sudo yum install python*
i think this problem solve
I need to force a virtualenv to use a compiled source python on my ci server (long story short: travis ci support python 2.7.3. heroku works with 2.7.6 and we insist on testing in the same environment as production) . But I fail to get virtualenv to run against it.
travis first runs this script:
if [ ! -d ./compiled ]; then
echo "creating compiled folder"
mkdir compiled
else
echo "compiled exists"
fi
cd compiled
if [ ! -e Python-2.7.6.tar.xz ]; then
echo "Downloading python and compiling"
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure
make
chmod +x ./python
else
echo "Compiled python exists!"
fi
and then:
- virtualenv -p ./python ./compiled/python276
- source ./compiled/python276/bin/activate
but when then doing python --version shows 2.7.3 instead of 2.7.6
Guess I'm missing something, Thanks for the help!
Go to the virtualenv folder, and open bin/ folder:
~/.Virtualenv/my_project/bin
Remove 'python' file, and create a symbolic link to the python executable, that you want to use, like:
cd ~/.Virtualenv/my_project/bin
mv python python-bkp
ln -s /usr/bin/python .
I played around a bit with my Python installations in OS X Mavericks.
I searched for all files which contained "python2.7" and deleted them. Now i want to point to my current Python version, which is 3.3.2.
When i type in python, i am getting this:
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory
My folder for my Python installation looks like this:
There is no Python-Path set in my .bash_profile file.
Where can i change the current Version of Python?
EDIT: Where i got the new version from? sudo pyenv install 3.3.2
EDIT: The result of which python:
I wouldn't delete the built in Python from the computer. There are applications that use Python 2, so deleting it would break them. I installed Python 3 in parallel to python 2.7.
Also not a good idea to point version 2.7 frameworks at version 3 frameworks for the above reasons. It will make for unnecessary confusion and mess that will be likely to cause issues.
Did you check out the configuration section here:
http://docs.python.org/3.3/using/mac.html
Section 4.1.3 mentions needing to changed environment variables to point to your version of Python that you want to be the default.
As well, here's how to create an alias to make Python 3 easy to access:
How to set Python's default version to 3.3 on OS X?
Don't take this the wrong way, but I would try to undo most of what you've done so far, before you get too far ahead of yourself.
Ok, i found a solution to install Python completely new. I had to use the official installer from the Python-Website.
I've downloaded the intaller and installed Python.
I moved the new installation to the Python-Versions-Folder:
sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions
Setting the group to wheel :
sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/2.7
Updating the current link:
sudo rm /System/Library/Frameworks/Python.framework/Versions/Current
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions/Current
Removing old copies
sudo rm /usr/bin/pydoc
sudo rm /usr/bin/python
sudo rm /usr/bin/pythonw
sudo rm /usr/bin/python-config
Creating the new sym-links:
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc /usr/bin/pydoc
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/python
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw /usr/bin/pythonw
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config /usr/bin/python-config
[Source]