Ubuntu下pycharm无法导入类的解决方法
<p>最近在学习python的flask框架,配置好环境后,在终端跑了一下“hello.py”效果不错,一点毛病没有;但当我用pycharm打开后却发现代码有错,无法导入 flask 类,详细错误信息如下:</p>
<div class="jb51code">
<div>
<div class="syntaxhighlighterxhtml" id="highlighter_664721">
<div class="toolbar">
<span>?</span>
</div>
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr>
<td class="gutter">
<div class="line number1 index0 alt2">
1</div>
</td>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2">
<code class="xhtml plain">this inspection detects names that should resolve but don't. due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. top-level and class-level items are supported better than instance items.</code>
</div>
</div>
</td>
</tr></tbody></table>
</div>
</div>
</div>
<p>
<img style="max-width:100%!important;height:auto!important;"title="Ubuntu下pycharm无法导入类的解决方法" alt="Ubuntu下pycharm无法导入类的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/0b623f5e809f0207f0238106993f8019.jpg"></p>
<p>
<strong>错误详情</strong></p>
<p>
这是终端的运行结果</p>
<p>
<strong>终端结果</strong></p>
<p>
<img style="max-width:100%!important;height:auto!important;"title="Ubuntu下pycharm无法导入类的解决方法" alt="Ubuntu下pycharm无法导入类的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/aedd12f34f157ca04aeb00cb807c8bb3.jpg"></p>
<p>
<span><strong>从网上百度了好长时间才找到解决办法,这里总结了一下希望能帮到大家</strong></span></p>
<p>
<strong>首先,打开终端(点击图片中“terminal”图标)</strong></p>
<p>
<img style="max-width:100%!important;height:auto!important;"title="Ubuntu下pycharm无法导入类的解决方法" alt="Ubuntu下pycharm无法导入类的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/75e91a76e50e9362e65886ab87af8ad2.jpg"></p>
<p>
<strong>打开终端</strong></p>
<p>
然后在终端输入</p>
<p>
<strong>pip install flask</strong></p>
<p>
<img style="max-width:100%!important;height:auto!important;"title="Ubuntu下pycharm无法导入类的解决方法" alt="Ubuntu下pycharm无法导入类的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/48145276ea06014f1b46ea21ff8187e1.jpg"></p>
<p>
<strong>安装flask</strong></p>
<p>
<strong>大功告成</strong></p>
<p>
<img style="max-width:100%!important;height:auto!important;"title="Ubuntu下pycharm无法导入类的解决方法" alt="Ubuntu下pycharm无法导入类的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/c70091c67ea0af974daf6dd925e4bd30.jpg"></p>
<p>
<strong>运行结果</strong></p>
<p>
<span><strong>注:</strong></span></p>
<p>
这个解决办法,其实就是在pycharm的终端,又重新安装了一次 flask ;但我也不是很懂为什么要这样做,在 windows 环境下通过 pip 安装的包,在 pycharm 中是可以直接导入的,可能是因为这个是在 linux 环境下的原因,也可能因为我之前配置环境时,配置的是虚拟环境。如果有哪位大佬看到了这篇博客,希望能不吝赐教,在评论区留下答案。</p>
<p>
以上这篇ubuntu下pycharm无法导入类的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。</p>
<p>
原文链接:http://blog.csdn.net/slwhy/article/details/78880165?utm_source=5ibc.net&utm_medium=referral</p>
頁:
[1]