Python 使用virtualenv解释器时,Pycharm基本上不可用

Python 使用virtualenv解释器时,Pycharm基本上不可用,python,pycharm,virtualenv,Python,Pycharm,Virtualenv,我使用以下方法创建了一个virtualenv: python3 -m venv /path/to/new/virtual/environment 当我使用从virtualenv配置给解释器的Pycharm时,我不能在运行时添加变量,我不能向手表添加变量,我只能打印一些变量的值,也就是说,应用程序根本不工作。这也发生在2017年、2018年和2019年。所有模块都会出现此问题,即使基本上为空的模块也是如此。当我尝试为cc赋值时,得到的确切错误消息是: cc=9 Traceback (most r

我使用以下方法创建了一个virtualenv:

python3 -m venv /path/to/new/virtual/environment
当我使用从virtualenv配置给解释器的Pycharm时,我不能在运行时添加变量,我不能向手表添加变量,我只能打印一些变量的值,也就是说,应用程序根本不工作。这也发生在2017年、2018年和2019年。所有模块都会出现此问题,即使基本上为空的模块也是如此。当我尝试为
cc
赋值时,得到的确切错误消息是:

cc=9
Traceback (most recent call last):
File "/Users/kylefoley/codes/venv/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3184, in run_ast_nodes
code = compiler(mod, cell_name, "exec")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/codeop.py", line 133, in __call__
codeob = compile(source, filename, symbol, self.flags, 1)
TypeError: required field "type_ignores" missing from Module
当我使用不是使用
virtualenv
创建的解释器运行Pycharm时,我没有任何问题。现在让我演示一下,我已经正确地完成了所有Pycharm设置。当我打印
sys.version
时,我得到:

3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) 
Pycharm始终打印执行时使用的解释器,即:

/Users/kylefoley/codes/venv/bin/python "/Applications/PyCharm CE 2.app/Contents/helpers/pydev/pydevd.py"
venv
是由virtualenv创建的目录

# 更新

我将我的
venv
文件夹中的所有站点包放入系统解释器中,再次遇到相同的错误。所以抛出错误的模块肯定有问题

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3184, in run_ast_nodes
我甚至不知道为什么要使用
IPython
。这是模块所说的发生错误的地方,对我来说没有任何意义:

def run_ast_nodes(self, nodelist:ListType[AST], cell_name:str, interactivity='last_expr',
                    compiler=compile, result=None):
    """Run a sequence of AST nodes. The execution mode depends on the
    interactivity parameter.

    Parameters
    ----------
    nodelist : list
      A sequence of AST nodes to run.
    cell_name : str
      Will be passed to the compiler as the filename of the cell. Typically
      the value returned by ip.compile.cache(cell).
    interactivity : str
      'all', 'last', 'last_expr' , 'last_expr_or_assign' or 'none',
      specifying which nodes should be run interactively (displaying output
      from expressions). 'last_expr' will run the last node interactively
      only if it is an expression (i.e. expressions in loops or other blocks
      are not displayed) 'last_expr_or_assign' will run the last expression
      or the last assignment. Other values for this parameter will raise a
      ValueError.

      Experimental value: 'async' Will try to run top level interactive
      async/await code in default runner, this will not respect the
      interactivty setting and will only run the last node if it is an
      expression. 

    compiler : callable
      A function with the same interface as the built-in compile(), to turn
      the AST nodes into code objects. Default is the built-in compile().
    result : ExecutionResult, optional
      An object to store exceptions that occur during execution.

    Returns
    -------
    True if an exception occurred while running code, False if it finished
    running.
    """
    if not nodelist:
        return
    if interactivity == 'last_expr_or_assign':
        if isinstance(nodelist[-1], _assign_nodes):
            asg = nodelist[-1]
            if isinstance(asg, ast.Assign) and len(asg.targets) == 1:
                target = asg.targets[0]
            elif isinstance(asg, _single_targets_nodes):
                target = asg.target
            else:
                target = None
            if isinstance(target, ast.Name):
                nnode = ast.Expr(ast.Name(target.id, ast.Load()))
                ast.fix_missing_locations(nnode)
                nodelist.append(nnode)
        interactivity = 'last_expr'

    _async = False
    if interactivity == 'last_expr':
        if isinstance(nodelist[-1], ast.Expr):
            interactivity = "last"
        else:
            interactivity = "none"

    if interactivity == 'none':
        to_run_exec, to_run_interactive = nodelist, []
    elif interactivity == 'last':
        to_run_exec, to_run_interactive = nodelist[:-1], nodelist[-1:]
    elif interactivity == 'all':
        to_run_exec, to_run_interactive = [], nodelist
    elif interactivity == 'async':
        _async = True
    else:
        raise ValueError("Interactivity was %r" % interactivity)
    try:
        if _async:
            # If interactivity is async the semantics of run_code are
            # completely different Skip usual machinery.
            mod = ast.Module(nodelist)
            async_wrapper_code = compiler(mod, 'cell_name', 'exec')
            exec(async_wrapper_code, self.user_global_ns, self.user_ns)
            async_code = removed_co_newlocals(self.user_ns.pop('async-def-wrapper')).__code__
            if (yield from self.run_code(async_code, result, async_=True)):
                return True
        else:
            for i, node in enumerate(to_run_exec):
                mod = ast.Module([node])
                code = compiler(mod, cell_name, "exec")
                if (yield from self.run_code(code, result)):
                    return True

            for i, node in enumerate(to_run_interactive):
                mod = ast.Interactive([node])
                code = compiler(mod, cell_name, "single")
                if (yield from self.run_code(code, result)):
                    return True

        # Flush softspace
        if softspace(sys.stdout, 0):
            print()

    except:
        # It's possible to have exceptions raised here, typically by
        # compilation of odd code (such as a naked 'return' outside a
        # function) that did parse but isn't valid. Typically the exception
        # is a SyntaxError, but it's safest just to catch anything and show
        # the user a traceback.

        # We do only one try/except outside the loop to minimize the impact
        # on runtime, and also because if any node in the node list is
        # broken, we should stop execution completely.
        if result:
            result.error_before_exec = sys.exc_info()[1]
        self.showtraceback()
        return True

    return False

我刚决定在终端上写

pip uninstall iPython

成功了。据我所知,我没有使用iPython,也没有任何用处。

您可能应该在JetBrains的bug tracker上报告此bug:我已经报告了,但如果您查看他们的bug tracker,您会发现请求很少得到响应。我总是在pycharm中使用virtualenv,从未遇到过任何问题。很可能是由anaconda安装的。