3

I am unable to run numpy in Pycharm BUT works fine in the Terminal. How do I make numpy work in Pycharm?

This is the error message I get in Pycharm

Traceback (most recent call last):
  File "/Users/giridhar/PycharmProjects/numpy/testfile", line 12, in <module>
    a = np.array([1, 2, 3])   # Create a rank 1 array
AttributeError: module 'numpy' has no attribute 'array'
Benji
  • 549
  • 7
  • 22

1 Answers1

2

Update:

It's quite likely that you have a file called numpy.py in another directory.

When you run testfile.py in your terminal, you are inside of your directory 'numpy' which does not have a file numpy.py and that's why it finds the correct numpy-module.

However, in PyCharm you can add directories to Sources Root (i.e. sys.path as explained in this answer) which apparently contains a file called numpy.py. Remove that directory from your sys.path (as explained by jetbrains) and it should also work in PyCharm.


Old answer (wrong!):

As of my knowledge, the directory name does not interfere with module names unless maybe you define your directory as a package using __init__.py
You need to be careful with how you name your directories. It's possible that the Python interpreter uses your directory 'numpy' to find the function 'array()' instead of using the PyPI numpy-module. Re-naming that directory might fix your issue.
So, e.g. "/Users/giridhar/PycharmProjects/my-numpy/testfile"

Benji
  • 549
  • 7
  • 22