I created a virtualenv using:
python3 -m venv /path/to/new/virtual/environment When I use Pycharm configured to the interpreter from that virtualenv, I cannot add variables in run time, I cannot add variables to watches and I can only print the values of some variables, that is to say, the app does not work at all. This also happens in Pycharm 2017, 2018 and 2019. The problem further occurs with all modules, even with modules which are basically blank. The exact error message I get is when I try to assign a value to cc is:
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 When I run Pycharm using an interpreter which was not created using virtualenv, I have no problems. Now let me demonstrate that I have all of the Pycharm settings done correctly. When I print sys.version I get:
3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27) Pycharm always prints the interpreter being used on execution and that is:
/Users/kylefoley/codes/venv/bin/python "/Applications/PyCharm CE 2.app/Contents/helpers/pydev/pydevd.py" venv is directory created by the virtualenv.
UPDATE
I put all of my site-packages that were in my venv folder into the system interpreter and I again encountered the same error. So it must be a problem with the module that is throwing the error which is
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3184, in run_ast_nodes I don't even know why IPython is being used. This is what the module says where the error is occurring none of which means anything to me:
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 
