gpt4 book ai didi

python - 在 IDLE 或 Pycharm 中插入 ".so"

转载 作者:太空宇宙 更新时间:2023-11-03 14:21:35 24 4
gpt4 key购买 nike

我刚刚安装完 OpenCV,
主要问题是 import cv2 仅在从 shell 运行时有效。在这种情况下:

$ python3 
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 5 2014, 20:42:22)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>

那很好。
如果我们尝试从 IDLE 导入 cv2,就会发生这种情况:

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  5 2014, 20:42:22) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: No module named 'cv2'
>>>

发生这种情况是因为 idle 和 Pycharm 不知道 cv2.so 文件的路径。我们希望也可以从 IDLE 或 Pycharm 导入 cv2。

有人可以帮助我们吗?费德里科

编辑

Python3.4 Shell 系统路径:

['', '/Users/n1/Documents', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']

终端Python3.4 sys.path :

['', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']

最佳答案

抱歉回复晚了,也许对其他人有帮助。方法是(从 PyCharm 菜单):

Run > Edit Configurations... 

当对话框打开时,将 LD_LIBRARY_PATH 环境变量设置为您的库路径

enter image description here

关于python - 在 IDLE 或 Pycharm 中插入 ".so",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27272077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com