Atom shows ModuleNotFoundError when running python script

那年仲夏 提交于 2021-01-29 09:28:49

问题


I'm running Mac OS X (10.14.4) and I'm attempting to follow YouTube tutorial; https://www.youtube.com/watch?v=bDaxeg4HKQY; Image Detection with YOLO v2 Process Video in Python + openCV

In a UNIX Terminal I'm able to do the following:

  1. Configure a virtual environment and activate it; source activate tensorvid

  2. Run a python script to setup the necessary dependencies python3 setup.py build_ext --inplace

  3. Run a python script successfully python video_processing.py

Here is the initial code present video_processing.py:

import cv2
from darkflow.net.build import TFNet
import numpy as np
import time

option = {

    'model': 'cfg/yolo.cfg',
    'load': 'bin/yolo.weights',
    'threshold': 0.15
}

#tfnet = TFNet(option)

capture = cv2.VideoCapture('CallOnMe.mp4')

colors = [tuple(255 * np.random.rand(3)) for i in range(5)]

for color in colors:
    print(color)

Here is the correct output shown in the Terminal:

(204.81913044109854, 251.10740779370366, 179.94942134863612)
(252.91320724585321, 180.778985117877, 190.80678674396898)
(192.82964108641886, 186.81635896070537, 9.692333421690345)
(88.90586768830556, 33.25890210180309, 201.9617662283273)
(71.27947539601615, 253.32836287511097, 171.81978416084678)

However, when I try the above using ATOM for Mac I receive the following error:

Traceback (most recent call last):
File "/Users/macuser/darkflow-master/video_processing.py", line 1, in <module>
import cv2 ModuleNotFoundError: No module named 'cv2'

In Atom:

  1. I've created a virtual environment using 'Virtualenv' and named it 'tensorvid'

  2. I've tried to configure the 'script' using 'configure script' but that doesn't seem to work

Does anyone know how to configure Atom with the UNIX commands given so it works please?


回答1:


You need to install cv2 before it will work. cv2 is really opencv but to install it you need to activate your virtual environment and then type: pip install opencv-python. On a discussion dated in July 2018 it was stated that opencv was not compatible with python 3.7 but did work with versions 3.5 and 3.65. It may be compatible now.




回答2:


I believe I have an answer to my own question.

I simply installed the 'Hydrogen' package via Atom --> Preferences --> Packages

Now I can start a virtual environment and control it all within the Atom application.

Problem solved :-)



来源:https://stackoverflow.com/questions/55781213/atom-shows-modulenotfounderror-when-running-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!