Openshift [Errno 13]许可被拒绝

时间:2016-06-29 14:06:29

标签: python linux django pip openshift

我遇到了与此链接所说的完全相同的问题: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标志。

4 个答案:

答案 0 :(得分:2)

如果您在虚拟环境中使用sudo,请不要使用pip(根据您发布的代码判断),因为这将全局安装软件包<在虚拟环境中强大>不。

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

pip install --user <package_name>

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

答案 1 :(得分:2)

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

答案 2 :(得分:1)

sudo用于执行具有root状态的命令。您可以在sudo ls之前使用sudo编写命令。

对于你的问题,我认为pip没有.cache的执行权限(如果你有文件的执行权限,那么,你可以执行这个,并且对于一个目录,你可以跨越它。要解决此问题,请使用sudo chmod和您希望的值添加权限。

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

  

chmod用户组,每个用户:读取写入执行时使用布尔值(0或1),例如:chmod 750表示用户拥有所有权限(111),组仅具有读取和执行权限(101)等任何权限权限。

您还可以使用sudo chmod +x name

添加权限x

如果您不知道旗帜,请先尝试man命令。

man sudo

  

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

因此,尝试使用简单的sudo pip install django-oscarsu命令在当前会话期间成为root。

答案 3 :(得分:1)

如果将来有人面临这个问题,这有助于我 - enter link description here

以下是链接的详细信息 -
这是我使用OpenShift动作钩子找到的修复程序。 帮助的关键Web链接列在下面的代码清单中。

详细说明:

  • 在您的本地仓库中,切换到文件夹$query->andFilterWhere($condition);
  • 将名为.openshift\action_hooks的文件添加到名为build
  • 的本地repo文件夹中
  • 在文件构建中添加以下行:
.openshift\action_hooks
  • 将构建文件标记为可执行文件,以使其正常运行:
  • 在Linux中运行:# !/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://stackoverflow.com/questions/29913677/openshift-app-with-flask-sqlalchemy-and-sqlite-problems-with-database-reverti # Ref: http://stackoverflow.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
  • 对于Windows,您需要运行此代码:chmod +x build
  • 最后完成你的git commit和git push

您可以通过ssh进入app文件夹并运行以确认已安装的正确软件包: git update-index --chmod=+x build