1

I'm completely new to Python, and just downloaded Anaconda with a professional license. I then cloned a GitHub repository into PyCharm to work on as my first project.

PyCharm (which I've never used before) fails on the first line of code:

import numpy as np
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm with Anaconda plugin .app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'numpy'

My understanding is that Anaconda should have "shipped" with numpy, scipy, and some other key packages. I get that PyCharm isn't finding that somehow, but how do I redirect it? I'm using a Mac and PyCharm 2020.1. Some of the other help pages said to install packages from the "settings" tab or file/default settings, but neither of those buttons exist in this version of the IDE. I also tried installing numpy in the Python console box based on this solution but that didn't work either:

pip3 install numpy
  File "<input>", line 1
    pip3 install numpy
               ^

How do I get PyCharm to "find" the software that I supposedly downloaded with Anaconda?

Edit: I managed to open the python interpreter for this project and install numpy with the "+" button, but it still gives this error when I run import numpy as np:

>>> import numpy as np
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm with Anaconda plugin .app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'numpy'

Edit 2: this error went away after restarting PyCharm... I'm surprised that's necessary after installing a package.

AFH
  • 665
  • 1
  • 9
  • 28
  • In PyCharm, press Ctrl + Alt + S and go to Project > Project Interpreter and click on + button and Install any desired package for your specific Project. – Devansh Soni Apr 16 '20 at 18:06
  • @DevanshSoni nothing happens when I try that shortcut in PyCharm on a Mac (or every other combination of keystrokes + s that I can think of), unless I'm missing something – AFH Apr 16 '20 at 18:10
  • 1
    In right bottom corner, Your python version is mentioned along with your project name. Click on that to go to Project Interpreter Settings. – Devansh Soni Apr 16 '20 at 18:12
  • There are multiple ways to do that. You can install it using 'Terminal' ( In left bottom corner ) also. – Devansh Soni Apr 16 '20 at 18:16

2 Answers2

3

The main difference between PyCharm and Anaconda is that PyCharm is a quite convenient IDE and Anaconda is a set of python libraries. What I can recommend you right now: (do it in your terminal (⌘+space -> terminal) or in PyCharm's terminal):

pip3 install numpy

The error you show seems like you tried to run it not in the terminal, but in python's console box :/

Also - here is a nice way to connect Anaconda's libraries to PyCharm

For installing libraries via PyCharm preferences:
1. Click on the "PyCharm" -> "Preferences" path

2. Click on "Project Interpreter" and go for "+" button add package

3. Type "numpy" and "install package"install package

  • you're right re terminal, oops! but I get this message: `Requirement already satisfied: numpy in /usr/local/lib/python3.7/site-packages (1.16.3)` suggesting that I did install numpy, but then pycharm can't find it when I run `import numpy as np`. – AFH Apr 16 '20 at 18:27
  • Try to run it in Python console in PyCharm Also - if needed - let`s add a "project interpreter". You can do it in "PyCharm" -> "Preferences" (⌘,) -> "Project" -> "Project Interpreter". You can choose any interpreter for starting (probably you have several) – Maks Fedorchuk Apr 16 '20 at 18:50
  • thanks! I had to close and reopen PyCharm but it works now. – AFH Apr 16 '20 at 19:32
0

Try this way:

1:

Pycharm Preferences => Phyton interpreter

2:

Select Project interpreter

3:

Select the add button ( + )

4:

in search bar search for numpy

5:

Install package.

If you still got errors

No module named 'numpy'

Then go to Terminal left bottom corner of PyCharm software.

Then install numpy.

pip install numpy
Samim Hakimi
  • 705
  • 8
  • 22