Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

So python installed probably fine. Or perhaps it was already on here (I'm using xubuntu 12.10).

But I tried to install networkx today using pip:

pip install networkx

then says I don't have permission. So I sudo the above command. Installs without errors.

Now I can't import networkx without being root. I'm fairly confident you shouldn't have to be root all the time to run python scripts. That shit sounds dangerous.

easy_install says this:

easy_install networkx

error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the installation directory:

[Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-13206.pth'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

/usr/local/lib/python2.7/dist-packages/

Perhaps your account does not have write access to this directory? If the installation directory is a system-owned directory, you may need to sign in as the administrator or "root" account. If you do not have administrative access to this machine, you may wish to choose a different installation directory, preferably one that is listed in your PYTHONPATH environment variable.

For information on other options, you may wish to consult the documentation at:

http://packages.python.org/distribute/easy_install.html

Please make the appropriate changes for your system and try again.

I also tried installing into ~/.networkx (a subfolder i created as not-root) and I get the same permissions error. I chmod 777 /usr/local/lib/python2.7/dist-packages and try to install, same permissions error.

pip uninstall and sudo easy_install causes the same problems as the pip install.

which by the way is:

python t1.py

Traceback (most recent call last): File "t1.py", line 3, in import networkx as nx ImportError: No module named networkx

sudo python t1.py

H: 10 ... more stuff that indicate its importing and working fine ...

Clearly, I've just been a noob at some point in either installing python, or... anywhere else. I don't know where, it could be anywhere. Has anyone encountered this before or is cluey enough to know what's going on? I need your halp. Cheers.

EDIT: (More info for Radoo)

sean@potatocake:~$./sh.sh
User is not part of the group which has access to that directory.
/usr/local/lib/python2.7/dist-packages needs access.

sean@potatocake:~$ll /usr/local/lib/
total 12
drwxrwxr-x 3 root root  4096 Mar 28 19:00 perl
drwxrwsr-x 4 root staff 4096 Oct 18 04:07 python2.7
drwxrwsr-x 3 root staff 4096 Oct 18 04:05 python3.2

sean@potatocake:~$ll /usr/local/lib/python2.7/
total 8
drwxrwsr-x 32 root staff 4096 Mar 28 23:13 dist-packages
drwxrwsr-x  2 root staff 4096 Oct 18 04:07 site-packages

note: I chmod'd this back to 775 when a non-sudo pip still didn't work.

sean@potatocake:~$groups
sean adm cdrom sudo dip plugdev lpadmin sambashare

sean@potatocake:~$sudo useradd -G staff sean
useradd: user 'sean' already exists
share|improve this question
    
What error do you get when you try to import? –  terdon Mar 29 '13 at 12:18
    
python t1.py Traceback (most recent call last): File "t1.py", line 3, in import networkx as nx ImportError: No module named networkx –  ninjamario Mar 29 '13 at 12:40
    
Ugh sorry, can't make that pretty. If you look above in the original post it is there nicely under the results for 'python t1.py' - cheers –  ninjamario Mar 29 '13 at 12:41

1 Answer 1

I'm definitely not an expert on this, but here are my thoughts.

It's good to have your install as root, so nobody can modify your files and configurations, but root and sudoers. So I guess your installation is OK. If you want to install a new package you should be root.

As for the permission error, you said you did this: chmod 777 /usr/local/lib/python2.7/dist-packages. Well, this offers access just to that directory at the end. You might have some parent directories which may not have access permissions (execute rights), which can cause your issue.

To check permissions for the current user on all those directories, you'll have to do something like this (I guess you can find a better version but anyway) for each of them:

dir="<directory_path>"
user_groups=$(groups <user>)
dir_group=$(stat "$dir" | cut -d' ' -f6)

if ! [[ "$dir_group" =~ "\\b$user_groups\\b" ]]; then printf "User is not part of the group which has access to that directory.\n"; fi

dir_access=$(stat "$dir" | cut -d' ' -f3)
group_dir_exec_access=${dir_access:6:1}

if [ "$group_dir_exec_access" != "x" ]; then printf "This dir needs access.\n"; <add some sudo chmod stuff to give access to group> fi

I hope this helps.

share|improve this answer
    
Thanks for the quick reply, sorry it took me a while to get back to you (sleep, then a full day =P). I pasted a bunch of (hopefully) relevant command outputs in an edit section up top. Your script is sh.sh btw, in case you can't recognise your own printf contents ;) –  ninjamario Mar 29 '13 at 12:17
    
Oops, just meant to newline, not submit comment. So if I want to install a new package I should be root? In that case the permissions thing should be 775 right. Or possibly even less. 755. Regardless, I can install the package fine if I sudo it but then I can't import the package unless python is running as root - how can I make networkx available to my normal user (sean)? –  ninjamario Mar 29 '13 at 12:20
    
I didn't get your printf comment, but anyway, the networkx file should have read and execute rights I guess for the group, and sean should be in that group. –  Radoo Mar 29 '13 at 15:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.