简体   繁体   English

ipython3 在使用 python3.7 的终端中不起作用

[英]ipython3 does not work in the terminal with python3.7

I recently upgraded from Python3.6 to Python3.7.我最近从 Python3.6 升级到 Python3.7。 Since I have upgraded, when I type in ipython3 in the terminal I get an error:自从我升级后,当我在终端中输入ipython3时出现错误:

~$ ipython3
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/IPython/__init__.py", line 48, in <module>
    from .core.application import Application
  File "/usr/lib/python3/dist-packages/IPython/core/application.py", line 25, in <module>
    from IPython.core import release, crashhandler
  File "/usr/lib/python3/dist-packages/IPython/core/crashhandler.py", line 28, in <module>
    from IPython.core import ultratb
  File "/usr/lib/python3/dist-packages/IPython/core/ultratb.py", line 124, in <module>
    from IPython.utils import path as util_path
  File "/usr/lib/python3/dist-packages/IPython/utils/path.py", line 18, in <module>
    from IPython.utils.process import system
  File "/usr/lib/python3/dist-packages/IPython/utils/process.py", line 19, in <module>
    from ._process_posix import system, getoutput, arg_split, check_pid
  File "/usr/lib/python3/dist-packages/IPython/utils/_process_posix.py", line 24, in <module>
    import pexpect
  File "/usr/lib/python3/dist-packages/pexpect/__init__.py", line 75, in <module>
    from .pty_spawn import spawn, spawnu
  File "/usr/lib/python3/dist-packages/pexpect/pty_spawn.py", line 14, in <module>
    from .spawnbase import SpawnBase
  File "/usr/lib/python3/dist-packages/pexpect/spawnbase.py", line 224
    def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
                                                                   ^
SyntaxError: invalid syntax

Furthermore I have noticed that my jupyter-notebook does not seem to work with the python3 kernel now as well (I get the kernel dead error).此外,我注意到我的 jupyter-notebook 现在似乎也不适用于 python3 内核(我得到内核死错误)。

NOTEs:笔记:

  • ipython and jupyter-notebook are working with fine when I use them with Python2.当我将它们与 Python2 一起使用时,ipython 和 jupyter-notebook 运行良好。
  • I am using Ubuntu 18.04 (Bionic Beaver) although I don't think this is relevant我正在使用 Ubuntu 18.04 (Bionic Beaver),尽管我认为这无关紧要

async is a reserved keyword in python3.7 and an old version of pexpect is using async as variable. async是 python3.7 中的保留关键字,旧版本的 pexpect 使用async作为变量。 The solution is to upgrade pexpect.解决方案是升级 pexpect。

For me, it was conflicting with apt-get installed python3, so I had to first uninstall it/them:对我来说,它与 apt-get 安装的 python3 冲突,所以我必须先卸载它/它们:

sudo apt-get remove python-pexpect python3-pexpect

And then进而

sudo pip3.7 install --upgrade pexpect

UPDATE Please update your installed packages.更新请更新您安装的软件包。 This error for pexpect has been reported and closed already issue pexpect此错误已报告并已关闭问题


In Python 3.7, async and await are now reserved keywords.在 Python 3.7 中, asyncawait现在是保留关键字。 This is what is breaking some of your installed packages.这就是破坏某些已安装软件包的原因。

If you do not need the new features in 3.7, roll back to 3.6 and wait until your packages are updated to support the new syntax in 3.7如果您不需要 3.7 中的新功能,请回滚到 3.6 并等待您的包更新以支持 3.7 中的新语法

What's New in Python 3.7 Python 3.7 中的新功能

I just solve this problem by upgrading pexpect manually.我只是通过手动升级 pexpect 来解决这个问题。

Download pexpect4.6 source code from https://github.com/pexpect/pexpect/releases/tag/4.6https://github.com/pexpect/pexpect/releases/tag/4.6下载 pexpect4.6 源代码

Extract the source code, get into the folder and install the pexpect by:提取源代码,进入文件夹并通过以下方式安装 pexpect:

sudo python3.7 setup.py install

As others have noted, having the current version of the pexpect package should solve this.正如其他人所指出的,拥有pexpect包的当前版本应该可以解决这个问题。 In my case, the python3-pexpect package that I had installed through apt was stuck on an old version and I first had to remove it.就我而言,我通过 apt 安装的python3-pexpect包卡在旧版本上,我首先必须将其删除。 Then installing the current pexpect package through pip3 fixed the problem.然后通过 pip3 安装当前的pexpect包解决了这个问题。

async is a reserved word in Python 3.7 asyncPython 3.7的保留字

You can edit the packages yourself if you feel comfortable doing it.如果你觉得这样做很舒服,你可以自己编辑包。 Here is a shell command that does just that:这是一个执行此操作的 shell 命令:

sed "s/async/_async/g" "/usr/lib/python3/dist-packages/pexpect/spawnbase.py" > tmp.txt && cat tmp.txt > "/usr/lib/python3/dist-packages/pexpect/spawnbase.py" && rm tmp.txt

Otherwise, you might want to use Python 3.6 while waiting for an update.否则,您可能希望在等待更新时使用 Python 3.6。

This appears to be an issue related to async being keyword in Python 3.7这似乎是与async是 Python 3.7 中的关键字相关的问题

As given here , updating pipenv might be the solution如此处所示,更新pipenv可能是解决方案

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

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