OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash [duplicate]

  • Thread starter Thread starter Mohit Gupta
  • Start date Start date
M

Mohit Gupta

Guest
Code:
Traceback (most recent call last):  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
    import imutils
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
    from .convenience import translate
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
    import cv2
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
    import imutils
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
    from .convenience import translate
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
    import cv2
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import
A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.0 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2.

I was trying to make a flask app that uses cv2 and imutils libraries of python in Pycharm. But there seems to be a problem in Pycharm.

The error seems to be on the lines of import statement :

Code:
import imutils
import cv2

I watched a tutorial online about how to download cv2 and imutils , but even after downloading there seems to be a problem.

The error is about the upgraded version of Numpy which I don't understand why it is happening , as I am not using Numpy.

Still I upgraded the version of Numpy but It does not work. I have tried multiple things the people have suggested but nothing is working I think i am not sure how to make a docker.

The problem can be something related to Pycharm. I am not sure.
<pre><code>Traceback (most recent call last): File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
import imutils
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
from .convenience import translate
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
import cv2
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
import imutils
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
from .convenience import translate
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
import cv2
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import
</code></pre>
<blockquote>
<p>A module that was compiled using NumPy 1.x cannot be run in NumPy
2.0.0 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to
rebuild instead e.g. with 'pybind11>=2.12'.</p>
<p>If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module. We
expect that some modules will need time to support NumPy 2.</p>
</blockquote>
<p>I was trying to make a flask app that uses cv2 and imutils libraries of python in Pycharm. But there seems to be a problem in Pycharm.</p>
<p>The error seems to be on the lines of import statement :</p>
<pre><code>import imutils
import cv2
</code></pre>
<p>I watched a tutorial online about how to download cv2 and imutils , but even after downloading there seems to be a problem.</p>
<p>The error is about the upgraded version of Numpy which I don't understand why it is happening , as I am not using Numpy.</p>
<p>Still I upgraded the version of Numpy but It does not work.
I have tried multiple things the people have suggested but nothing is working I think i am not sure how to make a docker.</p>
<p>The problem can be something related to Pycharm. I am not sure.</p>
 
Code:
Traceback (most recent call last):  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
    import imutils
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
    from .convenience import translate
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
    import cv2
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
    import imutils
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
    from .convenience import translate
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
    import cv2
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
    bootstrap()
  File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import


I was trying to make a flask app that uses cv2 and imutils libraries of python in Pycharm. But there seems to be a problem in Pycharm.

The error seems to be on the lines of import statement :

Code:
import imutils
import cv2

I watched a tutorial online about how to download cv2 and imutils , but even after downloading there seems to be a problem.

The error is about the upgraded version of Numpy which I don't understand why it is happening , as I am not using Numpy.

Still I upgraded the version of Numpy but It does not work. I have tried multiple things the people have suggested but nothing is working I think i am not sure how to make a docker.

The problem can be something related to Pycharm. I am not sure.
<pre><code>Traceback (most recent call last): File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
import imutils
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
from .convenience import translate
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
import cv2
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\tut2.py", line 8, in <module>
import imutils
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\__init__.py", line 8, in <module>
from .convenience import translate
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\imutils\convenience.py", line 6, in <module>
import cv2
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\mohit\OneDrive\Desktop\Front End\Flask\pythonProject1\.venv\Lib\site-packages\cv2\__init__.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Python312\Lib\importlib\__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import
</code></pre>
<blockquote>
<p>A module that was compiled using NumPy 1.x cannot be run in NumPy
2.0.0 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to
rebuild instead e.g. with 'pybind11>=2.12'.</p>
<p>If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module. We
expect that some modules will need time to support NumPy 2.</p>
</blockquote>
<p>I was trying to make a flask app that uses cv2 and imutils libraries of python in Pycharm. But there seems to be a problem in Pycharm.</p>
<p>The error seems to be on the lines of import statement :</p>
<pre><code>import imutils
import cv2
</code></pre>
<p>I watched a tutorial online about how to download cv2 and imutils , but even after downloading there seems to be a problem.</p>
<p>The error is about the upgraded version of Numpy which I don't understand why it is happening , as I am not using Numpy.</p>
<p>Still I upgraded the version of Numpy but It does not work.
I have tried multiple things the people have suggested but nothing is working I think i am not sure how to make a docker.</p>
<p>The problem can be something related to Pycharm. I am not sure.</p>
It looks like you're encountering an issue with the import of `cv2` and `imutils` in your Flask application, which is being developed in PyCharm. The error messages indicate a problem with NumPy, which is a dependency of OpenCV (`cv2`) and indirectly used by `imutils`.

Here are steps you can take to troubleshoot and potentially resolve the issue:

1. **Check Python Environment**:
- Ensure that your virtual environment (`pythonProject1\.venv`) is correctly set up and activated in PyCharm.
- Verify that NumPy is installed within this environment. You can check by running `pip list` in your terminal within PyCharm.

2. **NumPy Version Compatibility**:
- The error message suggests that there might be a mismatch between the versions of NumPy required by `cv2` and `imutils`.
- Try downgrading NumPy to a version that is compatible with both `cv2` and `imutils`. You can do this using:
```
pip install numpy==1.21.3
```
Replace `1.21.3` with a version that you find is compatible (typically, versions before NumPy 2.0).

3. **Reinstall Dependencies**:
- Sometimes, dependencies can become corrupted. It might help to reinstall `cv2` and `imutils`:
```
pip uninstall opencv-python imutils
pip install opencv-python imutils
```

4. **Check PyCharm Interpreter Settings**:
- Verify that PyCharm is using the correct Python interpreter and virtual environment where `cv2` and `imutils` are installed.
- Go to `File` -> `Settings` -> `Project: YourProjectName` -> `Python Interpreter` and ensure that the interpreter points to the correct virtual environment (`pythonProject1\.venv`).

5. **PyCharm Cache**:
- Sometimes, PyCharm caches can cause issues. Try clearing the caches and restarting PyCharm:
- Go to `File` -> `Invalidate Caches / Restart...` -> `Invalidate and Restart`.

6. **Docker Consideration**:
- If you're planning to deploy your Flask application using Docker in the future, ensure that your Dockerfile specifies the correct Python environment and dependencies (`opencv-python` and `imutils`) are included.

7. **Further Debugging**:
- If the issue persists, try running your Flask application outside of PyCharm (e.g., using the terminal). This can sometimes provide more straightforward error messages that help pinpoint the problem.

By following these steps, you should be able to resolve the NumPy-related import errors and successfully use `cv2` and `imutils` in your Flask application within PyCharm. If the issue continues, providing additional details from the error messages or trying alternative versions of NumPy might be necessary.
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top