Software & AppsOperating SystemLinux

Fixing ImportError when adding PPA repository in Ubuntu 18.04

Ubuntu 9

In this article, we will be discussing the ImportError issue that users might encounter when adding a PPA (Personal Package Archive) repository in Ubuntu 18.04. This error is typically related to a problem with the Python version being used by the system.

Quick Answer

To fix the ImportError when adding a PPA repository in Ubuntu 18.04, you can try changing the Python version in the script by editing the /usr/bin/add-apt-repository file. Another solution is to check for older Python versions on your system and replace the appropriate version number in the script. If you have Anaconda installed, it can sometimes cause conflicts, so you can try removing and reinstalling the softwareproperties package.

Understanding the Error

The error message usually looks something like this:

Traceback (most recent call last):
 File "/usr/bin/add-apt-repository", line 95, in <module>
 import softwareproperties.SoftwareProperties
ImportError: No module named 'softwareproperties'

This error indicates that the system is trying to import a module called softwareproperties from the softwareproperties package, but it is unable to do so. This is often due to a circular import issue or a conflict with Python versions.

Solution 1: Changing Python Version in the Script

One possible solution is to edit the file /usr/bin/add-apt-repository. This file is a Python script that is executed when you run the add-apt-repository command. The first line of this file specifies the Python interpreter that should be used to run the script.

You can open this file in a text editor with root privileges by running the following command:

sudo nano /usr/bin/add-apt-repository

In this file, change the line #!/usr/bin/python3 to #!/usr/bin/python3.8 (or the specific version of Python you have installed). This will ensure that the correct Python version is used when running the add-apt-repository command.

Solution 2: Checking for Older Python Versions

Another possible solution is to check if you have any older versions of Python installed on your system. You can do this by running the following command:

ls -al /usr/bin | grep python

This command lists all files in the /usr/bin directory and filters the output for lines containing the word “python”. Look for versions like python3.5 or python3.6. If you find any, try replacing the #!/usr/bin/python3 line in the /usr/bin/add-apt-repository file with the appropriate version number.

Solution 3: Fixing the Issue with Anaconda

If you have Anaconda installed, it can sometimes cause conflicts with the system’s Python interpreter. In this case, you can try the following method:

First, remove the existing softwareproperties package:

conda remove softwareproperties

Then, reinstall the package with pip:

pip install softwareproperties

Please note that you should replace the version numbers in the commands to match your Python version (e.g., change python3.7 to python3.8 and 36 to 38).

Conclusion

In this article, we discussed various solutions to resolve the ImportError issue when adding a PPA repository in Ubuntu 18.04. We hope that this guide has been helpful in resolving your issue. Remember to always back up your data and configurations before making any changes to your system.

Can I use a different Python version when running the `add-apt-repository` command?

Yes, you can change the Python version by editing the /usr/bin/add-apt-repository file and modifying the first line to specify the desired Python interpreter. Remember to use the correct version number for your installed Python version.

How can I check for older versions of Python installed on my system?

You can use the command ls -al /usr/bin | grep python to list all files in the /usr/bin directory that contain the word "python". Look for versions like python3.5 or python3.6. If you find any, you can modify the /usr/bin/add-apt-repository file to use the appropriate version.

Can Anaconda cause conflicts with the system’s Python interpreter?

Yes, Anaconda can sometimes cause conflicts with the system’s Python interpreter. In such cases, you can try removing the softwareproperties package with conda remove softwareproperties and then reinstalling it with pip install softwareproperties. Make sure to use the appropriate version numbers for your Python version.

Leave a Comment

Your email address will not be published. Required fields are marked *