OpenShift - 更新 Python 并在 Rails 应用程序中安装 PIP

OpenShift - Update Python and Install PIP in a Rails app

我已经在 OpenShift 上创建了我的 Rails 应用程序。它使用 Python 和一个从 PIP 安装的包。我如何升级到更新的 Python 版本(目前是 2.6)?

可见墨盒:

user@debian:~$ rhc cartridges
jbossas-7                JBoss Application Server 7              web
jboss-dv-6.1.0 (!)       JBoss Data Virtualization 6             web
jbosseap-6 (*)           JBoss Enterprise Application Platform 6 web
jboss-unified-push-1 (!) JBoss Unified Push Server 1.0.0.Beta1   web
jboss-unified-push-2 (!) JBoss Unified Push Server 1.0.0.Beta2   web
jenkins-1                Jenkins Server                          web
nodejs-0.10              Node.js 0.10                            web
perl-5.10                Perl 5.10                               web
php-5.3                  PHP 5.3                                 web
php-5.4                  PHP 5.4                                 web
zend-6.1                 PHP 5.4 with Zend Server 6.1            web
python-2.6               Python 2.6                              web
python-2.7               Python 2.7                              web
python-3.3               Python 3.3                              web
ruby-1.8                 Ruby 1.8                                web
ruby-1.9                 Ruby 1.9                                web
ruby-2.0                 Ruby 2.0                                web
jbossews-1.0             Tomcat 6 (JBoss EWS 1.0)                web
jbossews-2.0             Tomcat 7 (JBoss EWS 2.0)                web
jboss-vertx-2.1 (!)      Vert.x 2.1                              web
jboss-wildfly-8 (!)      WildFly Application Server 8.2.1.Final  web
jboss-wildfly-9 (!)      WildFly Application Server 9            web
diy-0.1                  Do-It-Yourself 0.1                      web
cron-1.4                 Cron 1.4                                addon
jenkins-client-1         Jenkins Client                          addon
mongodb-2.4              MongoDB 2.4                             addon
mysql-5.1                MySQL 5.1                               addon
mysql-5.5                MySQL 5.5                               addon
phpmyadmin-4             phpMyAdmin 4.0                          addon
postgresql-8.4           PostgreSQL 8.4                          addon
postgresql-9.2           PostgreSQL 9.2                          addon
rockmongo-1.1            RockMongo 1.1                           addon
switchyard-0             SwitchYard 0.8.0                        addon
haproxy-1.4              Web Load Balancer                       addon

Note: Web cartridges can only be added to new applications.

(*) denotes a cartridge with additional usage costs.

(!) denotes a cartridge that will not receive automatic security updates.

然后尝试安装更新的 Python ...

user@debian:~$ rhc add-cartridge --app myappname python-3.3
Short Name       Full name
==========       =========
cron-1.4         Cron 1.4
jenkins-client-1 Jenkins Client
mongodb-2.4      MongoDB 2.4
mysql-5.1        MySQL 5.1
mysql-5.5        MySQL 5.5
phpmyadmin-4     phpMyAdmin 4.0
postgresql-8.4   PostgreSQL 8.4
postgresql-9.2   PostgreSQL 9.2
rockmongo-1.1    RockMongo 1.1
switchyard-0     SwitchYard 0.8.0
haproxy-1.4      Web Load Balancer

There are no cartridges that match 'python-3.3'.

如果可以安装较新版本的 Python,我该如何安装 PIP?

没有名为 python 的墨盒,因为当您尝试将墨盒添加到现有应用程序时,它只会向您显示 兼容的 墨盒。正如 rhc cartridges 命令所指出的:

Note: Web cartridges can only be added to *new* applications.

更新 python 版本的最佳方法是创建一个新应用并从旧应用导入代码。

1) 创建新应用

$ rhc app create py33 python-3.3

2) 获取 git url 并将其作为远程添加到您的应用程序

$ cd old_python_app
$ git remote add py33 ssh://py33-giturl
$ git push py33 master -f 
# Force push as the repo comes with default config files

至于 pip,它预装了 openshift。

$ rhc ssh py33
$ pip --version
  pip 7.1.2 from /var/lib/openshift/.../python/virtenv/venv/lib/python3.3/site-packages (python 3.3)

我已经将lib复制到OpenShift,将其包含在包含路径中并使用py2.6执行!问题已解决!