简体   繁体   中英

install numpy for pycharm on mac

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.

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" 小路

2. Click on "Project Interpreter" and go for "+" button 添加包

3. Type "numpy" and "install package" 安装包

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM