【问题标题】:Openshift [Errno 13] Permission deniedOpenshift [Errno 13] 权限被拒绝
【发布时间】:2016-11-01 07:24:06
【问题描述】:

我遇到了与此链接所说的完全相同的问题:pip install Failed in OpenShift, the error info is Permission Denied。我在将 django-oscar 部署到 openshift 时遇到了错误。为了简化问题,我通过创建一个新墨盒进行了测​​试。然后通过 ssh 访问我的 openshift 服务器执行下一个命令:pip install django-oscar。它有一个好的开始,但有一个糟糕的结局,如下代码所示:

mrju@mrju:~/Documents/My_Project/My_Website/Oscar_Test$ rhc app create oscartest python-2.7
RSA 1024 bit CA certificates are loaded due to old openssl compatibility
Application Options
-------------------
Domain:     mrju
Cartridges: python-2.7
Gear Size:  default
Scaling:    no

Creating application 'oscartest' ... done


Waiting for your DNS name to be available ... done

Cloning into 'oscartest'...
The authenticity of host 'oscartest-mrju.rhcloud.com (52.3.216.108)' can't be established.
RSA key fingerprint is cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'oscartest-mrju.rhcloud.com,52.3.216.108' (RSA) to the list of known hosts.

Your application 'oscartest' is now available.



mrju@mrju:~/Documents/My_Project/My_Website/Oscar_Test$ ssh 5773c52c2d52710e5e00024a@oscartest-mrju.rhcloud.com



*********************************************************************

You are accessing a service that is for use only by authorized users.
If you do not have authorization, discontinue use at once.
Any use of the services is subject to the applicable terms of the
agreement which can be found at:
https://www.openshift.com/legal

*********************************************************************

Welcome to OpenShift shell

This shell will assist you in managing OpenShift applications.

!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
Shell access is quite powerful and it is possible for you to
accidentally damage your application.  Proceed with care!
If worse comes to worst, destroy your application with "rhc app delete"
and recreate it
!!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!

Type "help" for more info.


[oscartest-mrju.rhcloud.com 5773c52c2d52710e5e00024a]\> 

[oscartest-mrju.rhcloud.com 5773c52c2d52710e5e00024a]\> cd /var/lib/openshift/5773c52c2d52710e5e00024a/python//virtenv/
[oscartest-mrju.rhcloud.com virtenv]\> ls
bin  include  lib  lib64  pip-selfcheck.json
[oscartest-mrju.rhcloud.com virtenv]\> source bin/activate
(virtenv)[oscartest-mrju.rhcloud.com virtenv]\> pip install django-oscar
***The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.***
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting django-oscar
  Downloading django_oscar-1.2.1-py2.py3-none-any.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 39kB/s 
Collecting phonenumbers<8.0.0,>=6.3.0 (from django-oscar)
  Downloading phonenumbers-7.4.3.tar.gz (2.3MB)
    100% |████████████████████████████████| 2.3MB 81kB/s 
Collecting factory-boy<2.7,>=2.4.1 (from django-oscar)
  Downloading factory_boy-2.6.1-py2.py3-none-any.whl
Collecting purl>=0.7 (from django-oscar)
  Downloading purl-1.3-py2.py3-none-any.whl
Collecting mock<2.0,>=1.0.1 (from django-oscar)
  Downloading mock-1.3.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 57kB 3.7MB/s 
Collecting django<1.9,>=1.7.8 (from django-oscar)
  Downloading Django-1.8.13-py2.py3-none-any.whl (6.2MB)
    100% |████████████████████████████████| 6.2MB 61kB/s 
Collecting django-haystack<2.5.0,>=2.3.1 (from django-oscar)
  Downloading django_haystack-2.4.1-py2-none-any.whl (95kB)
    100% |████████████████████████████████| 98kB 3.9MB/s 
