Linux – How to install python with proper permissions

linuxpythonroot

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 sounds really 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

Best Answer

It's best not to try to override the system's version of Python. That version is there for the system. Customization to system's Python might cause conflicts or even open your system up to vulnerabilities. Also, system updates will probably revert your customization.

It's best to use your own version of Python, which can be done with tools such as virtualenv or pyenv.

Related Question