简体   繁体   English

Pycharm 4.0.4无法运行文件,而是在上下文菜单中显示“运行Doctests”

[英]Pycharm 4.0.4 cannot run file, shows 'Run Doctests' in context menu instead

I have copied a .py file from my teacher, and loaded it in to a project in Pycharm 4.04. 我从我的老师那里复制了一个.py文件,并将其加载到Pycharm 4.04中的一个项目中。 When i tried to right-click and run it, it shows "Run Doctests in 'foo.py'" instead of the regular "Run 'foo.py'", and i cannot find out how to run it normally. 当我试图右键单击并运行它时,它显示“在'foo.py'中运行Doctests”而不是常规的“Run'foo.py'”,我无法找到如何正常运行它。

I searched for 'doctest' in settings and found nothing, and in PyCharm documentation here , there's nothing about disabling doctests either. 我在设置搜索“文档测试”,发现什么都没有,和PyCharm文档中在这里 ,也没什么可说要么禁用文档测试。

I found a similar question here: Pycharm won't allow to run a file. 我在这里发现了一个类似的问题: Pycharm不允许运行文件。 Shows run unittest option only. 仅显示运行unittest选项。 and tried the suggested solution, but it still showed "Run doctests in 'foo.py'" in context menu. 并尝试了建议的解决方案,但它仍然在上下文菜单中显示“在'foo.py'中运行doctests”。

I'm having the same Run 'Doctests in __init__' issue with PyCharm 2016. I'm not sure if this is due to the same problem other people are having, but this is my fix. 我在PyCharm 2016上遇到了与__init__相同的Run'Doctests 。我不确定这是否是由于其他人遇到的同样问题,但这是我的修复。

I noticed the file that won't run lives in a resource directory: 我注意到不会在资源目录中运行的文件:

点击这里查看图片

Once I opened a new PyCharm project with the script I want to run not in a resource directory, PyCharm ran it with no problem. 有一次,我开了一家新的PyCharm项目,我想在一个资源目录运行脚本,PyCharm没有问题跑了。

Just had the same issue. 刚刚遇到同样的问题。 In my case, I had a '>>>' string within the docs of a function: 就我而言,我在函数的文档中有一个'>>>'字符串:

def foo(x):
    """Do foo.
    Example:
    >>>foo(1)
    # Out: 1
    """
    return x

I had to comment out # >>>foo(1) and delete the run config under Run > Edit Configurations (minus symbol). 我必须注释掉# >>>foo(1)并删除Run> Edit Configurations(减号)下的运行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM