Python 3

#distill #organize

To change python version

sudo update-alternatives --config python3    

If presented with error ModuleNotFoundError: No module named 'apt_pkg' then likely your current version of Python3's apt got messed up when changing default Python3. You likely have an apt_pkg but it's for a different version of your Python3. Some solutions may suggest a solution involving a symlink, but that can cause even more problems down the road.

Instead, you're going to look at which versions of Python3 you have to change your default version to one that matches . Then change directories to the dist-packages:

cd /usr/lib/python3/dist-packages

Run this command to locate .so files in the directory. They will look like:

sudo ln -s apt_pkg.cpython-{your-version-number}-x86_64-linux-gnu.so apt_pkg.so
Now, change your default version using #^edec4c this Private or Broken Links
The page you're looking for is either not available or private!
command, found previously in the documentation. Make sure the number you choose corresponds with one of the existing .so files. Now, try running that ppa command again and it should work.

[1] https://stackoverflow.com/questions/13708180/python-dev-installation-error-importerror-no-module-named-apt-pkg


Troubleshooting

Missing apt file

Sometimes, Python may be missing To install repo that contain's Ubuntu's apt version of git:

sudo add-apt-repository ppa:git-core/ppa -y

If it says no module called apt-pkg, it is because it is a Python3 file is missing from /usr/lib/python3/dist-packages necessary for downloading new packages.

Do the following:

sudo apt remove python3-apt
sudo apt autoremove
sudo apt autoclean
sudo apt install python3-apt

If you get this error:

add-apt-repository: command not found

then do the following:

sudo apt install software-properties-common

Verify that apt-add-repository command is now avaible to sysadmins and developer using the command/type command:

type apt-add-repository

and you should get:

apt-add-repository is /usr/bin/apt-add-repository

Version Manager


The version manager is known as pyenv