How do I install python with proper permissions?












7















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









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











  • Are you certain you're using the right python? What does type python return?

    – user2313067
    Nov 10 '15 at 8:36











  • Can you try - pip install --user <pkg-name> pkg-name = networkx

    – Deepak
    Sep 12 '18 at 8:52
















7















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









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











  • Are you certain you're using the right python? What does type python return?

    – user2313067
    Nov 10 '15 at 8:36











  • Can you try - pip install --user <pkg-name> pkg-name = networkx

    – Deepak
    Sep 12 '18 at 8:52














7












7








7


2






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









share|improve this question
















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






linux python root






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 29 '15 at 21:49







user261217

















asked Mar 28 '13 at 13:22









ninjamarioninjamario

36116




36116













  • 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











  • Are you certain you're using the right python? What does type python return?

    – user2313067
    Nov 10 '15 at 8:36











  • Can you try - pip install --user <pkg-name> pkg-name = networkx

    – Deepak
    Sep 12 '18 at 8:52



















  • 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











  • Are you certain you're using the right python? What does type python return?

    – user2313067
    Nov 10 '15 at 8:36











  • Can you try - pip install --user <pkg-name> pkg-name = networkx

    – Deepak
    Sep 12 '18 at 8:52

















What error do you get when you try to import?

– terdon
Mar 29 '13 at 12:18





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







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





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













Are you certain you're using the right python? What does type python return?

– user2313067
Nov 10 '15 at 8:36





Are you certain you're using the right python? What does type python return?

– user2313067
Nov 10 '15 at 8:36













Can you try - pip install --user <pkg-name> pkg-name = networkx

– Deepak
Sep 12 '18 at 8:52





Can you try - pip install --user <pkg-name> pkg-name = networkx

– Deepak
Sep 12 '18 at 8:52










3 Answers
3






active

oldest

votes


















0














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.

    – user127350
    Mar 29 '13 at 15:47





















0














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|improve this answer































    -2














    I faced the same problem while installing Buildozer. I executed following commands and it worked for me. Try:




    1. Change directory to Python2.7

    2. sudo chmod 777 dist-packages

    3. sudo chmod 777 etc

    4. and then python2.7 setup.py install


    It worked for me!






    share|improve this answer





















    • 1





      -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

      – Sithsu
      Jul 24 '15 at 14:39













    • 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.

      – atmosx
      Dec 25 '15 at 21:34











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f573699%2fhow-do-i-install-python-with-proper-permissions%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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.

      – user127350
      Mar 29 '13 at 15:47


















    0














    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.

      – user127350
      Mar 29 '13 at 15:47
















    0












    0








    0







    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















    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














    share|improve this answer



    share|improve this answer








    edited Nov 29 '13 at 10:17









    karel

    9,20793138




    9,20793138










    answered Mar 28 '13 at 22:08







    user127350




















    • 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.

      – user127350
      Mar 29 '13 at 15:47





















    • 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.

      – user127350
      Mar 29 '13 at 15:47



















    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





    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





    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.

    – user127350
    Mar 29 '13 at 15:47







    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.

    – user127350
    Mar 29 '13 at 15:47















    0














    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|improve this answer




























      0














      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|improve this answer


























        0












        0








        0







        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|improve this 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 23 '17 at 17:08









        SurefootSurefoot

        1




        1























            -2














            I faced the same problem while installing Buildozer. I executed following commands and it worked for me. Try:




            1. Change directory to Python2.7

            2. sudo chmod 777 dist-packages

            3. sudo chmod 777 etc

            4. and then python2.7 setup.py install


            It worked for me!






            share|improve this answer





















            • 1





              -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

              – Sithsu
              Jul 24 '15 at 14:39













            • 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.

              – atmosx
              Dec 25 '15 at 21:34
















            -2














            I faced the same problem while installing Buildozer. I executed following commands and it worked for me. Try:




            1. Change directory to Python2.7

            2. sudo chmod 777 dist-packages

            3. sudo chmod 777 etc

            4. and then python2.7 setup.py install


            It worked for me!






            share|improve this answer





















            • 1





              -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

              – Sithsu
              Jul 24 '15 at 14:39













            • 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.

              – atmosx
              Dec 25 '15 at 21:34














            -2












            -2








            -2







            I faced the same problem while installing Buildozer. I executed following commands and it worked for me. Try:




            1. Change directory to Python2.7

            2. sudo chmod 777 dist-packages

            3. sudo chmod 777 etc

            4. and then python2.7 setup.py install


            It worked for me!






            share|improve this answer















            I faced the same problem while installing Buildozer. I executed following commands and it worked for me. Try:




            1. Change directory to Python2.7

            2. sudo chmod 777 dist-packages

            3. sudo chmod 777 etc

            4. and then python2.7 setup.py install


            It worked for me!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 29 '15 at 19:58









            Jason C

            6,89073041




            6,89073041










            answered Jan 26 '15 at 7:57









            Aman SehgalAman Sehgal

            11




            11








            • 1





              -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

              – Sithsu
              Jul 24 '15 at 14:39













            • 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.

              – atmosx
              Dec 25 '15 at 21:34














            • 1





              -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

              – Sithsu
              Jul 24 '15 at 14:39













            • 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.

              – atmosx
              Dec 25 '15 at 21:34








            1




            1





            -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

            – Sithsu
            Jul 24 '15 at 14:39







            -1 Blind use of chmod 777 (= drwxrwxrwx) is a very bad idea, specially on above mentioned directories, as that would give any user write permission (last w in drwxrwxrwx) for them. Even group write (second w in drwxrwxrwx) should not be given. Its better to just give read and execute permission on dist-packages by chmod o+r,o+X dist-packages.

            – Sithsu
            Jul 24 '15 at 14:39















            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.

            – atmosx
            Dec 25 '15 at 21:34





            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.

            – atmosx
            Dec 25 '15 at 21:34


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f573699%2fhow-do-i-install-python-with-proper-permissions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Сан-Квентин

            Алькесар

            Josef Freinademetz