python import module troubleshooting

博客讲述了在Python中导入munkres库时遇到问题,原因是自定义的Python文件命名为munkres.py,导致导入时出错。此外,还验证了很多库在Python2和Python3环境下无冲突,给出了导入错误的具体信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用到了一个叫做munkres的库

但每次import的时候都出现了问题

后来找到问题是我自己的python file 命名为munkres.py 

所以每次它import 的时候都是import 我自己的python file 

python 这一点也挺不好的,感觉就是很随意的,interpreter一脸懵逼?

还有问题是不是很多库都是python2 和python3 共同使用的,就是没有冲突,为了验证这一点我还特意搞了python2的环境,结果是没有冲突。

Traceback (most recent call last):
  File "f:/PythonDev/benchmarks/scripts/import_munres.py", line 5, in <module>

ImportError: cannot import name 'Munkres' from 'munkres' (f:\PythonDev\benchmarks\scripts\munkres.py)

RuntimeError Traceback (most recent call last) RuntimeError: module compiled against API version 0xf but this version of numpy is 0xd --------------------------------------------------------------------------- ImportError Traceback (most recent call last) ImportError: numpy.core.multiarray failed to import The above exception was the direct cause of the following exception: SystemError Traceback (most recent call last) SystemError: <built-in method __contains__ of dict object at 0x00000270A8577F80> returned a result with an error set The above exception was the direct cause of the following exception: ImportError Traceback (most recent call last) <ipython-input-21-035b45420c6e> in <module> ----> 1 from model.build_mtcnn_model import create_Pnet, create_Rnet, create_Onet 2 import numpy as np 3 import cv2 4 5 ~\Desktop\第五课 实战案例:基于FaceNet的人脸智能识别 - 副本\(ppt、源代码、数据)数据&代码\数据&代码\基于FaceNet的人脸智能识别\model\build_mtcnn_model.py in <module> ----> 1 from tensorflow.keras.layers import Conv2D, Input, MaxPool2D, Flatten, Dense, Permute 2 from tensorflow.keras.layers import PReLU 3 from tensorflow.keras.models import Model 4 5 # -----------------------------# C:\StFiles\Anaconda\lib\site-packages\tensorflow\__init__.py in <module> 36 import typing as _typing 37 ---> 38 from tensorflow.python.tools import module_util as _module_util 39 from tensorflow.python.util.lazy_loader import LazyLoader as _LazyLoader 40 C:\StFiles\Anaconda\lib\site-packages\tensorflow\python\__init__.py in <module> 35 36 from tensorflow.python import pywrap_tensorflow as _pywrap_tensorflow ---> 37 from tensorflow.python.eager import context 38 39 # pylint: enable=wildcard-import C:\StFiles\Anaconda\lib\site-packages\tensorflow\python\eager\context.py in <module> 32 from tensorflow.python
03-29
中文解释这段报错: (py39) zero@zero-desktop:~/ros2_ws$ ros2 run ncnn_ros2 ncnn_node Traceback (most recent call last): File "/home/zero/ros2_ws/install/ncnn_ros2/lib/ncnn_ros2/ncnn_node", line 33, in <module> sys.exit(load_entry_point('ncnn-ros2==0.0.0', 'console_scripts', 'ncnn_node')()) File "/home/zero/ros2_ws/install/ncnn_ros2/lib/ncnn_ros2/ncnn_node", line 25, in importlib_load_entry_point return next(matches).load() File "/home/zero/archiconda3/envs/py39/lib/python3.9/importlib/metadata.py", line 86, in load module = import_module(match.group('module')) File "/home/zero/archiconda3/envs/py39/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/home/zero/ros2_ws/install/ncnn_ros2/lib/python3.9/site-packages/ncnn_ros2/ncnn_node.py", line 2, in <module> File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/__init__.py", line 49, in <module> from rclpy.signals import install_signal_handlers File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/signals.py", line 15, in <module> from rclpy.exceptions import InvalidHandle File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/exceptions.py", line 16, in <module> from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy File "/opt/ros/jazzy/lib/python3.12/site-packages/rclpy/impl/implementation_singleton.py", line 32, in <module> rclpy_implementation = import_c_library('._rclpy_pybind11', package) File "/opt/ros/jazzy/lib/python3.12/site-packages/rpyutils/import_c_library.py", line 39, in import_c_library return importlib.import_module(name, package=package) File "/home/zero/archiconda3/envs/py39/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) ModuleNotFoundError: No module named 'rclpy._rclpy_pybind11' The C extension '/opt/ros/jazzy/lib/python3.12/site-packages/_rclpy_pybind11.cpython-39-aarch64-linux-gnu.so' isn't present on the system. Please refer to 'https://docs.ros.org/en/jazzy/How-To-Guides/Installation-Troubleshooting.html#import-failing-without-library-present-on-the-system' for possible solutions [ros2run]: Process exited with failure 1
最新发布
04-05
Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\__init__.py", line 23, in <module> from . import multiarray File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\multiarray.py", line 10, in <module> from . import overrides File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\overrides.py", line 7, in <module> from numpy._core._multiarray_umath import ( add_docstring, _get_implementing_args, _ArrayFunctionDispatcher) ModuleNotFoundError: No module named 'numpy._core._multiarray_umath' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\__init__.py", line 127, in <module> from numpy.__config__ import show_config File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\__config__.py", line 4, in <module> from numpy._core._multiarray_umath import ( ...<3 lines>... ) File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\Lib\site-packages\numpy\_core\__init__.py", line 49, 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.13 from "C:\Users\Lenovo\AppData\Local\Programs\Python\Python313\python.exe" * The NumPy version is: "2.2.4" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No mo
04-02
Traceback (most recent call last): File "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/_core/__init__.py", line 23, in <module> from . import multiarray File "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/_core/multiarray.py", line 10, in <module> from . import overrides File "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/_core/overrides.py", line 7, 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 "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/__init__.py", line 114, in <module> from numpy.__config__ import show_config File "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/__config__.py", line 4, in <module> from numpy._core._multiarray_umath import ( File "/home/blw/anaconda3/envs/BLW/lib/jvm/languages/python/lib/python3.10/site-packages/numpy/_core/__init__.py", line 49, 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.10 from "/home/blw/anaconda3/envs/BLW/bin/python3" * The NumPy version is: "2.2.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 th
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值