{"id":5770,"date":"2016-01-21T20:46:14","date_gmt":"2016-01-21T19:46:14","guid":{"rendered":"http:\/\/emilkirkegaard.dk\/en\/?p=5770"},"modified":"2016-01-22T18:21:14","modified_gmt":"2016-01-22T17:21:14","slug":"python-virtualenv-pip-and-sudopermissions","status":"publish","type":"post","link":"https:\/\/emilkirkegaard.dk\/en\/2016\/01\/python-virtualenv-pip-and-sudopermissions\/","title":{"rendered":"python, virtualenv, pip and sudo\/permissions"},"content":{"rendered":"<p>The problem:<\/p>\n<ul>\n<li>To install a virtualenv (virtual environment for python) under a common (not user) folder, so that it is accessible to other users.<\/li>\n<\/ul>\n<p>If we try without using sudo, we get a permission error:<\/p>\n<pre>[go into virtualenv called env]\r\npip3 install fibo\r\n&gt;[lots of stuff]\r\n&gt;PermissionError: [Errno 13] Permission denied: '\/django\/env\/lib\/python3.4\/site-packages\/Fibo.py'<\/pre>\n<p>If we try with sudo, it installs it in the wrong location:<\/p>\n<pre>sudo which pip3\r\n&gt;\/usr\/bin\/pip3<\/pre>\n<p>I.e. it is installing it in the system-wide location. This isn&#8217;t accessible from within the virtualenv. What to do? Some links I found:<\/p>\n<ul>\n<li><a href=\"http:\/\/askubuntu.com\/questions\/234758\/how-to-use-a-python-virtualenv-with-sudo\">How to use a python virtualenv with sudo?<\/a><\/li>\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/common-python-tools-using-virtualenv-installing-with-pip-and-managing-packages\">Common Python Tools: Using virtualenv, Installing with Pip, and Managing Packages<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/30987118\/pip-with-virtualenv-requires-sudo\">pip with virtualenv requires sudo<\/a><\/li>\n<\/ul>\n<p>Of these, the first does not address the problem of running pip, which isn&#8217;t a python script. The second gives a command that doesn&#8217;t work (-E option does not work for me). The third addresses an issue that is almost right, but the solution appears not to be related.<\/p>\n<p>After some time, it occurred to me to call the right pip3 with sudo.<\/p>\n<pre>sudo -H env\/bin\/pip install django\r\n[install stuff]\r\nsudo -H env\/bin\/pip install list\r\n&gt;Django (1.9.1)\r\n&gt;pip (8.0.0)\r\n&gt;setuptools (19.4)\r\n&gt;wheel (0.26.0)<\/pre>\n<p>Success!<\/p>\n<h3>Better solution<\/h3>\n<p>Just change the permissions so that all users can edit the files. Then one does not need sudo at all.<\/p>\n<pre>sudo chmod -R o+rwx \/directory<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The problem: To install a virtualenv (virtual environment for python) under a common (not user) folder, so that it is accessible to other users. If we try without using sudo, we get a permission error: [go into virtualenv called env] pip3 install fibo &gt;[lots of stuff] &gt;PermissionError: [Errno 13] Permission denied: &#8216;\/django\/env\/lib\/python3.4\/site-packages\/Fibo.py&#8217; If we try [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2294,2292,2154,2293,2295],"class_list":["post-5770","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-permission","tag-pip","tag-python","tag-sudo","tag-virtualenv","entry"],"_links":{"self":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/comments?post=5770"}],"version-history":[{"count":4,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5770\/revisions"}],"predecessor-version":[{"id":5776,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/posts\/5770\/revisions\/5776"}],"wp:attachment":[{"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/media?parent=5770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/categories?post=5770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emilkirkegaard.dk\/en\/wp-json\/wp\/v2\/tags?post=5770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}