Install NCurses on python3 for Ubuntu - python

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

Related

dnf installs python3 modules only for platform-python

I'm currently working on an Ansible project which relies on python. For the ansbile package module the python3-dnf module is required.
On the destination Server (AlmaLinux 8.6) python3-dnf is already installed:
$ dnf install python3-dnf
Last metadata expiration check: 3:36:12 ago on Thu 06 Oct 2022 07:42:20 AM CEST.
Package python3-dnf-4.7.0-8.el8.alma.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
I found out, that python3-dnf is only installed for the platform-python version 3.6:
$ ls -l /usr/lib/python3.6/site-packages/
[...]
drwxr-xr-x. 9 root root 4.0K Oct 6 11:08 dnf
drwxr-xr-x. 3 root root 4.0K May 10 19:36 dnf-plugins
drwxr-xr-x. 3 root root 44 Sep 5 10:29 dnfpluginscore
$ /usr/libexec/platform-python
Python 3.6.8 (default, Sep 13 2022, 07:19:15)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dnf
>>>
Because when I try to import dnf with my latest installed python version 3.9:
Python 3.9.7 (default, Apr 21 2022, 08:39:11)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-10)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dnf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dnf'
So here is my question:
Is it possible to tell dnf ( dnf install python3-dnf ) to insall python modules not for the platform-python version but for the latest python version intalled or specify a python version?
Thanks
I found out, that python3-dnf is only installed for the platform-python version 3.6:
dnf can only install Python modules for the version of Python distributed with AlmaLinux. If you dnf install python3, you'll have a /usr/bin/python3 binary that can see Python modules installed using dnf.
If you're installing Python 3.9 via some other mechanism, you'll need to manually manage your dependencies.
I'm currently working on an Ansible project which relies on python.
Since you're using Ansible, one option is to simply use the platform-python version by setting ansible_python_interpreter=/usr/libexec/platform-python.

Version Numbers in 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

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

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.

Installing Pygame for Python 3.1.2 in Ubuntu

I'm reading the book Introduction to Computer Science Using Python and Pygame by Paul Craven (note: legally available for free online). In the book, he uses a combination of Python 3.1.3 and Pygame 1.9.1 . In my Linux Ubuntu machine, I have Python 3.1.2 but even after I sudo apt-get installed python-pygame (version 1.9.1), Python 3.1.2 can't import pygame.
Python 3.1.2 (r312:79147, Sep 27 2010, 09:45:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pygame
Python 2.6.5 imports it without fuss, however,
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
>>>
Are you aware of any issues for Linux/Ubuntu's Python 3.1.2 (Prof. Craven used Windows in his book)? How come Pygame 1.9.1 worked for Python 3.1.3 but not for 3.1.2?
Thanks for any pointers. (--,)
PyGame on Python 3 remains experimental, but these steps worked for me on Ubuntu 11.10:
sudo apt-get install mercurial python3-dev libjpeg-dev libpng12-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev libsmpeg-dev libx11-dev ttf-freefont libavformat-dev libswscale-dev
hg clone -u 01b2cb16dc17 https://bitbucket.org/pygame/pygame
cd pygame
python3 config.py
2to3 setup.py -w
python3 setup.py build
sudo python3 setup.py install
(You may remove the -u 01b2cb16dc17 to try the latest version; 01b2cb16dc17 worked for me.)
I hate to re-open an old post, but I had the hardest time installing pygame with a version of python that was not Ubuntu's default build. So I created this tutorial/ how to:
Install python3.1 and pygame1.9.1 in Ubuntu
I hopes this helps the next unfortunate soul to try this.
I installed pygame for python3 quite easily using the pip3 (a tool for installing and managing Python packages) command on Ubuntu 16.04.7 LTS.
Open a terminal and install pip3, type sudo apt install python3-pip
Now use it to install pygame for python3, type pip3 install pygame
That's it! Import the library and confirm that everything works:
# I'll try it out using the python 3 interpreter.
python3 --version
Python 3.5.2
robert#robert-E7212:~/Source/Python/python_crash_course/alien_invasion$ python3
Python 3.5.2 (default, Oct 7 2020, 17:19:02)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
# No errors, pygame was imported successfully!
>>> import pygame
pygame 2.0.0 (SDL 2.0.12, python 3.5.2)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
I followed #Søren 's method, but without the -u number.
The only complication was a few compilation errors at the last line, all due to syntax and unicode differences between Python 2 and Python 3, but with a little checking of the web documentation it was a matter of a few minutes with a text editor modifying the following files (all paths are relative to the pygame directory created during the download):
gedit build/lib.linux-x86_64-3.2/pygame/colordict.py
gedit build/lib.linux-x86_64-3.2/pygame/tests/test-utils/png.py
gedit build/lib.linux-x86_64-3.2/pygame/examples/movieplayer.py
The line numbers from the compiler error messages are great for giving you where to start. The things to look out for are:
1 remove all references to u"xxxx" colours
2 use Python3 syntax for exceptions
3 change all print commands to Python3 equivalents
Then re-issue the final compilation command:
sudo python3 setup.py install
If you miss one or two or get it wrong, just keep going round the loop editing and re-compiling till it works.
BTW I deliberately did not give details of the compiler messages, because I expect they will depend on the current build you download. The files I needed to change were for version '1.9.2pre' downloaded as of the date on this post.
Just use the below command to install pygame for Python3. I could install pygame correctly on Ubuntu 16.04 and Python Python 3.5.2.
pip3 install pygame
It's because installing the python-pygame package installs it for the default version of Python on your system, 2.6.5 in this case. You should download the pygame package and use setup.py to install it in 3.1.2.
The python-pygame package is only compiled for python2.6 and python2.7 where I am. You'll have to install it again, possibly from a python3 branch of the source.

Categories

Resources