module ‘markdown‘ has no attribute ‘version‘

最近在写一个CMDB的项目,遇到drf与django版本问题...

错误如下:

AttributeError at /
module ‘markdown‘ has no attribute ‘version‘
Request Method: GET
Request URL:    http://127.0.0.1:8000/
Django Version: 2.1.1
Exception Type: AttributeError
Exception Value:
module ‘markdown‘ has no attribute ‘version‘
Exception Location: D:\Code\Python\AutoCMDBViewer\venv\lib\site-packages\rest_framework\compat.py in <module>, line 161
Python Executable:  D:\Code\Python\AutoCMDBViewer\venv\Scripts\python.exe
Python Version: 3.6.5
Python Path:
[‘D:\\Code\\Python\\AutoCMDBViewer‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer\\venv\\Scripts\\python36.zip‘,
 ‘C:\\ProgramData\\Anaconda3\\DLLs‘,
 ‘C:\\ProgramData\\Anaconda3\\lib‘,
 ‘C:\\ProgramData\\Anaconda3‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer\\venv‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages\\setuptools-39.1.0-py3.6.egg‘,
 ‘D:\\Code\\Python\\AutoCMDBViewer\\venv\\lib\\site-packages\\pip-10.0.1-py3.6.egg‘,
 ‘C:\\Apps\\PyCharm\\helpers\\pycharm_matplotlib_backend‘]

版本信息如下:

(venv) D:\Code\Python\AutoCMDBViewer>pip freeze
asn1crypto==0.24.0
cffi==1.11.5
cryptography==2.3.1
Django==2.1.1
django-filter==2.0.0
djangorestframework==3.8.2
idna==2.7
Markdown==3.0
pycparser==2.18
PyMySQL==0.9.2
pytz==2018.5
six==1.11.0

解决方案如下:

打开drf源码目录下的 compat.py 文件,我的路径是: D:\Code\Python\AutoCMDBViewer\venv\Lib\site-packages\rest_framework\compat.py 定位到157行代码进行修改:

try:
    import markdown

    if markdown.__version__ <= ‘2.2‘: # 将version修改为__version__即可
        HEADERID_EXT_PATH = ‘headerid‘
        LEVEL_PARAM = ‘level‘
    elif markdown.__version__ < ‘2.6‘: # 将version修改为__version__即可
        HEADERID_EXT_PATH = ‘markdown.extensions.headerid‘
        LEVEL_PARAM = ‘level‘
    else:
        HEADERID_EXT_PATH = ‘markdown.extensions.toc‘
        LEVEL_PARAM = ‘baselevel‘

    def apply_markdown(text):
        """
        Simple wrapper around :func:`markdown.markdown` to set the base level
        of ‘#‘ style headers to <h2>.
        """
        extensions = [HEADERID_EXT_PATH]
        extension_configs = {
            HEADERID_EXT_PATH: {
                LEVEL_PARAM: ‘2‘
            }
        }
        md = markdown.Markdown(
            extensions=extensions, extension_configs=extension_configs
        )
        md_filter_add_syntax_highlight(md)
        return md.convert(text)
except ImportError:
    apply_markdown = None
    markdown = None

原文地址:http://blog.51cto.com/xvjunjie/2179047

时间: 2024-08-02 06:15:14

module ‘markdown‘ has no attribute ‘version‘的相关文章

os.uname() AttributeError: &#39;module&#39; object has no attribute &#39;uname&#39;

os.uname() Returns information identifying the current operating system. The return value is an object with five attributes: sysname - operating system name nodename - name of machine on network (implementation-defined) release - operating system rel

&#39;module&#39; object has no attribute &#39;contrib&#39;

Problem solved, turns i had 2 tensorflow versions installed: When launching $python , it used 0.6 version(which didnt had contrib module) When launching $sudo python ,it had the latest 0.9 version and everything works as the documentation. 'module' o

AttributeError: &#39;module&#39; object has no attribute &#39;dumps&#39;

报错: [[email protected] ~]# ./json.py DATA: [{'a': 'A', 'c': 3.0, 'b': (2, 4)}] Traceback (most recent call last): File "./json.py", line 4, in <module> import json File "/root/json.py", line 8, in <module> data_string = jso

Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attribute 'xxx'".这其实是.pyc文件存在问题. 问题定位: 查看import库的源文件,发现源文件存在且没有错误,同时存在源文件的.pyc文件 问题解决方法: 1. 命名py脚本时,不要与python预留字,模块名等相同 2. 删除该库的.pyc文件(因为py脚本每次运行时均会生成.pyc文件

python文件名与module名冲突,出错&#39;module&#39; object has no attribute &#39;strftime&#39;

import time print time.strftime('%Y%m%d%H%M%S') 以上小程序命名为time.py 运行时出现错误提示: print time.strftime('%Y%m%d%H%M%S') AttributeError: 'module' object has no attribute 'strftime' 确认了strftime确实是time的函数后,还以为这是一个bug呢 然后直接用console运行以上代码,发现能得出正确的结果,说明代码没问题,那就可能是名

Socket.Server &#39;module&#39; object has no attribute &#39;fork&#39; 原因分析

Exception happened during processing of request from ('127.0.0.1', 65066)Traceback (most recent call last): File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_nobloc self.process_request(request, client_address) File "C:\P

[Python]attributeError:&#39;module&#39; object has no attribute &#39;dump&#39;

[问题] [代码] 文件名:pickle.py # coding=utf-8 #持久存储 import pickle #b 以二进制的模式打开文件 with open('mydata.pickle','wb') as mysavedata: #用dump保存数据 pickle.dump([1,2,'three'],mysavedata) #b 以二进制的模式打开文件 with open('mydata.pickle','rb') as myreaddata: #使用load恢复数据 list =

关于报错:AttributeError: module &#39;turtle&#39; has no attribute &#39;setup&#39; 问题

对于我们菜鸟,往往安装软件后,都容易使用默认设置,结果将写的文件保存到了安装目录下. 这样造成了很大得隐患,如果写得文件,名称与安装目录下得系统文件名称重复,就容易出现以上报错. 解决方法:1.将文件名称修改为与安装目录下得系统文件名称不冲突. 2.最好直接将自己得文件保存路径修改为其他地方,不要与安装目录重复. 关于报错:AttributeError: module 'turtle' has no attribute 'setup' 问题

Faq_flask : AttributeError: ‘module’ object has no attribute ‘autoescape’

原文地址: http://www.suzf.net/thread-0613-153.html 转载须注明原始出处 前些天从 "spider_net" 上找了一篇文章 , 大致就是利用 highcharts + flask + mysql 构建的一个简单的监控系统 ,经过几番挣扎终于还是给捣持出来了 , 现在总结一下 , 分享给大家 .   o_O 部分报错信息: * Detected change in 'flask_web.py', reloading* Restarting wit