ModuleNotFoundError: No module named 'apt_pkg' - python

I'm using Ubuntu 16.04. I tried to add a repo using terminal. While adding that, I got an error :
Traceback (most recent call last):
File "/usr/bin/add-apt-repository", line 11, in <module>
from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler
File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
I tried installing that module using various commands like :
pip3 install apt_pkg
sudo apt-get install --reinstall python3-apt
sudo apt-get install python3-apt --reinstall
Then if I tried to add that repo, the same error appeared.
The python versions I have is :
$ python3 --version
Python 3.7.9
$ python --version
Python 2.7.12
These are the versions I have in terminal. In IDLE, I have 3.5
What else shall I do to install that package apt_pkg???

Related

Unable to install python3.6 virtualenv in Ubuntu 19.10 ('no module named apport')

I've upgraded my ubuntu distro to 19.10 and now I can't install virtualenv for python3.6. I can create virtualenv for python3.7 with no issues by typing 'virtualenv NAME --python=python3' but when I replace python3 with python3.6, I get the following output.
Running virtualenv with interpreter /usr/bin/python3.6
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 25, in <module>
import distutils.sysconfig
ModuleNotFoundError: No module named 'distutils.sysconfig'
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
ModuleNotFoundError: No module named 'apport'
Python3.6 runs fine when I type in python3.6 into shell.
I have python3-pip, python3-setuptools and python3-distutils installed.
I reinstalled Ubuntu (fresh), installed python3.7-venv and python3.8-venv, installed python3.6 (manually) and it worked then with the command:
python3.6 -m venv NAME
Not sure which fixed it. I expected I'd need python3.6-venv but I didn't.

ImportError: No module named gtk

I have a PC running Ubuntu 17.10. I want to runn a python script that uses gtk. HoweverI get the following error:
Traceback (most recent call last):
File "/usr/local/bin/selectvm.py", line 3, in <module>
import gtk
ImportError: No module named gtk
I have tried already many things like:
sudo apt install python-gtk2
sudo apt install python-gtk2-dev
but none of them works. APT says they are already installed.
Try:
sudo apt-get install python-gtk2
These are the python bindings for GTK.
Graphic package nessesary to build the software-center UI.
Or:
sudo apt-get install afnix
credits

ImportError: No module named mysql

Traceback (most recent call last):
File "C:\AppServ\www\pythonWeb\MySqlConn.py", line 1, in <module>
import mysql.connector
ImportError: No module named 'mysql'
I got the above error message while trying to import mysql.connector
I'm using a Window with python 3.4.2 and Appserv 2.5.10 for Window
I've saved the python file under the folder of AppServ.
Please help.
Error clearly shows you do 'not have the module "Mysql" which you are importing in order to process further.
ImportError: No module named 'mysql'
What you can do depending on OS you are using :
Windows
pip install mysqlclient
If you need 1.2.x versions (legacy Python only), use pip install MySQL-python
Note: Some dependencies might have to be in place when running the above command.
Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)
sudo apt-get install python-pip python-dev libmysqlclient-dev
Fedora 24:
sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc
Mac OS
brew install mysql-connector-c
if that fails, try
brew install mysql
once you install the module successfully re-run your script and it should work

Python ImportError: No module named utils

I am trying to run my python script in Debian but I keep getting the following error:
traceback (most recent call last):
File "gluon/contrib/websocket_messaging.py", Line 96, in <module>
import gluon.utils
ImportError: No module named utils
I've tried:
pip install gluon
Still didn't work. I also tried:
sudo apt-get update
sudo apt-get install python-gluon
but got
Unable to locate package python-gluon
Any help would be appreciated thank you
sudo apt-get update
sudo apt-get install python3-gluon
OR
pip3 install gluon

python3.4 pip ImportError: No Module named 'pkg_resources'

pip is not working in my python3.4
$ pip install django
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
$ pip
Traceback (most recent call last):
File "usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
How do I fix this? What's the problem? Thanks
i just ran into the same error, here is what i've done to fix it:
sudo apt-get remove --purge python-pkg-resources
sudo apt-get install ubuntu-desktop
Try >sudo pip install django< I think that ought to do it
well then I suspect your pip is messed up so try
sudo apt-get install --reinstall python-pkg-resources
however if you are using Python 3 you may need to adjust to insure that you get the Python 3 environment set up rather than the P2 default
see here for more on that
How to use pip with Python 3.x alongside Python 2.x

Categories

Resources