Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have tried importing NumPy in Python, but it did not succeed:

>>> import numpy as np 

x=np.array([[7,8,5],[3,5,7]],np.int32) 

Traceback (most recent call last): 

File "<pyshell#3>", line 1, in <module> 

import numpy as np 

File "C:\Python27\lib\numpy\__init__.py", line 127, in <module> raise ImportError(msg) 

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.

How can I fix this?

2 Answers

0 votes
by (106k points)

You should read the error message which is saying; your working directory should not be the NumPy source directory when you invoke Python; NumPy should be installed and your working directory should be anything but the directory where it lives.

To know more about this you can have a look at the following video tutorial:-

0 votes
by (37.3k points)

We need to follow some basic steps in order to import numpy in our Python shell. Below you can find all the steps.

Step 1: Open the Python shell:

On our command prompt or terminal, search Python or Python3, depending upon the installation of Python, and hit enter.

Step 2: Import numpy:

Once we are inside the Python shell, we need to run one command to import numpy.
Import numpy as np

Finally, we will be able to import numpy with the help of the above steps and commands.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...