为什么我在 Pycharm 中遇到导入错误以及什么是 virtualenv

问题描述 投票:0回答:1

我创建了一个与相机和手势识别有关的计算机视觉项目,当我第一次创建该项目时,整个代码运行良好且功能齐全,然后我关闭了该项目并尝试在一周后打开它,现在它给了我关于导入错误 numpy 和源树之类的东西的长错误。下面是确切的错误。顺便说一句,我使用的是 MacBook M1 Pro。苹果操作系统

我尝试再次运行它,但没有成功

/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/bin/python /Users/wali/Desktop/HandTracking/HandTrackingProject/HandTrackingModule.py 
Traceback (most recent call last):
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
    from . import multiarray
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
    from . import overrides
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
    from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
    from numpy.__config__ import show as show_config
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy.core._multiarray_umath import (
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
    raise ImportError(msg)
ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/bin/python"
  * The NumPy version is: "1.26.3"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: No module named 'numpy.core._multiarray_umath'


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/HandTrackingModule.py", line 1, in <module>
    import cv2
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/cv2/__init__.py", line 11, in <module>
    import numpy
  File "/Users/wali/Desktop/HandTracking/HandTrackingProject/.venv/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
    raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy

Process finished with exit code 1
python import pycharm virtualenv
1个回答
0
投票

嗯,也许尝试回溯中指定的方向? (在您的 venv(也称为 PyCharm 终端)中运行

pip install numpy
)。

我的意思是,回溯字面意思是

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
,所以我想阅读建议?

另外,请阅读一下什么是虚拟环境这里,我个人并不那么精通。

如果您还有其他问题,请告诉我。据报道,MacOS ARM 系列存在问题,因为 numpy 是用 C 语言编写的(我相信),因此请确保首先在 stackoverflow 上搜索您遇到的任何其他错误。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.