-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied - python

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

Related

How to install sqlite3 for python3.7 in seperate directory on linux without sudo commands?

I have the problem that when I run my code on a linux server I get:
ModuleNotFoundError: No module named '_sqlite3'
So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't.
I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide.
All solutions to this sqlite3 problem that I can find requires sudo commands.
Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?
I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
While installing a python package in a Linux system without "sudo" privileges you can use
For Python 3
pip3 install --user pysqlite3
You can install any third party packages with the same method
pip3 install --user PACKAGE_NAME
The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, #Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install
$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install
$ ~/applications/bin/python
Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/

Homebrew/Python errors after trying to install Certbot

I'm trying to install Certbot on my macOS machine (10.14.4) to generate a certificate, but as usual, some Homebrew errors are standing in the way.
After running, brew update and brew install certbot, I tried a command based on sudo certbot certonly -a manual -d example.com --email your#email.com, but I get sudo: certbot: command not found. I also tried brew upgrade.
brew doctor shows:
Warning: The following directories do not exist:
/usr/local/sbin
You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/sbin
sudo chown -R $(whoami) /usr/local/sbin
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python#2
python
brew link python returns Linking /usr/local/Cellar/python/3.7.3... Error: Permission denied # dir_s_mkdir - /usr/local/Frameworks.
For some reason, it looks like I have 2 versions of Python installed now and I don't want to run any of the commands that Homebrew suggests until I know I need to. python --version returns Python 2.7.10.
Should I uninstall one of my Pythons? Is one of them the system version or is that a third installation somewhere else? Which one should I symlink and how do I get the certbot command working? Thanks in advance
sudo mkdir /usr/local/Frameworks
sudo chmod 1777
then
brew link python3
this will install your python3 on your mac
i would not deinstall python 2.7 because there are still a lot of scripts depends on python 2.7!

virtualenv error bad interpreter: No such file or directory

