報錯信息
AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'
然後安裝低版本的cxOracle==5.2,6.*的時候又包clang的問題。
根據以往的經驗直覺,出現這樣的問題絕對不是包的問題,也不是主機環境的問題。
可以確定的是Python + Django + cxOracle 這三者之間出現版本匹配的問題。
版本試錯
使用pyenv裝了python 2.7.14, Python 3.7.1.
Python2的情況下:
- Django 2.1 + cxOracle 5、6、7 報錯
- Django 1.1 + cxOracle 5、6、7 報錯
Python3的情況下:
- Django 2.1 + cxOracle 5、6、7 報錯
- Django 1.1 + cxOracle 5、6、7 報錯
這就奇怪了!!!
由於版本的版本問題,本人更傾向於使用Python3,畢竟大勢所趨,所以最後還是使用Python3的解釋器。
吃了晚飯回來,繼續嘗試。
問題分析
- Django 2.1 + cxOracle 5、6、7 報錯
- Django 1.1 + cxOracle 5、6、7 報錯
都報錯,說明不是Python版本的問題, 可以繼續使用Python3。
由於查過官網,知道Django2.1是不支持 Oracle12g的(自己的是11g),所以不能再安裝Django 2.*了。
於是使用命令: pip install django==
看看Django 1.11的小版本號有哪些。
Collecting django==
Could not find a version that satisfies the requirement django== (from versions:
1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.4.21, 1.4.22, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.7.11, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.9a1, 1.9b1, 1.9rc1, 1.9rc2, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 1.9.7, 1.9.8, 1.9.9, 1.9.10, 1.9.11, 1.9.12, 1.9.13, 1.10a1, 1.10b1, 1.10rc1, 1.10, 1.10.1, 1.10.2, 1.10.3, 1.10.4, 1.10.5, 1.10.6, 1.10.7, 1.10.8, 1.11a1, 1.11b1, 1.11rc1, 1.11, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.11.5, 1.11.6, 1.11.7, 1.11.8, 1.11.9, 1.11.10, 1.11.11, 1.11.12, 1.11.13, 1.11.14, 1.11.15, 1.11.16, 1.11.17, 1.11.18, 1.11.20, 2.0a1, 2.0b1, 2.0rc1, 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10, 2.0.12, 2.0.13, 2.1a1, 2.1b1, 2.1rc1, 2.1, 2.1.1, 2.1.2, 2.1.3, 2.1.4, 2.1.5, 2.1.7, 2.2a1, 2.2b1)
根據經驗,不能太新,不能過舊,由於Django 1.11 是LTS版本,所以想了下,選擇了 Django 1.11.18。
執行命令: pip install django==1.11.18
,然後 python manager.py inspectdb
.
出現一下:
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey has `on_delete` set to the desired behavior.
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from __future__ import unicode_literals
from django.db import models
OK,成了。
總結
由於以前開發使用的是Python2,2019開始使用Python3,第一次開始嘗試到了工具版本切換帶來的挑戰。
不難想象,以後類似的問題還是會有的。
關鍵還是要耐心看報錯,細心看報錯,遇到問題不要第一時間copy報錯就查,先自己分析問題所在,然後再去網上查;如果什麼苗頭都不知道,就copy報錯一通查,運氣好可以碰到解決方案,運氣不好,查的越多,人反而越急躁。
因此,沉着耐心分析問題是第一。