Collecting django-treebeard>=3.0 (from django-oscar)
  Downloading django-treebeard-4.0.1.tar.gz (93kB)
    100% |████████████████████████████████| 94kB 2.6MB/s 
Collecting django-extra-views<0.6.5,>=0.2 (from django-oscar)
  Downloading django_extra_views-0.6.4-py27-none-any.whl
Collecting pillow>=1.7.8 (from django-oscar)
  Downloading Pillow-3.2.0.zip (10.5MB)
    100% |████████████████████████████████| 10.5MB 22kB/s 
Collecting Unidecode<0.05,>=0.04.12 (from django-oscar)
  Downloading Unidecode-0.04.19.tar.gz (204kB)
    100% |████████████████████████████████| 204kB 1.4MB/s 
Collecting sorl-thumbnail==12.3 (from django-oscar)
  Downloading sorl_thumbnail-12.3-py2.py3-none-any.whl (40kB)
    100% |████████████████████████████████| 40kB 4.2MB/s 
Collecting django-tables2<1.1,>=1.0.4 (from django-oscar)
  Downloading django-tables2-1.0.7.tar.gz (966kB)
    100% |████████████████████████████████| 970kB 343kB/s 
Collecting Babel<3.0,>=1.0 (from django-oscar)
  Downloading Babel-2.3.4-py2.py3-none-any.whl (7.1MB)
    100% |████████████████████████████████| 7.1MB 46kB/s 
Collecting django-widget-tweaks>=1.4.1 (from django-oscar)
  Downloading django_widget_tweaks-1.4.1-py2.py3-none-any.whl
Collecting fake-factory>=0.5.0 (from factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading fake_factory-0.5.8-py2.py3-none-any.whl (505kB)
    100% |████████████████████████████████| 507kB 618kB/s 
Requirement already satisfied (use --upgrade to upgrade): six in /opt/rh/python27/root/usr/lib/python2.7/site-packages (from purl>=0.7->django-oscar)
Collecting funcsigs (from mock<2.0,>=1.0.1->django-oscar)
  Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock<2.0,>=1.0.1->django-oscar)
  Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB)
    100% |████████████████████████████████| 98kB 3.5MB/s 
Collecting pytz>=0a (from Babel<3.0,>=1.0->django-oscar)
  Downloading pytz-2016.4-py2.py3-none-any.whl (480kB)
    100% |████████████████████████████████| 483kB 404kB/s 
Collecting python-dateutil>=2.4 (from fake-factory>=0.5.0->factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB)
    100% |████████████████████████████████| 204kB 1.1MB/s 
Collecting ipaddress (from fake-factory>=0.5.0->factory-boy<2.7,>=2.4.1->django-oscar)
  Downloading ipaddress-1.0.16-py27-none-any.whl
Building wheels for collected packages: phonenumbers, django-treebeard, pillow, Unidecode, django-tables2
Exception:
Traceback (most recent call last):
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/commands/install.py", line 293, in run
    wb.build(autobuilding=True)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/wheel.py", line 756, in build
    ensure_dir(output_dir)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/app-root/runtime/dependencies/python/virtenv/lib/python2.7/site-packages/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 150, in makedirs
    makedirs(head, mode)
  File "/var/lib/openshift/5773c52c2d52710e5e00024a/python/virtenv/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache'

(virtenv)[oscartest-mrju.rhcloud.com virtenv]\> 

提示很有用

The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
You are using pip version 7.1.0, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The directory '/var/lib/openshift/5773c52c2d52710e5e00024a/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

但是我不知道如何获得 sudo 的权限或如何使用 sudo 的 -H 标志。

