我正在尝试在我的 python 脚本中使用 regex 包,使用:
import regex as re
并且包裹丢失:
$ ./lula2.py
Traceback (most recent call last):
File "./lula2.py", line 13, in <module>
import regex as re
ImportError: No module named regex
我正在尝试安装它,但收到以下错误/失败:
$ sudo apt install regex
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package regex
$ sudo apt install python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-pip
请告诉我如何安装regex
。
答案1
python-pip
并且python-regex
包位于 Universe 存储库中。使用以下命令启用它:
sudo add-apt-repository universe
sudo apt update
然后安装regex
:
sudo apt install python-regex #For Python 2
sudo apt install python3-regex #For Python 3
如果你想使用 pip 安装正则表达式:
安装 pip:
sudo apt install python-pip #For Python 2 sudo apt install python3-pip #For Python 3
然后正则表达式:
pip install regex #For Python 2 pip3 install regex #For Python 3