Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to download mongo-connector using pip

I am trying to install mongo-connector on Amazon-EC2 instance using the following command:

 pip install mongo-connector

But following error flashes up everytime:

Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in                                                                                         main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 31                                                                                        7, in run
    prefix=options.prefix_path,
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 736, in                                                                                         install
    requirement.uninstall(auto_confirm=True)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_install.py", line 742                                                                                        , in uninstall
    paths_to_remove.remove(auto_confirm)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_uninstall.py", line 1                                                                                        15, in remove
    renames(path, new_path)
  File "/usr/local/lib/python2.7/site-packages/pip/utils/__init__.py", line 267,                                                                                         in renames
    shutil.move(old, new)
  File "/usr/lib64/python2.7/shutil.py", line 300, in move
    rmtree(src)
  File "/usr/lib64/python2.7/shutil.py", line 252, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "/usr/lib64/python2.7/shutil.py", line 250, in rmtree
    os.remove(fullname)
OSError: [Errno 13] Permission denied: '/usr/lib/python2.7/dist-packages/request                                                                                        s/sessions.pyo'

I thought this might be some issue with root permissions, so I tried :

sudo pip install mongo-connector

But this says ,

sudo: pip: command not found

I am using pip 8.1.2, Python 2.7.12.

Any help would be appreciated!

like image 618
Sohan Shirodkar Avatar asked Sep 13 '16 05:09

Sohan Shirodkar


2 Answers

I solved this by using the following command:

sudo `which pip`install mongo-connector
like image 131
Sohan Shirodkar Avatar answered Nov 12 '22 08:11

Sohan Shirodkar


You shouldn't be using sudo to install packages with pip. While it works, it's modifying files that should be managed by your OS package manager which isn't desirable -- see also https://stackoverflow.com/a/21056000/1931274.

If you pass --user to that command, you'll be able to install without permission issues:

pip install --user mongo-connector

Moreover, newer versions of pip (installable via pip install --user pip or using get-pip.py) print a better, more helpful message when such errors occur.

like image 42
pradyunsg Avatar answered Nov 12 '22 07:11

pradyunsg