-1

I had pip installed and installed few packages successfuly with it. However after running the following commands. I get an error saying no module named pip:

sudo chmod 666 /Library/Python/2.7/site-packages/
pip install --upgrade git+http://git@github.com/sympy/sympy.git
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip import main
ImportError: No module named pip
b4hand
  • 9,550
  • 4
  • 44
  • 49
MAS
  • 4,503
  • 7
  • 32
  • 55

2 Answers2

3

Err... why did you run that chmod?

The issue here is that 666 is bad for directories. The permission bits, specifically the executable bit, has a different meaning for directories: in order to go into a directory, you need it to have the executable bit set. See, for example, this question or this one. Try running cd /Library/Python/2.7/site-packages/, and you'll see the problem.

So while you were trying to make the directory read-write for everyone, you actually made it so that no one can access it.

Running chmod +X /Library/Python/2.7/site-packages/ will fix this: the +X permission sets the executable bit only on directories (and files that already have +x).

Beyond this, however, do you really want something in /Library to be read-write for everyone? And have you considered (from the directory structure I'm assuming OS X) using something other than the Apple-provided Python, which often has problems with package installation, etc? I personally use the Homebrew version.

Community
  • 1
  • 1
cge
  • 9,552
  • 3
  • 32
  • 51
  • I run chmod +X /Library/Python/2.7/site-packages/ but the same error appears – MAS Apr 25 '15 at 02:59
  • i was trying to install a python package without having to use sudo – MAS Apr 25 '15 at 03:00
  • 1
    I'd strongly recommend using the homebrew version of Python then, which allows and is designed for that. Did you run just chmod, or chmod -R? – cge Apr 25 '15 at 03:01
  • i have permission denied when i run >>cd /Library/Python/2.7/site-packages/ >> ls – MAS Apr 25 '15 at 03:02
  • i only run chmod and chmod +X – MAS Apr 25 '15 at 03:03
  • You'll have to go into those directories and see what the permissions look like. I assume you can go into /Library/Python/2.7; from there, you'll have to see what the permissions look like, and fix them up. I'll note that chmodding like this will not let you easily use pip without sudo, especially since you've already installed things as root. – cge Apr 25 '15 at 03:05
  • how do i do this? This is what i get when using: ls -l total 0 drwx--x--x 32 root wheel 1088 Apr 25 06:31 site-packages – MAS Apr 25 '15 at 03:07
  • Use `virtualenv`, and you won't need `sudo` to install packages via `pip`. – b4hand Apr 25 '15 at 03:10
  • ill give it a try but first i have to fix my pip @b4hand – MAS Apr 25 '15 at 03:19
  • 1
    No you don't. `virtualenv` will install a separate isolated working `pip` environment. – b4hand Apr 25 '15 at 03:23
  • 1
    Err... how did that happen? That's not 666 or 777. Try `chmod +rwX /Library/Python/2.7/site-packages/` – cge Apr 25 '15 at 05:11
-1
sudo apt-get install --reinstall python-pkg-resources
Frank T
  • 8,268
  • 8
  • 50
  • 67
  • 1
    Don't answer in one-liners without any explanation! See [answer]! – jkalden Feb 20 '17 at 09:36
  • Obviously you didn't read my link. Your answer lacks explanation and information and simply doesn't match the requirements for a good answer. You want to know why? See the link in my first comment. Take the [tour]! Read [ask] and [answer]. that's my recommendation... – jkalden Feb 27 '17 at 08:05