简体   繁体   中英

Regex Installed with Pip but Not Recognized

So I am trying to parse data from a file using regular expressions.

I've successfully installed regex...

pip install regex
Requirement already satisfied: regex in /usr/local/lib/python3.8/site-packages (2020.7.14)

And I'm including the module in my Python file....

import regex

But when I run my script I get the following error:

parser.py 14 <module>
import regex

ModuleNotFoundError:
No module named 'regex'

I have absolutely no clue as to what I'm doing wrong. Why is it not recognizing that I have the regex module installed? Any help is greatly appreciated.

您可以尝试import re并改用它(它是内置的)。

Figured it out!

Turns out pip and python were in totally different directories:

$ where pip
/usr/local/bin/pip
$ where python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3

All I had to do to fix that was this:

python -m pip install regex

This ensured that regex was installed to the /Library/Frameworks/Python.framework directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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