简体   繁体   English

在 PyCharm 上导入 NumPy

[英]Import NumPy on PyCharm

I'm trying to import NumPy on PyCharm.我正在尝试在 PyCharm 上导入 NumPy。

Using the PyCharm terminal and Miniconda I've launched the command:使用 PyCharm 终端和 Miniconda 我启动了命令:

conda install numpy

And this was the output:这是输出:

Fetching package metadata: ....
Solving package specifications: ....................
# All requested packages already installed.
# packages in environment at C:\Users\...\Miniconda3:
#
numpy                     1.10.4                   py35_0

So I run my project but the terminal said:所以我运行我的项目,但终端说:

ImportError: No module named 'numpy'

On my project bar I can see two different folders, the one with my project and another one with the external libraries.在我的项目栏上,我可以看到两个不同的文件夹,一个是我的项目,另一个是外部库。

Under External libraries > Extendend definitions there is a NumPy folder so I guess that the installation goes well.External libraries > Extendend definitions有一个 NumPy 文件夹,所以我猜安装进行得很顺利。

Go to

  1. ctrl-alt-s ctrl-alt-s
  2. click "project:projet name"单击“项目:项目名称”
  3. click project interperter单击项目互操作者
  4. double click pip双击pip
  5. search numpy from the top bar从顶部栏中搜索 numpy
  6. click on numpy单击 numpy
  7. click install package button单击安装包按钮

if it doesnt work this can help you:如果它不起作用,这可以帮助您:

https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html

In PyCharm go to在 PyCharm 中转到

  1. File → Settings, or use Ctrl + Alt + S文件 → 设置,或使用Ctrl + Alt + S
  2. < project name > → Project Interpreter → gear symbol → Add Local <项目名称>→项目解释器→齿轮符号→添加本地
  3. navigate to C:\\Miniconda3\\envs\\my_env\\python.exe , where my_env is the environment you want to use导航到C:\\Miniconda3\\envs\\my_env\\python.exe ,其中my_env是您要使用的环境

Alternatively, in step 3 use C:\\Miniconda3\\python.exe if you did not create any further environments (if you never invoked conda create -n my_env python=3 ).或者,如果您没有创建任何其他环境(如果您从未调用conda create -n my_env python=3 ),则在步骤 3 中使用C:\\Miniconda3\\python.exe

You can get a list of your current environments with conda info -e and switch to one of them using activate my_env .您可以使用activate my_env conda info -e获取当前环境的列表,并使用activate my_env切换到其中之一。

It seems that each project may have a separate collection of python libraries in a project specific computing environment.似乎每个项目都可能在项目特定的计算环境中拥有单独的 Python 库集合。 To get this working with numpy I went to the terminal at the bottom of the pycharm window and ran pip install numpy and once the process finished running the install and indexing my python project was able to import numpy from the line of code import numpy as np .为了使用numpy我转到 pycharm 窗口底部的终端并运行pip install numpy ,一旦该过程完成运行安装和索引,我的 python 项目就能够从代码行import numpy as np . It seems you may need to do this for each project you setup in numpy.似乎您可能需要为在 numpy 中设置的每个项目执行此操作。

I have encountered problem installing numpy package to pycharm and finally figured out.我在将 numpy 包安装到 pycharm 时遇到了问题,终于想通了。 I hope it would be helpful for someone having the same problem in installing numpy and other packages on pycharm.我希望这对在 pycharm 上安装 numpy 和其他软件包时遇到相同问题的人有所帮助。

Pycharm Setting : Pycharm 设置:Pycharm 设置

Go to File => Setting => Project => Project Interpreter.转到文件 => 设置 => 项目 => 项目解释器。 On this window select the appropriate project interpreter.在这个窗口中选择合适的项目解释器。 After this, a list of packages under the selected project interpreter will be shown.之后,将显示所选项目解释器下的包列表。 From the list select pip and check if the version column and the latest version column are the same.从列表中选择 pip 并检查版本列和最新版本列是否相同。 If different upgrade the version to the latest version by selecting the pip and using the upward triangle sign on the right side of the lists.如果不同,通过选择 pip 并使用列表右侧的向上三角形符号将版本升级到最新版本。 Once the upgrading completed successfully, you can now add new packages from the plus sign.升级成功完成后,您现在可以从加号添加新包。

在此处输入图片说明

I hope this would be clear and useful for someone.我希望这对某人来说是清楚和有用的。

另一种选择是在 pycharm 上打开终端并使用 pip 安装它

sudo pip install numpy

I added Anaconda3/Library/Bin to the environment path and PyCharm no longer complained with the error.我将Anaconda3/Library/Bin添加到环境路径中,PyCharm 不再抱怨错误。

Stated by https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001194720/comments/360000341500https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001194720/comments/360000341500陈述

In general, the cause of the problem could be the following:一般来说,问题的原因可能如下:

You started a new project with the new virtual environment.您使用新的虚拟环境启动了一个新项目。 So probably you install numpy from the terminal, but it is not in your venv.所以可能你从终端安装了 numpy,但它不在你的 venv 中。 So所以

  • either install it from PyCahrm Interface: Settings -> Project Interpreter -> Add the package从 PyCahrm 界面安装它:设​​置 -> 项目解释器 -> 添加包

  • or activate your venv and -> pip install numPy或激活您的 venv 和 -> pip install numPy

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

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