1

I am unable to run NumPy in PyCharm, BUT it works fine from Terminal (Mac OS). How do I get NumPy to work in PyCharm?

This is the error message that I am getting from PyCharm:

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

1 Answer 1

1

It looks like the Python that is visible to Pycharm and the system python are different. You will have to specify which python interpreter Pycharm should use.

You can do this the following way:

  1. Press Ctrl+Alt+S to open the project Settings/Preferences.

  2. In the Settings/Preferences dialog Ctrl+Alt+S, select Project {project name} | Project Interpreter. Click the The Configure project interpreter icon and select Add.

You can also try adding this to the top of your Python files:

#!/opt/python3.7/bin/python 

This will allow you to specify which python interpreter should be used from the terminal. Just make sure that you are using a Python interepreter that already has numpy installed.

Sign up to request clarification or add additional context in comments.

9 Comments

I run Mac OS. I see Control and S BUT do not see Alt. I see Project Preferences in Edit Configuration .
BtB, I did take a clue from what you had mentioned, and changed the Python path. numpy now works in Pycharm. However, when I run my pure Python code ( in a path different to that of numpy) I get stuck. So, it appears I have to change Python Interpreter path when I run numpy and when I run pure Python code. But then, how can I run a Python code that has numpy code? How do I alter interpreter path? to run python + numpy combined code? Should I just have 1 directory for Python ?
You can try adding this to the top of your python files: #!/opt/python3.7/bin/python This will allow you to specify which python interpreter should be used from the terminal. Just make sure that you are using a python interepreter that already has numpy installed.
No problem. I am glad that I could help. Could you please mark my answer as the answer to the question?
Sure, but I am pretty new to Stackoverflow. How do I mark your answer as the one that solved the issue?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.