简体   繁体   English

在mac上为pycharm安装numpy

[英]install numpy for pycharm on mac

I'm completely new to Python, and just downloaded Anaconda with a professional license.我对 Python 完全陌生,刚刚下载了具有专业许可证的 Anaconda。 I then cloned a GitHub repository into PyCharm to work on as my first project.然后我将 GitHub 存储库克隆到 PyCharm 作为我的第一个项目。

PyCharm (which I've never used before) fails on the first line of code: PyCharm(我以前从未使用过)在第一行代码中失败:

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.我的理解是 Anaconda 应该与 numpy、scipy 和其他一些关键软件包一起“发货”。 I get that PyCharm isn't finding that somehow, but how do I redirect it?我知道 PyCharm 没有以某种方式找到它,但我该如何重定向它? I'm using a Mac and PyCharm 2020.1.我使用的是 Mac 和 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. 其他一些帮助页面说从“设置”选项卡或文件/默认设置安装软件包,但在此版本的 IDE 中不存在这些按钮。 I also tried installing numpy in the Python console box based on this solution but that didn't work either:我还尝试基于此解决方案在 Python 控制台中安装 numpy ,但这也不起作用:

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?如何让 PyCharm “找到”我应该使用 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 :编辑:我设法为此项目打开 python 解释器并使用“+”按钮安装 numpy,但是当我运行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.编辑 2 :重新启动 PyCharm 后,此错误消失了......我很惊讶在安装 package 后这是必要的。

The main difference between PyCharm and Anaconda is that PyCharm is a quite convenient IDE and Anaconda is a set of python libraries. 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) :我现在可以向您推荐的内容:(在您的终端(⌘+空格 -> 终端)或 PyCharm 的终端中执行)

pip3 install numpy

The error you show seems like you tried to run it not in the terminal, but in python's console box:/您显示的错误似乎您尝试不在终端中运行它,而是在 python 的控制台框中:/

Also - here is a nice way to connect Anaconda's libraries to PyCharm另外 - 是将 Anaconda 的库连接到 PyCharm 的好方法

For installing libraries via PyCharm preferences:通过 PyCharm 首选项安装库:
1. Click on the "PyCharm" -> "Preferences" 1.点击“PyCharm”->“首选项”小路

2. Click on "Project Interpreter" and go for "+" button 2.点击“项目解释器”和“+”按钮的go添加包

3. Type "numpy" and "install package" 3.输入“numpy”和“安装包”安装包

Try this way:试试这个方法:

1: 1:

Pycharm Preferences => Phyton interpreter Pycharm 首选项 => Phyton 解释器

2: 2:

Select Project interpreter Select 项目解释器

3: 3:

Select the add button ( + ) Select 添加按钮(+)

4: 4:

in search bar search for numpy在搜索栏中搜索 numpy

5: 5:

Install package.安装 package。

If you still got errors如果您仍然遇到错误

No module named 'numpy'没有名为“numpy”的模块

Then go to Terminal left bottom corner of PyCharm software.然后 go 到 PyCharm 软件的终端左下角。

Then install numpy.然后安装 numpy。

pip install numpy

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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