前言

在django CMS 安装一文我介绍了如何一步一步手动安装django CMS,这篇文章将介绍如何一键自动安装django CMS。

djangocms-installer安装

具体安装步骤在https://github.com/nephila/djangocms-installer 里有介绍,非常简单,执行一条命令

首先创建工作环境

cd C:\virtualenv\djangocmsinstaller
virtualenv env
env\Scripts\activate

安装djangocms-installer

pip install djangocms-installer

pip freeze

dj-database-url==0.5.0
djangocms-installer==1.0.0
pytz==2018.3
six==1.11.0
tzlocal==1.5.1

创建新项目

djangocms csblog

csblog是本文的演示项目名

安装时报错:

Traceback (most recent call last):
File "c:\python27\Lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\virtualenv\djangocmsinstaller\env\Scripts\djangocms.exe__main__.py", line 9, in <module>
File "c:\virtualenv\djangocmsinstaller\env\lib\site-packages\djangocms_installer\main.py", line 33, in execute
verbose=config_data.verbose
File "c:\virtualenv\djangocmsinstaller\env\lib\site-packages\djangocms_installer\install__init__.py", line 95, in requirements
output = subprocess.check_output(['pip'] + args, stderr=subprocess.STDOUT)
File "c:\python27\Lib\subprocess.py", line 544, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '[u'pip', u'install', u'-q', u'django-cms>=3.5,<3.6', u'djangocms-admin-style>=1.2,<1.3', u'django-treebeard>=4.0,<5.0', u'https://github.com/divio/djangocms-text-ckeditor/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-file/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-link/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-style/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-googlemap/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-snippet/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-picture/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-video/archive/master.zip?1520402678.71', u'https://github.com/divio/djangocms-column/archive/master.zip?1520402678.71', u'easy_thumbnails', u'django-filer>=1.3', u'Django<2.0', u'pytz', u'django-classy-tags>=0.7', u'html5lib>=0.999999,<0.99999999', u'Pillow>=3.0', u'django-sekizai>=0.9', u'six']' returned non-zero exit status 2

从报错的信息看,在安装依赖库时出了问题。当时安装时没能判断哪一步出了问题,所以决定通过源码安装在本地进行调试

Fallback版本

在源码调试之前,我尝试了老的版本djangocms-installer==0.9.8,安装是正常的。

源码调试

下载 git@github.com:nephila/djangocms-installer.git 到本地,目录 e:\Computer\virtualenv\djangocms-installer-develop

创建virtualenv工作环境并激活

virtualenv env
env\Scripts\activate

通过源码安装djangocms-installer

python setup.py install

这样djangocms-installer本地安装完成

继续尝试执行djangocms csblog,跟pip安装报错相同,所以本地安装和pip安装没有差别!

报错是pip安装出错,所以查看源码里跟requirements相关的文件

  • e:\computer\virtualenv\djangocms-installer-develop\build\lib\djangocms_installer\config\data.py
  • e:\computer\virtualenv\djangocms-installer-develop\djangocms_installer\config\data.py
  • e:\computer\virtualenv\djangocms-installer-develop\env\lib\site-packages\djangocms_installer-1.0.0rc1-py2.7.egg\data.py
    'plugins-3.4': [
        'djangocms-text-ckeditor >= 3.2.1',
        'djangocms-link >= 1.8',
        'djangocms-style >= 1.7',
        'djangocms-googlemap >= 0.5',
        'djangocms-snippet >= 1.9',
        'djangocms-video >= 2.0',
        'djangocms-column >= 1.6',
        'djangocms-file >= 2.0,< 3.0',
        'djangocms-picture >= 2.0,< 3.0',
    ],
    'plugins-3.5': [
        'https://github.com/divio/djangocms-text-ckeditor/archive/master.zip?{bust}'
        ''.format(**bust),
        'https://github.com/divio/djangocms-file/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-link/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-style/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-googlemap/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-snippet/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-picture/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-video/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-column/archive/master.zip?{bust}'.format(**bust),
    ],
    'plugins-master': [
        'https://github.com/divio/djangocms-text-ckeditor/archive/master.zip?{bust}'
        ''.format(**bust),
        'https://github.com/divio/djangocms-file/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-link/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-style/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-googlemap/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-snippet/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-picture/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-video/archive/master.zip?{bust}'.format(**bust),
        'https://github.com/divio/djangocms-column/archive/master.zip?{bust}'.format(**bust),
    ],

怀疑通过网址的方式会有问题,所以修改以上内容,用plugins-3.4覆盖plugins-master,继续执行djangocms csblog,成功!基本确认跟这个网址安装有关。

继续确认,尝试执行

pip install https://github.com/divio/djangocms-file/archive/master.zip 报错 error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error

对SSL这块不是太了解,所以网上取搜了一些解决方案 https://stackoverflow.com/questions/33972671/downloading-https-pages-with-urllib-error14077438ssl-routinesssl23-get-serve

Then it depends on the site. Typical problems with this version of Python is missing support for Server Name Indication (SNI) which was only added to Python 2.7.9. Since lots of sites require SNI today (like everything using Cloudflare Free SSL) I guess this is the problem.
@yak: since TLS 1.2 is also supported with Python 2.7.6. in (K)ubuntu 14.04 my guess is that the upgrade to Python 2.7.10 simply fixed the SNI issue and that's why it worked. Nevertheless, it counts that it works.

从以上stackover问题描述可以看到他们的解决方案是升级python到2.7.10,当前我的python版本是2.7.3,而且我一直碰到SNIMissingWarning的问题,所以我猜测这两个问题相关,于是将我的python升级到了2.7.10 (注: Python2.7.10是一个bug fix release )

附带信息:下面是我执行pip install操作时一直碰到的两个告警

C:\virtualenv\djangocmsinstaller\env\lib\site-packages\pip_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
SNIMissingWarning

C:\virtualenv\djangocmsinstaller\env\lib\site-packages\pip_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning

Python升级完成后,继续尝试执行

pip install https://github.com/divio/djangocms-file/archive/master.zip

成功,问题解决。

djangocms安装

执行djangocms csblog,即可完成安装。

对应的requirements.txt

django-cms>=3.5,<3.6
djangocms-admin-style>=1.2,<1.3
django-treebeard>=4.0,<5.0

https://github.com/divio/djangocms-text-ckeditor/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-file/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-link/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-style/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-googlemap/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-snippet/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-picture/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-video/archive/master.zip?1520586375.33
https://github.com/divio/djangocms-column/archive/master.zip?1520586375.33
easy_thumbnails
django-filer>=1.3
Django<2.0
pytz
django-classy-tags>=0.7
html5lib>=0.999999,<0.99999999
Pillow>=3.0
django-sekizai>=0.9
six

执行pip freeze

Django==1.11.11
django-classy-tags==0.8.0
django-cms==3.5.1
django-filer==1.3.0
django-formtools==2.1
django-mptt==0.8.7
django-polymorphic==1.3
django-sekizai==0.10.0
django-treebeard==4.2.1
djangocms-admin-style==1.2.7
djangocms-attributes-field==0.3.0
djangocms-column==1.7.0
djangocms-file==2.0.2
djangocms-googlemap==1.1.1
djangocms-link==2.1.2
djangocms-picture==2.0.6
djangocms-snippet==2.0.0
djangocms-style==2.0.2
djangocms-text-ckeditor==3.5.3
djangocms-video==2.0.4
easy-thumbnails==2.5
html5lib==0.9999999
Pillow==5.0.0
pytz==2018.3
six==1.11.0
Unidecode==0.4.21

参考文档

  • http://docs.django-cms.org/en/release-3.4.x/how_to/install.html