简体   繁体   中英

Can't import numpy from pycharm

I have Anaconda3. When I use its interpreter from Pycharm or directly from the folder to import numpy I get the following error:

ImportError                               Traceback (most recent call last)
~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
     16 try:
---> 17     from . import multiarray
     18 except ImportError as exc:

~\Anaconda\lib\site-packages\numpy\core\multiarray.py in <module>
     13
---> 14 from . import overrides
     15 from . import _multiarray_umath

~\Anaconda\lib\site-packages\numpy\core\overrides.py in <module>
      6
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-d4cdadb62aa7> in <module>
----> 1 import numpy

~\Anaconda\lib\site-packages\numpy\__init__.py in <module>
    140     from . import _distributor_init
    141
--> 142     from . import core
    143     from .core import *
    144     from . import compat

~\Anaconda\lib\site-packages\numpy\core\__init__.py in <module>
     45 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     46         __version__, exc)
---> 47     raise ImportError(msg)
     48 finally:
     49     for envkey in env_added:

ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
  1. Check that you expected to use Python3.7 from "C:\Users\noamw\Anaconda\python.exe",
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.17.4" you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load failed: The specified module could not be found.

However, when I use it from ipython after activating my environment, using conda, it works just fine. It's really frustrating that I can't create a Pycharm project like this. Would really appreciate any help Thanks

Setting your environment as the interpreter for PyCharm should work. Got to Preferences --> Project --> Project Interpreter . In the drop down menu select your conda environment. Set it to something like: ~/Anaconda3/envs/myenvname/bin/python

It is a bummer that Pycharm has not looked into this issue and has not come up with a solution for it.

Most solutions I found suggest removing numpy and reinstalling it using pip install numpy , which basically defeats the purpose of having a conda environment and getting its benefits like conda revisions; not to mention the bad practice of using both pip and conda in the same environment.

Until Pycharm gets to the bottom of this, you can get around this issue following this:

  1. Activate your environment in command prompt.
  2. Use set command to print all environment variables.
  3. Copy the PATH environment variable.

在此处输入图片说明

  1. Add it to the environment variables of your Run/Debug configurations.

在此处输入图片说明

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