Unable to run pip/pip3 without root access

Hi,

In a github issue about a python program I was told that running ‘sudo pip install’ is wrong with a link for more info:

https://stackoverflow.com/questions/33004708/osx-el-capitan-sudo-pip-install-oserror-errno-1-operation-not-permitted

Still for some reason without being root I am unable to run pip or pip3.


~]: pip list
Traceback (most recent call last):
  File "/usr/bin/pip", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'
~]: pip3 list
Traceback (most recent call last):
  File "/usr/bin/pip3", line 7, in <module>
    from pip import main
ImportError: cannot import name 'main'

What is the reason (and hopefully the fix) for this?

Hi
What program, link please… is there already a python package available?

What shell are you using?

FWIW, pip list works fine here as my user. Not sure how a MacOS thread is relevant?

https://github.com/mps-youtube/mps-youtube/issues/760#issuecomment-358774035
bash
What has MacOS to do with Leap 42.3?

Hi
Exactly, the link you provided is related to MacOS issue with pip…

Not sure because the developers linux instructions say to use sudo to install?


Installation
Linux

Using pip:

[sudo] pip3 install mps-youtube


 su -
Password: 
grover:~ # pip3 install mps-youtube
Collecting mps-youtube
  Downloading mps_youtube-0.2.7.1-py3-none-any.whl (74kB)
    100% |████████████████████████████████| 77kB 1.7MB/s 
Collecting pafy!=0.4.0,!=0.4.1,!=0.4.2,>=0.3.82 (from mps-youtube)
  Downloading pafy-0.5.3.1.tar.gz
Installing collected packages: pafy, mps-youtube
  Running setup.py install for pafy
Successfully installed mps-youtube-0.2.7.1 pafy-0.5.3.1
pip3 install youtube-dl
Collecting youtube-dl
  Downloading youtube_dl-2018.1.18-py2.py3-none-any.whl (1.7MB)
    100% |████████████████████████████████| 1.7MB 153kB/s 
Installing collected packages: youtube-dl
Successfully installed youtube-dl-2018.1.18

http://thumbs2.imagebam.com/ff/be/09/f9058d724479033.jpg](http://www.imagebam.com/image/f9058d724479033)

I didn’t notice that. Thanks for sharing your observation. I have added a comment to the github issue about it.
I find it strange that you did exactly the same as I did and the program works for you… Are you running Leap 42.3? Are you starting the program as normal user (not root)?

His copy/paste starts with:

su -
Password: 
grover:~ # pip3 install mps-youtube

Isn’t it clear that he switches to user root? And that the the prompt then shows a root prompt?

And you have some story telling about that you do the same, but that something different happens. Please show that, like malcolmlewis shows it.

Perhaps you misunderstood my question. I was asking if he started the program ‘mpsyt’ as user or root (not the program ‘pip3’). That is not obvious from the screenshot he shared.

And you have some story telling about that you do the same, but that something different happens. Please show that, like malcolmlewis shows it.

It’s in the linked bug report with full details.

Hi
Yes, this system is Leap 42.3, plus in this case it’s in my signature :wink:

Installed as root (never use sudo except added with visudo for /usr/bin/build for osc command and building packages), and yes, running the application as my user.

Weird. Might that have anything to do with any security policies (or I don’t know what)? Otherwise I can’t explain why the same software on the same OS doesn’t work the same way.

Hi
If you create a test user does it run as that user without error?

Else it is probably some conflict on what you may have previously installed, adjusted your user path at all?

No. I have another user and testing with it I am getting a similar error:


otheruser@pc:~> mpsyt
Traceback (most recent call last):
  File "/usr/bin/mpsyt", line 7, in <module>
    from mps_youtube import main
  File "/usr/lib/python3.4/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib/python3.4/site-packages/mps_youtube/init.py", line 92, in init
    pafy.set_api_key(config.API_KEY.get)
AttributeError: 'module' object has no attribute 'set_api_key'

~]: mpsyt
Traceback (most recent call last):
  File "/usr/bin/mpsyt", line 7, in <module>
    from mps_youtube import main
  File "/usr/lib/python3.4/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib/python3.4/site-packages/mps_youtube/init.py", line 58, in init
    cache.load()
  File "/usr/lib/python3.4/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached'pafy'])
AttributeError: 'module' object has no attribute 'load_cache'

Else it is probably some conflict on what you may have previously installed, adjusted your user path at all?

What do you mean?
FWIW this system was installed as openSUSE 13.2, then upgraded each time a new release was out.

Hi
I mean a system path tweak somewhere, change a config etc, install other items with pip3?

If you cat /usr/bin/mpsyt is the first line (the whole shebang);


#!/usr/bin/python3

or 
#!/usr/bin/env python3

If you open the python3 interpreter and run (as your user);


 python3
Python 3.4.6 (default, Mar 22 2017, 12:26:13) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import sys
>>> from mps_youtube import main

What happens?

Hi
Also try a reinstall, suggest you become root user, no sudo please and it’s su - not just su :wink:


su -
pip3 install -I mps-youtube youtube-dl

I don’t know what is system path tweak. Please explain.
Also explain what do you mean by “change a config”
In the past I think I have ran only:

pip install --upgrade pip
pip install --upgrade pillow

and I also have installed

python-Pillow
python3-Pillow

I can’t recall installing anything else using pip/3 but it is possible.

