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

时间:2019-12-02 10:47:22

标签: python pycharm virtualenv

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

python3 -m venv /path/to/new/virtual/environment

当我使用从virtualenv配置为解释器的Pycharm时,无法在运行时添加变量,无法将变量添加到监视中,并且只能打印某些变量的值,也就是说,该应用程序无法正常工作完全没有在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创建的目录。

configs

config2

更新

我将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

1 个答案:

答案 0 :(得分:0)

我刚决定在Terminal中写

pip uninstall iPython

做到了。据我所知,我没有使用iPython,也没有使用它。

相关问题