Version Numbers in Python - python

I'm just starting to learn python. For this I want to install the latest version on Ubuntu 18.04.
I have accessed the page https://www.python.org/downloads/.
Python 3.8.3 should be the current verison, right? I entered the following commands and expected phyton 3.8 to be installed on my computer.
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install python3.8
Unfortunately, this is not the case. At least this request shows me a different version number.
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.
>>>
Maybe I'm not reading it right?
What do the individual numbers mean and why can't I see 3.8 anywhere?

The python 3.6.9 is the default version of the Ubuntu 18.04. If You want to update to the 3.8, You can follow this step by step instructions: Configure python 3 in linux ubuntu

Related

How do I use a different python3.x version of python inside virtual environment

I have read this post but I think it is about using python2 or python3 inside virtual environment.
My problem is bit different, I want to different version of python 3 itself inside virtual environment.
I am using Ubuntu 18.04. I have three different versions of python 3 in my system and all of them seem to work.
They can be started by mentioning specific python version.
eg: python3.6, python3.7, python3.8.
But simply typing python3 will load python 3.7 because it is Anaconda's python version.
sankethbk7777#Lenovo-ideapad:/$ which python3
/home/sankethbk7777/anaconda3/bin/python3
However I want to create a virtual environment with python 3.8 as python version inside it.
(I mean inside my virtual env if I type python3 - python3.8 should boot up).
I tried using this command.
sankethbk7777#Lenovo-ideapad:/$ sudo python3.6 -m venv myproject
sankethbk7777#Lenovo-ideapad:/$ source myproject/bin/activate
(myproject) sankethbk7777#Lenovo-ideapad:/$ python3
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Above we can see that it boots python 3.6 when I type python3.
But when I tried the same for python3.8 this error shows up.
sankethbk7777#Lenovo-ideapad:/$ sudo python3.8 -m venv myproject3
Error: Command '['/myproject3/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
However, I have a working python3.8.
sankethbk7777#Lenovo-ideapad:/$ python3.8
Python 3.8.7 (default, Dec 21 2020, 20:10:35)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
sankethbk7777#Lenovo-ideapad:/$ which python3.8
/usr/bin/python3.8
I will provide any further information please help me with this.
Looks like you have Anaconda distribution of Python. I'd simply create a conda virtual environment with the version of Python you need -
conda create -n py38 python=3.8
That should create a conda virtual environment named py38 with Python version 3.8
To activate it,
conda activate py38
And that should give you Python version 3.8

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 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

Install NCurses on python3 for Ubuntu

I'm having issues installing ncurses for Python3. When I did the normal sudo apt-get install ncurses-dev, it appeared to install for Python2 but when I try to run my script for Python3, it says.
ImportError: No module named curses
How would you get ncurses to work for Python3?
I had this same problem. The issue was that ncurses was not installed on my Ubuntu installation. To fix it, I ran:
sudo apt-get install libncurses-dev
and then reinstalled Python. In my case with:
pyenv install 3.8.1
Answering y when asked continue with installation? (y/N)
This fixed the problem.
Try this:
import curses
curses is ncurses. It's also built in to python, there's nothing to install.
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-65-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Mon Oct 19 19:06:03 2015 from xxx.xxx.xxx.xxx
me#ubuntu:~$ python3
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>>

Python3 has no acces to python2 modules (ubuntu)

Im fairly new to programming and Ubuntu. Yesterday I finally managed to create a dual-boot system, so now I'm running Ubuntu 12.04 LTS.
For a school project, I need to work in Python3 with a module called SPARQLWrapper (https://pypi.python.org/pypi/SPARQLWrapper).
On my freshly installed Ubuntu, I've installed the latest version of Python. When I type "python3" in my terminal, python 3.2.3 starts so thats good.
I installed easy_install (sudo apt-get install python-setuptools), and downloaded and installed the SPARQLWrapper egg file (sudo easy_install SPARQLWrapper-1.5.2-py3.2).
If I run python2 and use "import SPARQLWrapper", it just works. But if I try the same in python3 it gives me the following error:
x#ubuntu:~$ python3
Python 3.2.3 (default, Oct 19 2012, 20:10:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named SPARQLWrapper
So my problem is that python3 isn't able to acces the same modules as my python2. How do I fix this?
Thanks!
To install packages for Python3, you need python3's setuptools.
Following are the steps to be followed to install python3's setuptools and SPARQLWrapper
sudo apt-get install python3-setuptools
sudo easy_install3 pip
pip -V This should show the pip corresponding to your python3 installation.
sudo pip install SPARQLWrapper
After doing the above mentioned steps, I get this
~$ python3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import SPARQLWrapper
>>> exit()
~$
Each Python installation has its own modules directory. In addition, Python 3 is not backwards compatible and won't generally run Python 2 code. You'll need to find a Python 3 version of the module you need and install it for Python 3.

Categories

Resources