Ask Your Question

I have an error in #import numpy as np, why is that?

asked 2016-11-15 20:15:42 -0500

updated 2016-11-16 01:54:00 -0500

berak gravatar image

The code I am trying to run is this one: ( Microsoft Visual Studio Coomunity 2015, Open cv 3.1.0. and numpy is downloaded in directory C:)

PS: how can I copy-paste the code here so you can read it properly?

#import numpy as np
#import cv2

//cargamos la plantilla e inicializamos la webcam :
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')
cap = cv2.VideoCapture(0)

while (True) :
    //leemos un frame y lo guardamos
    ret, img =

    //convertimos la imagen a blanco y negro
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    //buscamos las coordenadas de los rostros(si los hay) y
    //guardamos su posicion
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    //Dibujamos un rectangulo en las coordenadas de cada rostro
    for (x, y, w, h) in faces :
cv2.rectangle(img, (x, y), (x + w, y + h), (125, 255, 0), 2)

//Mostramos la imagen
cv2.imshow('img', img)

//con la tecla 'q' salimos del programa
if cv2.waitKey(1) & 0xFF == ord('q') :
    cv2 - destroyAllWindows()
edit retag flag offensive close merge delete


  • "PS: how can I copy-paste the code here so you can read it properly?" -- you mark it with the mouse, and press the "10101" button.
berak gravatar imageberak ( 2016-11-16 01:01:03 -0500 )edit

is that supposed to be python ? (then you'll have to go back and learn the language basics)

berak gravatar imageberak ( 2016-11-16 01:03:17 -0500 )edit

yes it is... I understand... thanks for the useful tip!

polenorth1 gravatar imagepolenorth1 ( 2016-11-19 07:21:49 -0500 )edit

2 answers

Sort by » oldest newest most voted

answered 2016-11-17 01:56:20 -0500

KirtiSwagat gravatar image

Please remove # tag. Just save the above program with an extension .py and run the program as below.

Step 1 Go to Command Prompt. type- Python and hit enter key. it will move you to the Python environment by showing >>> symbol on the command prompt screen.

Step 2 just verify whether your numpy has successfully installed in your PC or not by typing the command;-" import numpy" . If it is showing >>> symbol, then your numpy installation is ok. If not u have to uninstall the numpy and re-install it again.

Step 3 If numpy is correctly installed in your pc, then compile your code with following command:- Python and hit enter key

It will compile your code.

This is very simple procedure.

edit flag offensive delete link more


OK thank you, but it doesn´t recognize "Python" othingsn Command Prompt Visual Studio 2015... I guess I am mixing too many things, I don´t know the basics also... just learning on my own!

polenorth1 gravatar imagepolenorth1 ( 2016-11-19 07:38:14 -0500 )edit

just remove/ uninstall all the with proper steps...

KirtiSwagat gravatar imageKirtiSwagat ( 2016-11-22 04:40:10 -0500 )edit

answered 2016-11-16 01:37:34 -0500

berak gravatar image

updated 2016-11-16 01:40:13 -0500

python uses # for comments , not // (this will throw a lot of other errors later)

so, your import statements have to look like:

import numpy as np
import cv2

also: " and numpy is downloaded in directory C:"

this is the wrong place. numpy has to go into python/Lib/site-packages (same as the cv2.pyd)

edit flag offensive delete link more


Yes it is in that directory, thanks, yesterday I added a new pythonpath- to there, because I didn´t know I was mixing languages-I am starting learning, on my own. Thanks!

polenorth1 gravatar imagepolenorth1 ( 2016-11-19 07:26:07 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-11-15 20:15:42 -0500

Seen: 274 times

Last updated: Nov 17 '16