Python 入門級報錯處理

張衝andy發表於2019-02-12

問題1:Missing parentheses in call to 'print'

原因:因為Python2.X和Python3.X不相容。
我安裝的是Python3.X,但是我試圖執行的卻是Python2.X 的程式碼。
所以上面的語法在python3中是錯誤的。在python3中,你需要將print後面的語句加括號,正確的寫法:
print ("hello world")


問題2:建立專案報錯,django-admin startproject sundyblog 
File "c:\users\andy\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\html.py", line 16, in <module>
from .html_parser import HTMLParser, HTMLParseError
File "c:\users\andy\appdata\local\programs\python\python35-32\lib\site-packages\django\utils\html_parser.py", line 12, in <module>
HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'


原因:HTMLParseError在pythons3.5已經沒有了

解決方法:

方法1:將python版本回退到3.3或3.4

方法2:升級django版本
>pip3 install django==1.8 ##升級django版本
C:\Users\andy>django-admin startproject sundyblog ##再次執行,無報錯

 

問題3: 使用  ImageField  欄位建表報錯

C:\Users\andy\sundyblog>python manage.py makemigrations
SystemCheckError: System check identified some issues:

ERRORS:
blog.Article.portal: (fields.E210) Cannot use ImageField because Pillow is not installed.
HINT: Get Pillow at or run command "pip install Pillow".

解決:C:\Users\andy\sundyblog>pip install -i Pillow
Looking in indexes:
Collecting Pillow
Downloading
100% |████████████████████████████████| 1.7MB 351kB/s
Installing collected packages: Pillow
Successfully installed Pillow-5.4.1
You are using pip version 19.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

C:\Users\andy\sundyblog>python manage.py makemigrations
Migrations for 'blog':
0001_initial.py:
- Create model Article
- Create model Author
- Add field autor to article

C:\Users\andy\sundyblog>


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2625293/,如需轉載,請註明出處,否則將追究法律責任。

相關文章