How do I install python with proper permissions?

20,063

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.

Share:
20,063

Related videos on Youtube

ninjamario
Author by

ninjamario

Updated on September 18, 2022

Comments

  • ninjamario
    ninjamario over 1 year

    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
    
    • terdon
      terdon about 11 years
      What error do you get when you try to import?
    • ninjamario
      ninjamario about 11 years
      python t1.py Traceback (most recent call last): File "t1.py", line 3, in import networkx as nx ImportError: No module named networkx
    • ninjamario
      ninjamario about 11 years
      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
    • user2313067
      user2313067 over 8 years
      Are you certain you're using the right python? What does type python return?
    • Deepak
      Deepak over 5 years
      Can you try - pip install --user <pkg-name> pkg-name = networkx
  • ninjamario
    ninjamario about 11 years
    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
    ninjamario about 11 years
    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)?
  • Admin
    Admin about 11 years
    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.
  • atmosx
    atmosx over 8 years
    If you have to use sudo go directly with sudo -H pip install <whatever> and get over with it. This doesn't make sense. As @Sithsu point's out, having 777 permissions on anything is a bad idea anyway.