Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'regex._regex' #413

Open
mrabarnett opened this issue Jun 7, 2021 · 15 comments
Open

ModuleNotFoundError: No module named 'regex._regex' #413

mrabarnett opened this issue Jun 7, 2021 · 15 comments
Labels
bug Something isn't working major

Comments

@mrabarnett
Copy link
Owner

Original report by Anonymous.


On both the latest (2021.4.4) and previous (at least all from 2020.10.11-2021.3.17) versions, regex has a ModuleNotFoundError similar to issue #349

I'm using python 3.9.5 on windows 10

@mrabarnett
Copy link
Owner Author

Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett).


Cannot reproduce.

@mrabarnett
Copy link
Owner Author

Original comment by Sanath Jathanna (Bitbucket: [Sanath Jathanna](https://bitbucket.org/Sanath Jathanna), ).


(I’m the issue creator, hadn’t logged in)

I’ve tested it in a clean venv with only regex installed and I still get the issue. Any way for me to check whether regex installed properly such as the file layout or something?

@mrabarnett
Copy link
Owner Author

Original comment by Matthew Barnett (Bitbucket: mrabarnett, GitHub: mrabarnett).


How are you installing it? The recommended way is py -m pip install regex, which works for me.

@mrabarnett
Copy link
Owner Author

Original comment by Sanath Jathanna (Bitbucket: [Sanath Jathanna](https://bitbucket.org/Sanath Jathanna), ).


Didn’t work for me. Windows update seems to have fixed the issue, though I cant be sure. The update broke a lot of my workflow and I had to reinstall quite a few things, any one of them could have been the issue. Either way, the problem seems to be fixed

Edit: Figured out the issue. pip was installing the 32 bit wheel, its still doing it unless im in a venv so ill have to figure out how to avoid that

@drmfinlay
Copy link

I have encountered this problem when using the package in Python installations with different ABIs that share a common site-packages directory.

My experience is with two different Python installations on a Windows system — Python 3.8 (32-bit) and Python 3.8 (64-bit). If I install regex to the 32-bit installation (with py -3.8-32 -m pip install regex), I can import and use the package as expected. However, if I try to install it to the 64-bit installation, pip will say it is already installed and, when importing regex in the interpreter, the internal _regex module (for a different ABI) will not be importable. Hence, the ModuleNotFoundError.

This is fixed by reinstalling regex for the Python installation where the problem occurs. This can be done by running pip install --force-reinstall regex. One may also solve the problem by configuring the Python installations to use separate site-packages directories. (I am not sure how to do this, but I presume there is a way.)

Unless I am much mistaken, only a very small percentage of users, i.e. those with unusual Python configurations, will be affected by this. It might not be worth fixing.

@davedx
Copy link

davedx commented Jun 20, 2022

I have this issue on MacOS with the python3.8 installation. I've tried all kinds of invocations of pip to uninstall it, force reinstall it, update it, I've tried rm -rf /usr/local/lib/python3.8/site-packages/regex, pinning the version to older version, newer versions, and for nltk (which is why I'm using this package) I've tried nltk --no-binary=regex in the requirements.txt. Nothing works.

Interpreter:

python3
Python 3.9.10 (main, Jan 15 2022, 11:48:04) 
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import regex
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/usr/local/lib/python3.8/site-packages/regex/regex.py", line 402, in <module>
    import regex._regex_core as _regex_core
  File "/usr/local/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ModuleNotFoundError: No module named 'regex._regex'

I've also read on the internet that this could be something to do with binaries, which is a bit beyond me in terms of how I should solve it. Any tips or advice really welcome, I'm totally blocked by this.

Edit: I finally managed to fix this. What I did was this (probably better methods exist):

  • Installed latest Python (3.10) for MacOS from the official site
  • Force removed the python3.8 directories that pip was still using (this broke pip)
  • Downloaded the get_pip script and used python3 (now python 3.10) to reinstall pip
  • Reinstalled using my project's requirements.txt (pip install -r requirements.txt)
  • Now regex module is importable

I have no idea why this fixed it. Something is quite broken in the ecosystem I think.

@Maozerhouni
Copy link

I have this issue on MacOS with the python3.8 installation. I've tried all kinds of invocations of pip to uninstall it, force reinstall it, update it, I've tried rm -rf /usr/local/lib/python3.8/site-packages/regex, pinning the version to older version, newer versions, and for nltk (which is why I'm using this package) I've tried nltk --no-binary=regex in the requirements.txt. Nothing works.

Interpreter:

python3
Python 3.9.10 (main, Jan 15 2022, 11:48:04) 
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import regex
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/site-packages/regex/__init__.py", line 1, in <module>
    from .regex import *
  File "/usr/local/lib/python3.8/site-packages/regex/regex.py", line 402, in <module>
    import regex._regex_core as _regex_core
  File "/usr/local/lib/python3.8/site-packages/regex/_regex_core.py", line 21, in <module>
    import regex._regex as _regex
ModuleNotFoundError: No module named 'regex._regex'

I've also read on the internet that this could be something to do with binaries, which is a bit beyond me in terms of how I should solve it. Any tips or advice really welcome, I'm totally blocked by this.

Edit: I finally managed to fix this. What I did was this (probably better methods exist):

  • Installed latest Python (3.10) for MacOS from the official site
  • Force removed the python3.8 directories that pip was still using (this broke pip)
  • Downloaded the get_pip script and used python3 (now python 3.10) to reinstall pip
  • Reinstalled using my project's requirements.txt (pip install -r requirements.txt)
  • Now regex module is importable

I have no idea why this fixed it. Something is quite broken in the ecosystem I think.

Does that mean regex would only work with python 3.10 ?

@mrabarnett
Copy link
Owner Author

It's currently supported back to Python 3.6. I'm on Windows 10 and I don't have any Apple stuff.

@a28293971
Copy link

Hey guys.
My solution is install regex manually.

I found that pip install 32bit version in default. But my python is 64bit.
So, I go to PyPI(Link) and download right file for me.

E.g. I want to install Python3.8 with 64bit in Windows, so I download this:
image

Then, manually install it: pip install --force-reinstall .\regex-2023.5.5-cp38-cp38-win_amd64.whl
And it successfully install 64bit pyd file in dst folder for me.
image

Finally, it works~.

@MrLukezy
Copy link

MrLukezy commented Jun 2, 2023

Hey guys. My solution is install regex manually.

I found that pip install 32bit version in default. But my python is 64bit. So, I go to PyPI(Link) and download right file for me.

E.g. I want to install Python3.8 with 64bit in Windows, so I download this: image

Then, manually install it: pip install --force-reinstall .\regex-2023.5.5-cp38-cp38-win_amd64.whl And it successfully install 64bit pyd file in dst folder for me. image

Finally, it works~.

it does work.!!!

@jinghaoliu
Copy link

Using conda install regex is also works for this problem.

@matkoniecz
Copy link

python3.10 -m pip install regex --ignore-installed worked (regex was distutils installed project for other python version so it was not working and was not detected, but it was detected by pip and therefore it refused to install a version of it...)

Beware: it is likely a horrific hack. It may break your or mine system in weird way.

@Petyrrr
Copy link

Petyrrr commented Dec 6, 2023

python3.10 -m pip install regex --ignore-installed worked (regex was distutils installed project for other python version so it was not working and was not detected, but it was detected by pip and therefore it refused to install a version of it...)

Beware: it is likely a horrific hack. It may break your or mine system in weird way.

This is my situation regarding this problem:

I downloaded Python 3.12 in order to code a chatbot. All seemed to be well until I ran into a problem with importing tenserflow. 3.12 has dropped imp in favor of importlib but tf still uses imp. I downloaded Python 3.11 to get around this, but now it can't import regex module. I've attempted to use all the tips above, but my case is different since it's between Python 3.12 and 3.11 and not between 64bit and 32bit.

@mrabarnett
Copy link
Owner Author

Have you installed regex for Python 3.12?

@Petyrrr
Copy link

Petyrrr commented Dec 7, 2023

Yes. At this point, I will attempt a complete uninstall of Python from my machine and start over from 3.11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working major
Projects
None yet
Development

No branches or pull requests

9 participants