I created an Azure Redhat Linux VM that came pre-installed with python 2.7.5. I need to update it to the latest version so I can then install databricks CLI on it to access DBFS. Need help on how to do this, please.
Tried:
$ sudo yum update python
Result:
Loaded plugins: langpacks, product-id, search-disabled-repos
No packages marked for update
I need at least 2.7.9 version of python to be able to install databricks CLI.
I don't have an on-prem Linux server. Only have Windows and don't have admin access to install python on PowerShell.
Generally, the default Python version of a Linux distribution is depended on the Linux distribution version. So if you created the latest version of RedHat Linux on Azure VM, you can upgrade the default Python 2 version via the steps below.
Check whether exists an upgrade version of Python you want via yum info python or yum list python.
If there is an upgrade version, you can upgrade it via yum -y upgrade python or yum -y update python.
For older Linux distribution, there is an upper limit version of Python, such as 2.7.5 for Python 2 on your current RedHat Linux VM I guess. So you could not simply upgrade it via the system package manager yum to install an upper version from default package repository. Then, we need to download the source code of a specified version of Python to compile and install on the current environment.
There is a blog How to Install or Upgrade Python in Linux Systems introduces how to do.
Here is my steps to install Python 2.7.9.
Make sure there is compiler tool kits gcc & g++ installed in your current environment. To check via gcc -v and g++ -v. To install via yum -y install gcc gcc-c++ and other dependencies like zlib, zlib-dev, openssl, openssl-dev, ncurses-libs, readline-devel, sqlite-devel, bzip2-devel, gdbm-devel, libdbi-devel, and so on.
Download the source code package from the offical Python FTP via $ wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz.
Decompress it via tar -zxvf Python-2.7.9.tgz.
cd Python-2.7.9.
If you just want to use Python 2.7.9 temporarily, the next steps are as below.
./configure && make
To configure the PATH environment variable via export PATH=$HOME/<the parent path>/Python-2.7.9/:$PATH
Then, you can use Python 2.7.9 in the current Shell session.
If you want to install Python 2.7.9 into /usr/local and not break the current default Python version to avoid the possible system crash issue, the next steps as as below.
./configure --prefix=/usr/local
make && sudo make altinstall
Then, you can use Python 2.7.9 via python2.7. You can check all Python version via python -V, python2 -V and python2.7 -V.
Hope it helps.
Related
In order to install older version of keras, tensorflow 1.10.0 is needed. That should solve compatibility issues with an algorithm I am trying to run. TO be able to install these older versions of tensorflow and keras and older version of python is required. I have tried to work with different algorithm using my linux system, terminal and have not been successful so far. I wish to know how to downgrade my current python version (replacing my version on the OS system or through a virtual environment) to python 3.5.6 or even 2.7.
The code I am trying to run is FSA-Net at https://github.com/shamangary/FSA-Net
I am trying to run the demo 'sh run_demo_FSANET.sh' after cloning to my local computer.
I do not use anaconda. I use pip.
I could not install Pyenv on my ubuntu.
I also donot have brew I have qbrew, which does not follow with the other commands suggested at How to downgrade python from 3.7 to 3.6.
Thank you in advance.
You can have multiple versions of Python at the same time.
First, install your python ver (alongside your present version):
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.5.6
Then create & setup your project:
cd your_project
# Create venv
python3.5 -m venv venv
# Source
source venv/bin/activate
# Install everything you need
pip install {package_name}
That's it! You should be good to go.
NOTE: you did not specify what version of Linux you have,
so I assumed it's Ubuntu. But the process should be the same for the other versions of Linux also (just different commands).
I am using python 3.7 in google colab, but for some reason when I am connected with a linux server in google cloud the python becomes 2.7. How can I change it? Note that python 3.7 is already installled in the server.
I tried these things but weren't helpful.
apt update
sudo apt install python3-pip
alias pip='pip3'
I checked also these sites https://cloud.google.com/python/docs/setup#linux_2, How do I install Python 3.7 in google cloud shell but didn't solve my problem.
Edit
By doing Runtime --> Change runtime I can see only this, which the options are 'non', 'gpu', 'tpu'.
You can check your Python version at the command line by running python --version. In Colab, we can enforce the Python version by clicking Runtime -> Change Runtime Type and selecting python3.
Python 2.7 is expected to be removed in Debian "testing", the basis of gLinux. This is expected to happen shortly after the next major version, Debian Bullseye, is released.
You need to migrate Python 2.7 code to Python 3 and remove python-is-python2 packages you might have installed.
When Python 2.7 is removed from gLinux, python-is-python2 will be uninstalled.
If you have software that requires /usr/bin/python to work, but can be used with Python 3, you should install python-is-python3.
You can change Python version by running the following commands in terminal:
pip install virtualenv
virtualenv venv --python=python3
This only works if you have Python2.7 installed at the system level (e.g. /usr/bin/python2.7).
You can find the path to your Python installation with
which python3
virtualenv venv --python=/usr/local/bin/python3
And check the version using python3 –version.
So actually the answer of my question comes from this post How to completely uninstall python 2.7.13 on Ubuntu 16.04.
Everyone who have a similar problem the first thing that he/she should do is to unistall python 2.7 by using either
sudo apt install --reinstall python python-apt python2.7-minimal
or
sudo apt purge python2.x-minimal
and then install python 3.7, by using
sudo ln -s /usr/bin/python3 /usr/bin/python
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# Confirm the new version of Python: 3
python --version
I'm new for linux and python ,yesterday I update my python from 2.6.6 to 2.7.13,but when i finished these command "./configure 、make、make install " ,then run "python“ ,I got "command not found ". thanks for help
I completely agree with the answer provided by #holdenweb. Just to add some more details considering for a tyro:
If you need access to a newer version of Python you must compile it yourself and install it side-by-side with the system version.
Here are the steps necessary to install Python 2.7. Execute all the commands below as root. Either log in as root temporarily or use sudo.
Install development tools
In order to compile Python you must first install the development tools:
The first one is :
yum groupinstall "Development tools"
You also need a few extra libraries installed before compiling Python or else you will run into problems later when trying to install various packages:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
Download, compile and install Python
The --no-check-certificate is optional
cd /opt
wget --no-check-certificate https://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 --prefix=/usr/local
make && make altinstall
It is important to use altinstall instead of install, otherwise you will end up with two different versions of Python in the filesystem both named python.
After running the commands above your newly installed Python 2.7 interpreter will be available as /usr/local/bin/python2.7 and the system version of Python 2.6.6 will be available as /usr/bin/python and /usr/bin/python2.6.6.
Now Python is an essential component of many operating systems, the safest rule is leave the system's Python to the system, and don't modify it yourself. That way you can be sure you aren't going to interfere with any OS code that depends on a specific version of Python.
If you want some other version of Python to be your own default, install it somewhere like /usr/local/bin (the default installation for most Linux systems will put it there by default) and then put that directory at the front of your shell's PATH to ensure that the python command gets your version instead of the system's (which will remain as /usr/bin/python).
I would recommend that you re-link /usr/bin/python to point to /usr/bin/python2.6 and then the PATH adjustment mentioned above (but in your case adding /usr/local/python2.7.13/bin, which is where you seem to have installed your updated Python) should be all you need to do.
I have compiled and installed python2.6 on my system with python2.7 installed as well. Unfortunately, I did not do it correctly and now my default python is 2.6. When I enter
which python && /usr/bin/env python -V
I am given
/usr/local/bin/python
Python 2.6.9
How can I change this? I checked my $PATH variable, but anything relevant to python is not there. The desired version is
/usr/bin/python
Ideally, you should NOT change the default python on your systems. Too many things are dependent on it. HOwever, you can install a newer version and use it in your scripts. Here's is an abridged version of how to do this
DOWNLOAD AND INSTALL PYTHON 2.7
The Fedora system comes stock with Python 2.6. As I've learned, you do not want to remove/overwrite 2.6 as other system tools use it. So you will want to install it as an "alternate" version.
First download Python 2.7 from the Python Org download website!. At the time of this writing, the latest release is Python 2.7.6. All of these instructions assume you are doing these as root. You can alternatively use sudo.
NOTE: the final step is to use make altinstall. This is important.
wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar xvzf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/local
make
You can verify the installation:
[root#centos6_4_32 ~]# python2.7 --version
Python 2.7.6
make altinstall
DOWNLOAD AND INSTALL PIP
The pip tool is used to install Python modules (a.k.a. "packages", "libraries", etc.). You need to install the latest set of tools and ensure they are installed in the Python 2.7 area of you system. You do NOT want to use the stock pip tool since it will install in the Python 2.6 area. The following instructions were taken from this website. At the time of this writing, the latest version of pip is 1.4.1.
# copy the setup scripts
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
# now make sure you use python2.7 when installing
# these tools!
python2.7 ez_setup.py
python2.7 get-pip.py
NOTE: Ensure that you are using python2.7 when running these scripts, and not just python.
You can verify the installation:
[root#centos6_4_32 ~]# pip-2.7 --version
pip 1.4.1 from /usr/local/lib/python2.7/site-packages (python 2.7)
NOTE: use pip-2.7 and not just pip.
Source: http://forums.juniper.net/t5/Network-Automaniac/Installing-Python-2-7-on-CentOS-6/ba-p/217295
I recently installed Python 2.7.3 on a CentOS machine by compiling from source. Python 2.7.3 is installed at /opt/python2.7 and when I installed it I just changed /usr/bin/python to point to the new version. This apparently is wrong though because when I did it it broke yum. I would get the following.
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.3 (default, May 15 2012, 17:45:42)
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
I changed /usr/bin/python to point back to the python 2.6.6 but now 2.6.6 is the default version of python. Any idea how to fix this?
I have written a quick guide on how to install the latest versions of Python 2 and Python 3 on CentOS 6 and CentOS 7. It currently covers Python 2.7.13 and Python 3.6.0:
# Start by making sure your system is up-to-date:
yum update
# Compilers and related tools:
yum groupinstall -y "development tools"
# Libraries needed during compilation to enable all features of Python:
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel expat-devel
# If you are on a clean "minimal" install of CentOS you also need the wget tool:
yum install -y wget
The next steps depend on the version of Python you're installing.
For Python 2.7.14:
wget http://python.org/ftp/python/2.7.14/Python-2.7.14.tar.xz
tar xf Python-2.7.14.tar.xz
cd Python-2.7.14
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
# Strip the Python 2.7 binary:
strip /usr/local/lib/libpython2.7.so.1.0
For Python 3.6.3:
wget http://python.org/ftp/python/3.6.3/Python-3.6.3.tar.xz
tar xf Python-3.6.3.tar.xz
cd Python-3.6.3
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
# Strip the Python 3.6 binary:
strip /usr/local/lib/libpython3.6m.so.1.0
To install Pip:
# First get the script:
wget https://bootstrap.pypa.io/get-pip.py
# Then execute it using Python 2.7 and/or Python 3.6:
python2.7 get-pip.py
python3.6 get-pip.py
# With pip installed you can now do things like this:
pip2.7 install [packagename]
pip2.7 install --upgrade [packagename]
pip2.7 uninstall [packagename]
You are not supposed to change the system version of Python because it will break the system (as you found out). Installing other versions works fine as long as you leave the original system version alone. This can be accomplished by using a custom prefix (for example /usr/local) when running configure, and using make altinstall (instead of the normal make install) when installing your build of Python.
Having multiple versions of Python available is usually not a big problem as long as you remember to type the full name including the version number (for example "python2.7" or "pip2.7"). If you do all your Python work from a virtualenv the versioning is handled for you, so make sure you install and use virtualenv!
vim `which yum`
modify #/usr/bin/python to #/usr/bin/python2.4
Put /opt/python2.7/bin in your PATH environment variable in front of /usr/bin...or just get used to typing python2.7.
pythonz, an active fork of pythonbrew, makes this a breeze. You can install a version with:
# pythonz install 2.7.3
Then set up a symlink with:
# ln -s /usr/local/pythonz/pythons/CPython-2.7.3/bin/python2.7 /usr/local/bin/python2.7
# python2.7 --version
Python 2.7.3
ln -s /usr/local/bin/python2.7 /usr/bin/python
Alright so for me, the error being fixed is when there are different versions of python installed and yum can't find a certain .so file and throws an exception.
yum wants 2.7.5 according to the error.
which python gives me /usr/bin/python
python --version gives me 2.7.5
The fix for me was append /lib64 to the LD_LIBRARY_PATH environment variable.
The relevant content is /lib64/python2.7 and /lib64/python3.6.
export LD_LIBRARY_PATH=/lib64:$LD_LIBRARY_PATH
Fixed the yum error for me with multiple python versions installed.
Daniel's answer is probably the most ideal one as it doesn't involve changing OS files. However, I found myself in a situation where I needed a 3rd party program which invoked python by calling usr/bin/python, but required Python 2.7.16, while the default Python was 2.7.5. That meant I had to make usr/bin/python point to a Python version of 2.7.16 version, which meant that yum wouldn't work.
What I ended up doing is editing the file /usr/bin/yum and replacing the shebang there to use to the system default Python (in my case, that meant changing #! /usr/bin/python to #! /usr/bin/python2). However, after that running yum gave me an error:
ImportError: No module named urlgrabber.grabber
I solved that by replacing the shebang in /usr/libexec/urlgrabber-ext-down the same way as in /usr/bin/yum. I.e., #! /usr/bin/python to #! /usr/bin/python2. After that yum worked.
This is a hack and should be used with care. As mentioned in other comments, modifying OS files should be last resort only.
I recommend, instead, updating the path in the associated script(s)
(such as /usr/bin/yum) to point at your previous Python as the interpreter.
Ideally, you want to upgrade yum and its associated scripts so that they
are supported by the default Python installed.
If that is not possible, the above is entirely workable and tested.
Change:
#!/usr/bin/python
to whatever the path is of your old version until you can make the
above yum improvement.
Cases where you couldn't do the above are if you have an isolated machine,
don't have the time to upgrade rpm manually or can't connect temporarily
or permanently to a standard yum repository.
If you want to try out rpm packages, you can install
binary packages based on the newest Fedora rpms, but recompiled
for RHEL6/CentOS6/ScientificLinux-6 on:
http://www.jur-linux.org/download/el-updates/6/
best regards,
Florian La Roche
I read a piece with a comment that states the following commands can be run now. I have not tested myself so be careful.
$ yum install -y epel-release
$ yum install -y python36