Error with python installation

Python is not functioning as it supposed to be.

I tried reinstalling using the command

sudo pacman -S python

I even tried removing it completely using different commands but was unable to,
the commands are ,

sudo pacman -R python 
sudo pacman -Rsc python

But wasn’t able to remove it because 10s of dependencies will break if python is uninstalled.

Also when I try to run python just for simple print function, it gives this kind error,

M. ~/Desktop 
○ echo "print('Nitkarsh')" > test.py

M. ~/Desktop 
○ python3 test.py
Error processing line 1 of /usr/lib/python3.10/site-packages/protobuf-3.20.1-py3.10-nspkg.pth:

  Traceback (most recent call last):
    File "/usr/lib/python3.10/site.py", line 186, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 568, in module_from_spec
  AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored
Nitkarsh

Please anyone help me out.
Thanks in advance.
I am a programming student, studying in a university and python is my ultimate tool to practice on, and learn.
How should I tackle this?

may you open a konsole and check

python -V

You cannot and you should not mess with the system python

Don’t ever do pacman -Rns python it will have catastropic results for your system

Your error is likely cause by your attempt to uninstall python.

 $ cat test.py
print('test')

 $ python test.py
test

Use virtual environment(s) as your sandbox

3 Likes

I checked using commands,

python --version
or 
python -V

It is giving the output,

Python 3.10.10

Even when I simply type python to start python in command line.
It gives, something like this ,

python
Error processing line 1 of /usr/lib/python3.10/site-packages/protobuf-3.20.1-py3.10-nspkg.pth:

  Traceback (most recent call last):
    File "/usr/lib/python3.10/site.py", line 186, in addpackage
      exec(line)
    File "<string>", line 1, in <module>
    File "<frozen importlib._bootstrap>", line 568, in module_from_spec
  AttributeError: 'NoneType' object has no attribute 'loader'

Remainder of file ignored
Python 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Is your system up to date?

Whereas

pacman -Fl python-protobuf | grep site-packages/protobuf
python-protobuf usr/lib/python3.10/site-packages/protobuf-4.21.12-py3.10-nspkg.pth
1 Like

I would say it is:

However you found the issue, 3.20.1 is more than a year old.
Placing my bet on it being installed through sudo pip.

2 Likes

Yes, it is totally updated by the command

sudo pacman-mirrors --fasttrack ; sudo pacman -Syyu ;

Before writing this, I performed the full system upgrade before writing this query and testing the python file.

Again running the same command gives me this output,

M. ~ 
○ sudo pacman -Syyu
[sudo] password for nitkarshc: 
:: Synchronising package databases...
 core                                                                                                             163.2 KiB   120 KiB/s 00:01 [#######################################################################################] 100%
 extra                                                                                                           1652.3 KiB  1412 KiB/s 00:01 [#######################################################################################] 100%
 community                                                                                                          6.8 MiB  1085 KiB/s 00:06 [#######################################################################################] 100%
 multilib                                                                                                         167.9 KiB   327 KiB/s 00:01 [#######################################################################################] 100%
:: Starting full system upgrade...
 there is nothing to do

M. ~ 

So, if lack of update is not the case then what will be?

From your other topic, you told that you messed with your system (apparently that is what you’re taught at university).

Did you use sudo pip at any time?

You could try reinstalling everything python related with pamac reinstall python\*

Does it work with another user?
What’s the output of sudo python, which python, etc.?

Please don’t post headlines as your content e.g. underlining with - or =

It can be something in your path or more likely messing with system python.

It is a sure sign of messing with system python. One possible fix is this command

sudo pacman -S --needed   $(cat /rootfs-pkgs.txt | awk '{print $1;}')

What the command does

  1. It will take the original root package list found in the root of your system
  2. parse the package names
  3. feed the result to pacman - only installing what is missing.

I’m guessing you messed up with your system. What’s the output of the following command?
pacman -Qo /usr/lib/python3.10/site-packages/protobuf-3.20.1-py3.10-nspkg.pth

Even better, you can run the following command to show Python packages that you may have installed manually at system level:
pacman -Qo /usr/lib/python3.10/site-packages/* | grep "No package owns"

I went to chatGpt.
Asked and ran few queries.

It looks like there is an error in the first line of the file /usr/lib/python3.10/site-packages/protobuf-3.20.1-py3.10-nspkg.pth. The error message indicates that there is an attribute error related to the loader object being NoneType. This could be caused by a few things, such as a missing dependency or an issue with the installation.

One possible solution is to try reinstalling the protobuf package. You can do this using the following command:

pip install --upgrade --force-reinstall protobuf

If that doesn’t work, you may need to investigate further or seek additional support from the Python community.

The error message indicates that there is an issue with the protobuf package installed in your Python environment.

One possible solution is to reinstall the protobuf package using pip. You can try running the following commands in your terminal:

pip uninstall protobuf
pip install protobuf

If the issue persists, you could try downgrading to an earlier version of the protobuf package by specifying a specific version number. For example:

pip install protobuf==3.19.4

You may need to experiment with different versions until you find one that works without issues.

Then uninstalled the same using sudo command.

And it was Solved!.

What did you run with sudo, exactly? You never use sudo with pip in Manjaro.

I just did,

sudo pip uninstall protobuf

and the problem was solved for me.

Stick to running pip under local user only. Otherwise, you’ll have more problems in the future :+1:

1 Like

If you’d paid attention 6 days ago, it would’ve been solved then.

I hope you don’t mind, but I moved the solution mark to your last post where you stated the solution clearly and succinctly.

Unless you’ve previously installed something using sudo pip and are now trying to uninstall it.

Aside from not using ‘sudo pip’…

You should also not use this as a removal command.
Its recursive+cascade … which is usually a bad idea.
It is specifically discouraged in the wiki.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.