Altinstall of Python 2.7.13 on RHEL7 just launches system version - python

I'm doing an altinstall of Python 2.7.13 on RHEL7 which has 2.7.5 installed. Here's how I'm building from source:
$ ./configure --prefix=/usr/local --enable-shared
$ make && sudo make altinstall
However, even when I tried to access this altinstall directly, I'm getting the system Python, rather than the altinstall. I've put SELinux into permissive mode and get the same result.
$ /usr/local/bin/python2.7 -V
Python 2.7.5
$ getenforce
Permissive
and when I enter the interpreter
$ /usr/local/bin/python2.7
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
I'm at a loss here. From everything I've been reading this should work. The only thing I can think of is that since they're both 2.7.X there's some sort of conflict, but I thought that was the reason for altinstalls in the first place.

I believe you're running into the same problem as in this thread: Strange Python compilation results with “--enable-shared” flag.
To fix it, you need to use:
LD_RUN_PATH=/usr/local/lib make && sudo make altinstall
(So that the generated binary looks for the correct shared Python library.)
As a sidenote, I think you'd be much better served by Red Hat Software Collections when you need to have different Python versions on one system. Check out About RHSCL.

Related

How to fix PYTHONPATHS and a weird error of Python?

Yesterday, I did put my laptop on upgrade 19.10 to 20.04 but due to power failure, that became a partial-upgrade, the system broked. I resolved everything but my Django app wasn't running due to PYTHONPPATH so I tried uninstalling python3 and everything got broken. I re-installed that again.
Now when I do python --version I got
bash: python: command not found
whereas python3 --version gives correct answer.
Python 3.8.2
I have python2.7 and python3 both installed. So for now, my Python is not working and also I think I've messed up my PYTHONPATH and I really don't know what I'm going to do now.
My ./~bashrc file looks like below :
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME=$HOME/gems
export PATH=$HOME/gems/bin:$PATH
# Install Ruby Gems to ~/gems
export GEM_HOME="$HOME/gems"
export PATH="$HOME/gems/bin:$PATH"
I'm using Ubuntu 20.04.
Please specify how are you running your project and what exactly is the issue you are facing. May be you can paste the error message you get.
For python command,
In Linux, generally the base commands (like python) without version in it, would actually be pointing the specific (python) version executable through symbolic links (or simply links).
[foo#linuxbox ~]$ ls -l /usr/bin/python
lrwxrwxrwx. 1 root root 16 Feb 9 16:26 /usr/bin/python -> /usr/bin/python3
These links can be created or even edited to our need to point to the version we need. Use the below command to link python to python3. This is equivalent to setting alias for python3 as python but bit more than that as all users/process can run python but in case of alias the tool/user must be running from bash or corresponding shell where alias was created.
sudo ln -f -s /usr/bin/python3 /usr/bin/python
I feel in Ubuntu 20 you have to run command python2 to go into 2.7.* interpreter. python and python3 command both refers to Python3. But anyway your python command should work.
#ideapad:~$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python2
Python 2.7.17 (default, Apr 15 2020, 17:20:14)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
ideapad:~$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
To solve your issue, use an alias. Place command alias python=python3 into ~/.bashrc file, after adding this run source ~/.bashrc.
Other solutions:
run command which python it will reveal the location of installed Python and then try adding the location given by which python command to PYTHONPATH
Reinstall your python - sudo apt install python

How do I initialize / switch to python3 from python2 in terminal?

I just created my first AWS EC2 instance. I used sudo yum install python3 -y to install Python3 but when I check the version via python --version it says Python 2.7.16. How do I switch versions?
You can either invoke python 3 with python3 directly from the terminal, or create an alias by adding the following line to your ~/.bashrc or ~/.bash_aliases file:
alias python=python3
More details and troubleshooting tips available in this related question.
There are a couple of ways to do this:
You could explicitly request python3, invoking it as-is, instead of just python, i.e.:
$ python3
Python 3.7.6 (default, Feb 26 2020, 20:54:15)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
As per #Nick Walsh's answer, you can create a shell alias(1) that just expands python to python3 by putting the following either into .profile, .bashrc, or even .bash_aliases:
alias python=python3
Granted python3 is in your PATH, this will work without a hitch, with the added benefit that this is a per user setting, meaning you won't be changing the system-wide python interpreter (since python remains pointing to /usr/bin/python2). If you'd like, you can opt for a system-wide alias as well by modifying /etc/profile or /etc/bashrc, adding the alias there.
You could replace the python symlink, linking it to python3 instead.
You can achieve this using ln(1) (pay close attention to the # vs. $ prompt, meaning you require root privileges to issue this command. Using sudo will suffice):
# ln -sf /usr/bin/python{3,}
I'm leveraging bash's string expansion features to avoid repetition. The command effectively expands to:
# ln -sf /usr/bin/python3 /usr/bin/python
This is probably recommended for the sake of portability (when it comes to scripting).
The latter alternative might work up until python gets updated, replacing the default python interpreter again with python2. #kichik pointed out the use of alternatives(8) to adequately (and truly persistently) configure your python interpreter.
As per this answer, you can issue the following commands to install and configure your default python interpreter:
# alternatives --install /usr/bin/python python /usr/bin/python2 50
# alternatives --install /usr/bin/python python /usr/bin/python3 60
# alternatives --config python
There are 2 programs which provide 'python'.
Selection Command
-----------------------------------------------
1 /usr/bin/python2
*+ 2 /usr/bin/python3
Enter to keep the current selection[+], or type selection number: 2
$ alternatives --display python
python - status is manual.
link currently points to /usr/bin/python3
/usr/bin/python2 - priority 50
/usr/bin/python3 - priority 60
Current `best' version is /usr/bin/python3.
$ python
Python 3.7.6 (default, Feb 26 2020, 20:54:15)
[GCC 7.3.1 20180712 (Red Hat 7.3.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

How to downgrade to python 2.7.5 and make it as default in CentOs7?

CentOS7 comes with python 2.7.5 and I followed https://myopswork.com/install-python-2-7-10-on-centos-rhel-75f90c5239a5 and installed python 2.7.10 to meet yugabyte db installation pre-requisites.
Executed the following commands, without considering consequences:
alias python="/usr/local/bin/python2.7"
ln -fs /usr/bin/python2.7 /usr/bin/python
alternatives --install /usr/bin/python python /usr/bin/python2.7 50
Now, python 2.7.10 became default:
[root#srvr0 ~]# python
Python 2.7.10 (default, Jan 27 2020, 17:09:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
rpm lists installed packages list contains, python-2.7.5
[root#srvr0 python]# rpm -qa | grep python
...
python-2.7.5-86.el7.x86_64
...
I am getting error while invoking yum command:
[root#srvr0 ~]# yum install mysql
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.10 (default, Jan 27 2020, 17:09:56)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
I tried installing python 2.7.5:
[root#srvr0 python]# rpm -ivh python-2.7.5-76.el7.x86_64.rpm
error: Failed dependencies:
python-libs(x86-64) = 2.7.5-76.el7 is needed by python-2.7.5-76.el7.x86_64
python < 2.7.5-86.el7 conflicts with (installed) python-devel-2.7.5-86.el7.x86_64
[root#srvr0 python]#
Please help me in getting back the default python 2.7.5 along with required default packages/modules.
Maybe you can try uninstall orginal python version , and reinstall your specific python version ,i have forget the exact download command in CentOs7 , but in ubuntu it is sudo apt-get install python==2.7.5
after you install , try to use ln -s python2.7.5 python,so that every time you call python , it is python version 2.7.5

How to stop Python 2.7 running when "python3" is called in terminal?

When I run python3 in terminal, it states that I am running Python 2.7.10. I updated a pip package and conda package and since I have no way of running python3. I am sure python 2 is running as writing 'print "hello"' works which is should not, if python3 successfully ran.
Daves-MBP:Desktop dave$ python3
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
This should NOT work if python3 is running.
How can I get python3 running when I want to?
Do I need to set up the environment path, or something else?
Good news. I have solved the problem myself (using a different forum article)
Setting the alias to the different python version in terminal solves this error.
$ alias python='python3.7'
$ alias python2='python2'
$ alias python3='python3.7'
So when I type 'python' in terminal, python3 is called. Not sure if my issue was an alias or path issue, as I was not aware of both concepts before I had the problem.
Make sure you have the python version installed before typing in python3.7 or 3.5 for instance.
Also, python3 alone does not work.
Type python3.1 or python3.3

Why is my sys.prefix being set to '/usr'?

I'm trying to install python2.7 on linux from source on a system where I don't have admin rights. There is a version installed in /usr/bin but I want my install to be completely independent of this. I'm also testing builds with a newer gcc compiler so I want to avoid prebuilt packages like anaconda.
I downloaded python source and ran the following
./configure --prefix=$INSTALL_DIR --exec-prefix=$INSTALL_DIR --enable-shared --enable-optimizations --enable-unicode=ucs4
make
make install
where $INSTALL_DIR is where I want my install to go.
The configure and build ran without error, however, when I run the built python executable
$INSTALL_DIR/bin/python
and check the search paths it is still using /usr as the prefix:
Python 2.7.13 (default, May 31 2017, 17:58:17)
[GCC 7.1.1 20170503 (Red Hat 7.1.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.prefix
'/usr'
This means modules I install into $INSTALL_DIR aren't being found. Also running pip install XXX doesn't do anything if the module is already installed in the /usr space.
I'd like to avoid using things like $PYTHONPATH and $LD_LIBRARY_PATH so is there a way to set this up where sys.prefix and sys.path point to $INSTALL_DIR and know nothing about the system level install?
Thanks for your help.
Stop passing flags other than prefix to configre, and your python will give correct sys.path that stats with $INSTALL_DIR.
$ ./configure --prefix=$INSTALL_DIR

Categories

Resources