If I attempt to create a virtual env I get this error message, which I do not understand: bad interpreter: No such file or directory. I have reviewed this stack overflow answer and have tried to apply it in the diagnostic steps below.
This is my first day running on Mojave but I don't know if that is a factor in this issue or not.
I have created a new empty folder for the project at /Users/Wes/Dropbox/Programming/Python/glade_againn
My plan has been to run the project in the virtualenv /Users/Wes/.virtualenvs/glade_againn
However, when I attempt to use virtualenv I get this error message.
$ virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory
If I attempt to install virtualenv with PIP I am told it already exists.
$ pip install virtualenv
Requirement already satisfied: virtualenv in /usr/local/lib/python2.7/site-packages (15.2.0)
$
My current PATH is
echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/opt/local/bin:/opt/local/sbin:/usr/local/opt/postgresql#9.4/bin:/usr/local/Cellar/postgresql/9.5.4_1/bin/psql/:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS:/usr/local/git/bin:/Users/Wes/bin:/sw/bin:/usr/local/bin:/Users/Wes/.sdkman/candidates/groovy/current/bin/
If you search for pyth* across all those directories you get this list, in this order.
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6-config
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6m-config
/opt/local/bin/python2.7
/opt/local/bin/python2.7-config
/opt/local/bin/python3.4
/opt/local/bin/python3.4-config
/opt/local/bin/python3.4m
/opt/local/bin/python3.4m-config
/opt/local/bin/pythonw2.7
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
/usr/bin/python
/usr/bin/python-config
/usr/bin/python2.7
/usr/bin/python2.7-config
/usr/bin/pythonw
/usr/bin/pythonw2.7
/sw/bin/python2.7
/sw/bin/python2.7-config
/usr/local/bin/python-32
/usr/local/bin/python2-32
/usr/local/bin/python2.7-32
/usr/local/bin/python3
/usr/local/bin/python3-config
/usr/local/bin/python3.6
/usr/local/bin/python3.6-config
/usr/local/bin/python3.6m
/usr/local/bin/python3.6m-config
/usr/local/bin/pythoni
/usr/local/bin/pythoni1
/usr/local/bin/pythonw-32
/usr/local/bin/pythonw2-32
/usr/local/bin/pythonw2.7-32
Does anyone have a suggestion on how to get virtualenv to work again?
Try to reinstall using this
pip install -U --force-reinstall virtualenv
if above solution doesn't work for you
you should create a new virtualenv again because of mojave update
In my case I was renaming project and project's folder where venv has been located.
So in my case I was changing paths to python interpreter in the following files:
~/PycharmProjects/myproject/venv/bin/activate*
And modified ~/PycharmProjects/myproject/venv/bin/pip* files to:
#!/home/myuser/PycharmProjects/myproject/venv/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
To modify it I was required to login with root permissions: sudo su. The sudo vim.tiny venv/bin/pip just not allowed me to edit the files.
I've changed only the first line starting with #!/home...
In my case, I was on MacOS and I had python3.9 installed, but virtualenv was installed using python3.7 and at some point I uninstalled python3.7.
$ /usr/local/bin/virtualenv --version
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python/bin/python3.7: bad interpreter: No such file or directory
However, my python version:
$ which python3.9
/usr/local/bin/python3.9
No amount of pip or pip3 install/uninstall/install virtualenv worked for me.
Finally I did the following:
$ python3.9 -m pip install --user virtualenv
Collecting virtualenv
Using cached virtualenv-20.4.6-py2.py3-none-any.whl (7.2 MB)
<snip>
Successfully installed appdirs-1.4.4 distlib-0.3.1 filelock-3.0.12 virtualenv-20.4.6
And then
$ /usr/local/bin/virtualenv --version
virtualenv 20.4.6 from <mypath>
Yay!!
That solved the problem in my case: (my env file is called .venv)
mv .venv .venv_old
python3.7 -m venv .venv
source .venv/bin/activate
pip install wheel
pip install --upgrade pip wheel setuptools
pip install -r requirements.txt
In my case, the error shows in Github action and the root cause is the broken python symbolic link. As a workaround, I just simply re-create it during the process.
Error:
home/runner/work/_temp/810926a2-36c5-4488-ac84-6f3f57713147.sh: /home/runner/work/dataops/dataops/.venv/bin/pytest: /home/runner/work/dataops/dataops/.venv/bin/python: bad interpreter: No such file or directory
Root Cause:
/home/runner/work/dataops/dataops/.venv/bin/python: broken symbolic link to /opt/hostedtoolcache/Python/3.9.15/x64/bin/python3.9
Solution:
Add below scripts into wherever has broken link:
PYTHON_PATH=$(which python3)
source .venv/bin/activate
PYTHON_BROKEN_PATH=$(dirname $(which pip))
rm $PYTHON_BROKEN_PATH/python
ln -s $PYTHON_PATH $PYTHON_BROKEN_PATH/python
export PATH=$PATH:$(dirname $PYTHON_BROKEN_PATH)
Similar problem after switching package managers on a Mac. No reinstallation required for my use case, just updates to 2 files.
1st update config file
I updated pyvenv.cfg in the virtual environment directory (cd /to/your/venv/dir)
I had to update the home and the version settings.
home = /usr/local/bin
include-system-site-packages = false
version = 3.10.8
2nd fix symlinks
Lastly I updated the symlink to the python executable. It's in the virtual environment's bin directory.
cd /to/your/venv/dir/bin
ln -s /usr/local/bin/python3.10 python
Note, in my case there were 2 other symlinks to python executables in the venv/bin directory, python3 and python3.10. I didn't need to touch these as they were both pointers to the python symlink that was just updated.

How to recover /usr/bin/python on Debian when removed by accident

On my Debian system, I removed /usr/bin/python and /usr/bin/python2.7 by accident. Then I tried to remove all of Python entirely with the apt-get remove command and installed it again. Unfortunately, /usr/bin/python was not created again as I expected.
As a result, the python command cannot be run anymore. So I would like to recover the /usr/bin/python2.7 on the OS level.
Moreover, when I restart the Debian system, even the GNOME GUI can't be launched anymore; only the tty terminal 8 was available, almost certainly because of the absence of /usr/bin/python.
/usr/bin/python is part of the python-minimal package and /usr/bin/python2.7 is contained in python2.7-minimal, reinstall those packages:
$ sudo apt-get install --reinstall python-minimal python2.7-minimal
You can always ask your package manager what package to reinstall, dpkg -S lets you search for what package owns a given file:
$ dpkg --help | grep -- -S
-S|--search <pattern> ... Find package(s) owning file(s).
$ dpkg -S /usr/bin/python /usr/bin/python2.7
python-minimal: /usr/bin/python
python2.7-minimal: /usr/bin/python2.7
or you can use the Debian package web interface.
If apt-get install still fails with errors, then the package scripts could well be requiring Python to still work. Your next step is to then download the .deb files manually and copy those into place until you can run the apt-get install.
Determine your system architecture:
$ dpkg --print-architecture
amd64
then visit the python2.7-minimal and python-minimal package pages; on each page click on the matching architecture link under the Download header. You are taken to a list of mirrors. Download a copy of the .deb files from a suitable mirror or copy the URL to use curl -O <url> to download it directly to your affected computer.
Then unpack those files with:
$ mkdir /tmp/rescue
$ dpkg-deb -x python-minimal_*.deb rescue
$ dpkg-deb -x python2.7-minimal_*_amd64.deb rescue
You can now copy the required files from /tmp/rescue/usr/bin to your system.