【问题讨论】:

    标签: python linux django pip openshift


    【解决方案1】:

    sudo 用于以 root 状态执行命令。您可以简单地在sudo ls 之前使用 sudo 编写命令。

    对于你的问题,我认为 pip 没有 .cache 的执行权限(如果你有文件的执行权限,那么你可以执行这个,对于一个目录,你可以交叉它。解决这个,添加权限 sudo chmod 和你想要的值。

    chmod 采用权利值给出的数字,如 777 等。chmod rwx rwx rwx

    chmod user group other with each : read write execute with boolean value (0 or 1) so for example: chmod 750 表示用户拥有所有权限 (111),组只有读取和执行权限 (101) 和其他任何权限。

    你也可以用sudo chmod +x name添加权限x

    如果您不知道标志,请先尝试man 命令。

    man sudo

    -H (HOME) 选项选项设置 HOME 环境 变量到目标用户的主目录(root by 默认)由密码数据库指定。这 HOME 环境变量的默认处理取决于 在 sudoers(5) 设置上。默认情况下,sudo 将设置 HOME 如果 设置了 env_reset 或 always_set_home,或者如果设置了 set_home 并且 -s 选项在命令行中指定。

    所以,尝试一个简单的sudo pip install django-oscarsu 命令在当前会话期间成为root。

    【讨论】:

    • 您好,非常感谢。经过多次尝试,我发现使用sudo或相关方法无法用于Openshift Online,因为无法获得Openshift Online的许可。幸运的是,我通过使用源文件(python setup install)而不是使用 pip install 成功安装了 django-oscar。
    【解决方案2】:

    如果您在虚拟环境中使用pip,请不要使用sudo(从您发布的代码来看,您就是这样),因为这会全局安装包,不会 在虚拟环境中。

    相反,您可以将pip--user 标志一起使用,如下所示:

    pip install --user &lt;package_name&gt;

    如果失败,请尝试按照回溯建议升级pip,然后尝试重新安装

    【讨论】:

    • 非常感谢。我终于成功地使用了“python setup.py install”而不是“pip install django-oscar”。
    【解决方案3】:

    试试pip install django-oscar --no-cache-dir

    【讨论】:

    • 在 Openshift Online 2 和 Python2.7 上仍然有效。谢谢!
    【解决方案4】:

    如果将来有人遇到这个问题,这对我有帮助 - enter link description here

    这是链接中的详细信息-
    这是我设法使用 OpenShift 操作挂钩找到的修复程序。 下面的代码清单中列出了有帮助的关键 Web 链接。

    详细说明:

    • 在您的本地仓库中,更改为文件夹.openshift\action_hooks
    • 将名为 build 的文件添加到名为 .openshift\action_hooks 的本地 repo 文件夹中
    • 在文件构建中添加以下行:
    # !/bin/bash
    # Written by Priyend Somaroo, 06 Jun 2016, Vardaan Enterpises, www.vardaan.com
    #
    # This will execute pip install but using no caching in order to fix broken 
    # cache problems with python-2.7 cartridge as at 06 Jun 2016
    #
    #   Ref: http://*.com/questions/29913677/openshift-app-with-flask-sqlalchemy-and-sqlite-problems-with-database-reverti
    #   Ref: http://*.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows
    #
    # 
    # *** Very important *** : this file must be marked executable using 'chmod +x'.
    # In Windows this is a problem so we simply mark it in the git repo as executable as follows.
    # - In Windows open command prompt and change to the folder with this build file
    # - Then run 'git update-index --chmod=+x build'
    # - Ten check the permissions aer 0755 using 'git ls-files --stage' .
    #
    # Normal commits and push's occur after that.
    
    # This build hook gets executed at the end of the build cycle before delpoy
    
    # Change to repo directory and run pip install with no caching
    cd ${OPENSHIFT_REPO_DIR}
    pip install -r requirements.txt --no-cache-dir
    
    • 标记构建文件可执行文件以使其正确运行:
    • 在 Linux 中运行:chmod +x build
    • 对于 Windows,您需要运行它:git update-index --chmod=+x build
    • 终于完成你的 git commit 和 git push

    您可以通过 ssh'ing 到您的应用程序文件夹并运行来确认安装了正确的软件包: pip list

    【讨论】: