报错如题所示,具体如下:

C:\Python27\Scripts>pip install django
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://pypi.douban.com/simple, http://mirrors.aliyun.com/pypi/simple/
Collecting django
  WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
  Downloading http://mirrors.aliyun.com/pypi/packages/56/2e/c0495314c0bdcf19d9b888a98ff16a4c58a90dd77ed741f4dbab2cbf7efe/Django-2.2.2.tar.gz (8.8MB)
     |████████████████████████████████| 8.8MB 62kB/s
ERROR: Could not install packages due to an EnvironmentError: [Errno 22] invalid mode ('wb') or filename: 'c:\\users\\adamhuan\\appdata\\local\\temp\\pip-install-ihdzki\\django\\tests/staticfiles_tests/apps/test/static/test/\xe2\x8a\x97.txt'


C:\Python27\Scripts>

在我的环境里,该错误发生在MS Windows 10,通过PIP安装Django的模块的时候。
但事实上,该错误与操作系统并没有关系。

错误原因:
发生该错误的原因是:
Python的版本与Django的版本不匹配

我们先看看Python的版本生命周期以及每个版本的最大小版本号的信息:

以上信息,来自于Django官网:【https://www.djangoproject.com/download/】

Python与Django的版本的对应关系如下:

可以看到,从【2.0】开始,Django不再支持Python【2】的版本。
因此,如果使用Python2安装Django2以上的版本,就会出现问题。

而Django支持Python2的最后一个版本是【1.11】,该版本的最大的小版本号是【21】。

因此,对于文首的错误,我们用Python2,安装Django1.11.21就没问题了:

C:\Python27\Scripts>pip install django==1.11.21
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://pypi.douban.com/simple, http://mirrors.aliyun.com/pypi/simple/
Collecting django==1.11.21
  WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
  Downloading http://mirrors.aliyun.com/pypi/packages/a2/84/9f66e359ba8e63cf9b54f6815ed55188dda43cd1cc951a8bb95542dee956/Django-1.11.21-py2.py3-none-any.whl (6.9MB)
     |████████████████████████████████| 7.0MB 5.7MB/s
Collecting pytz (from django==1.11.21)
  WARNING: The repository located at pypi.douban.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS we recommend you use HTTPS instead, otherwise you may silence this warning and allow it anyway with '--trusted-host pypi.douban.com'.
  Downloading http://mirrors.aliyun.com/pypi/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
     |████████████████████████████████| 512kB 6.0kB/s
Installing collected packages: pytz, django
  WARNING: The script django-admin.exe is installed in 'c:\python27\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed django-1.11.21 pytz-2019.1

C:\Python27\Scripts>

C:\Python27\Scripts>pip -V
pip 19.1.1 from c:\python27\lib\site-packages\pip (python 2.7)

C:\Python27\Scripts>pip list
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Package    Version
---------- -------
Django     1.11.21
pip        19.1.1
PyMySQL    0.9.3
pytz       2019.1
setuptools 40.6.2

C:\Python27\Scripts>

————————————————————
Done。

说点什么

avatar

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

  Subscribe  
提醒