Here is also the code you asked for:


~]: cat /usr/bin/mpsyt
#!/usr/bin/python3
...
~]: python3
Python 3.4.6 (default, Mar 22 2017, 12:26:13) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> import sys
>>> from mps_youtube import main
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib/python3.4/site-packages/mps_youtube/init.py", line 58, in init
    cache.load()
  File "/usr/lib/python3.4/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached'pafy'])
AttributeError: 'module' object has no attribute 'load_cache'
>>>

Hi
OK, force the re-install of the default openSUSE versions of pip(3) and pillow(3) and see how it goes…

Done.
What changed: now I can run pip(3) as normal user (at least I see the options of the programs, I can’t ‘install’ as user). So trying again:


# pip3 uninstall mps-youtube youtube_dl
...
  Successfully uninstalled youtube-dl-2018.1.18
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
#
# pip install --upgrade pip
Collecting pip
  Using cached pip-9.0.1-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
Successfully installed pip-9.0.1
# pip3 install --upgrade pip
Requirement already up-to-date: pip in /usr/lib/python3.4/site-packages
# pip3 install -I mps-youtube youtube-dl
Collecting mps-youtube
  Using cached mps_youtube-0.2.7.1-py3-none-any.whl
Collecting youtube-dl
  Using cached youtube_dl-2018.1.18-py2.py3-none-any.whl
Collecting pafy!=0.4.0,!=0.4.1,!=0.4.2,>=0.3.82 (from mps-youtube)
  Using cached pafy-0.5.3.1.tar.gz
Installing collected packages: pafy, mps-youtube, youtube-dl
  Running setup.py install for pafy ... done
Successfully installed mps-youtube-0.2.7.1 pafy-0.5.3.1 youtube-dl-2018.1.18
# logout
~]: mpsyt
Traceback (most recent call last):
  File "/usr/bin/mpsyt", line 7, in <module>
    from mps_youtube import main
  File "/usr/lib/python3.4/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib/python3.4/site-packages/mps_youtube/init.py", line 58, in init
    cache.load()
  File "/usr/lib/python3.4/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached'pafy'])
AttributeError: 'module' object has no attribute 'load_cache'

:frowning:

Hi
Why do you keep upgrading, consider == use the system version? Use the default openSUSE version… pip install must be run as root user, run apps as user…

I upgraded because pip recommends so. Tried also without upgrading - nothing changes. Still errors.
Any other ideas?

Hi
Force the re-install of the openSUSE pip3 (it may clean something up) and another force install of the apps;


su -
zypper in -f python3-pip python3-Pillow
pip3 install -I mps-youtube youtube-dl
exit


~]: su -
Password:
# zypper in -f python3-pip python3-Pillow
Loading repository data...
Reading installed packages...
Forcing installation of 'python3-Pillow-2.9.0-4.1.x86_64' from repository '*Main (OSS)'.
Forcing installation of 'python3-pip-7.1.2-7.1.noarch' from repository '*Main (OSS)'.
Resolving package dependencies...

The following 2 packages are going to be reinstalled:
  python3-Pillow python3-pip

2 packages to reinstall.
Overall download size: 1.6 MiB. Already cached: 0 B. No additional space will be used or freed after the operation.
Continue? [y/n/...? shows all options] (y): y
Retrieving package python3-pip-7.1.2-7.1.noarch                                                                        (1/2),   1.1 MiB (  5.2 MiB unpacked)
Retrieving: python3-pip-7.1.2-7.1.noarch.rpm .........................................................................................................[done]
Retrieving package python3-Pillow-2.9.0-4.1.x86_64                                                                     (2/2), 494.1 KiB (  1.8 MiB unpacked)
Retrieving: python3-Pillow-2.9.0-4.1.x86_64.rpm ......................................................................................................[done]
Checking for file conflicts: .........................................................................................................................[done]
(1/2) Installing: python3-pip-7.1.2-7.1.noarch .......................................................................................................[done]
(2/2) Installing: python3-Pillow-2.9.0-4.1.x86_64 ....................................................................................................[done]
# pip3 install -I mps-youtube youtube-dl
Collecting mps-youtube
  Using cached mps_youtube-0.2.7.1-py3-none-any.whl
Collecting youtube-dl
  Using cached youtube_dl-2018.1.18-py2.py3-none-any.whl
Collecting pafy!=0.4.0,!=0.4.1,!=0.4.2,>=0.3.82 (from mps-youtube)
  Using cached pafy-0.5.3.1.tar.gz
Installing collected packages: pafy, mps-youtube, youtube-dl
  Running setup.py install for pafy
Successfully installed mps-youtube-0.2.7.1 pafy-0.5.3.1 youtube-dl-2018.1.18
You are using pip version 7.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# logout
~]: mpsyt
Traceback (most recent call last):
  File "/usr/bin/mpsyt", line 7, in <module>
    from mps_youtube import main
  File "/usr/lib/python3.4/site-packages/mps_youtube/__init__.py", line 8, in <module>
    init.init()
  File "/usr/lib/python3.4/site-packages/mps_youtube/init.py", line 58, in init
    cache.load()
  File "/usr/lib/python3.4/site-packages/mps_youtube/cache.py", line 34, in load
    pafy.load_cache(cached'pafy'])
AttributeError: 'module' object has no attribute 'load_cache'
~]: