Re Module Has No Attribute Compile
Solution 1:
Yes it was a case of some code I imported shadowing the the inbuilt re. I solved this by making sure I put the import of re at the very last of my imports so it took precedence.
Solution 2:
You can debug such scenario by using imp.find_module()
:
import imp
imp.find_module("re")
It will tell you which re.py
is imported.
Solution 3:
Upgrade your pip version using: python -m pip install --upgrade pip
in the cmd
Then import regex module again using: pip install regex
.
Solution 4:
That's probably because your filename is "re.py".
Solution 5:
if anyone gets here you might have just used a name for your .py that is already a library. I made one called enum.py and got this error. I renamed it to something unique and all was happy again.
Thank you for your feedback, I will add to my answer to make it more clear as to why is it relevant to the original question.
The original question had an issue after importing their own module called re I did the same but named my enum. Some of the answers here were helpful but vague. I am making it more clear that you must use unique names in your code or can experience this with any attribute, class or function that is used by the library or its dependencies. By me having this file enum.py in my project folder I pretty much broke my interrupter. The point of my reply is that if you find yourself here like did, this might help you quicker than reading all the other steps that were taking to get to this solution.
Post a Comment for "Re Module Has No Attribute Compile"