My python installation is broken/corrupted. How do I fix it?

I followed these instructions on my RedHat Linux version 7 server (which originally just had Python 2.6.x installed):
beginning of instructions
install build tools
sudo yum install make automake gcc gcc-c++ kernel-devel git-core -y
install python 2.7 and change default python symlink
sudo yum install python27-devel -y
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2.7 /usr/bin/python
yum still needs 2.6, so write it in and backup script
sudo cp /usr/bin/yum /usr/bin/_yum_before_27
sudo sed -i s/python/python2.6/g /usr/bin/yum
sudo sed -i s/python2.6/python2.6/g /usr/bin/yum
should display now 2.7.5 or later:
python -V
end of instructions
The above commands and comments were taken from:
http://www.lecloud.net/post/61401763496/install-update-to-python-2-7-and-latest-pip-on
The python -v command returned this:
-bash: python: command not found
Now it is as if I have no Python installed. I don't want yum to break. I tried installing Python 3.4.
whereis python shows this:
python: /usr/bin/python2.6 /usr/bin/python2.6-config /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python3.4m-config /usr/local/bin/python2.7-config /usr/local/bin/python3.4 /usr/local/bin/python3.4m /usr/local/lib/python2.7 /usr/local/lib/python3.4 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
What should I do now? I want a working installation of Python. For certain things I'm doing, I need it to be 2.7 or higher. I want yum to still work.
Do
sudo update-alternatives --remove-all python
sudo ln -sf /usr/bin/python2.7 /usr/bin/python
I got the same issue while upgrading ubuntu 18 to 19, this made it:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2.7 /usr/bin/python
do-release-upgrade
From:
https://bugs.launchpad.net/ubuntu/+source/ubuntu-release-upgrader/+bug/1825655
For me, nothing worked except this one:
unlink /usr/bin/python3
ln -s /usr/bin/python3.7 /usr/bin/python3
Credit: https://josephgeis.dev/2020/04/upgrading-to-ubuntu-20-04-python3/
This is easily fixed by installing the python27 package via yum. It should install in /usr/bin, and may overwrite the /usr/bin/python symlink that should be pointing to 2.6. If it did (just run ls -l python* in /usr/bin to see), remove the symlink and point it back to 2.6. Next create a symlink for /usr/local/bin/python pointing at /usr/bin/python2.7. Finally, modify your ~/.bashrc or ~/.bash_profile (whichever you use) to have /usr/local/bin before /usr/bin in your PATH:
export PATH=/usr/local/bin:$PATH
at the very end of the file. This way, /usr/bin/python remains linked to Python 2.6, which is what the system expects, and when you run python at the command line it'll start up 2.7. You shouldn't have to make any changes to the yum script either - just blanket replacing python with python2.6 without understanding what you're doing is not a very good idea.
I'd also recommend installing Python 3.4 in /usr/local/bin if possible, where the binary will be named python3 by convention. Even if it installs in /usr/bin, you'll still have the choice of running python3 or python3.4 to specify which version you want. I work on a CentOS system that has each version of Python from 2.4 up to 3.4 installed, all in /usr/local/bin (I'm sure this was done manually, and not via yum), while the only python* in /usr/bin is 2.6. I couldn't find a python3 package for RedHat (I may not have been looking hard enough), so I'd recommend building the latest version from source (3.4.3 as of this writing). Unzip the tarball in a suitable directory, check out the README file, then, in the Python-3.4.3 directory, run ./configure --help to see what the options are, and if you need to change anything. As long as you have gcc installed, and don't need to link to any weird math libraries or anything, you should just be able to run:
./configure
make
make test
sudo make install
and it'll install to /usr/local/bin. Check the messages at the end of the make step, as it'll list any modules it wasn't able to build there. Fails usually happen because you don't have a required library installed, so look in setup.py in the base directory in the detect_modules() function (starting on line 449, and stretching all the way down to line 1564). Install both the lib and the -devel packages so you get the necessary headers.
This same process can also be followed if you want to install the latest 2.7.9, instead of RH's 2.7.5. One of the major (in my eyes) advantages of 2.7.9 is that pip is installed by default, making third-party module installation that much easier.
Good luck!

Categories

Resources