PyCharm Won't Import Module (Numpy) Even Though It Shows It's Installed

Answered

I'm sorry if this problem has already been covered. I'm new to Python and PyCharm, so I may have missed something, but I checked similar questions and didn't see a solution that applied to me. 

 

I created a virtual environment and installed numpy using PyCharm's GUI. The screenshots below of the 1) project interpreter settings and 2) terminal verify that the installation took place. 


However, when I try to import numpy in the session, I get an error:

I thought it might be something wrong with numpy itself, but the same problem occurs with pandas. 

12 comments
Comment actions Permalink

Hi Fenixjeanne,

Thank you for contacting PyCharm support.

Please provide a screenshot of your Run/Debug Configuration window (Run | Edit Configurations...).

Looking forward to your reply.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

1
Comment actions Permalink

I hope this was the screenshot you were looking for.

0
Comment actions Permalink

Please check your Python interpreter in  `Settings | Build, Execution, Deployment | Console | Python Console`.

It should be the same as your Project Interpreter as shown on the screenshot with example:

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0
Comment actions Permalink

The interpreter looks to be the same - PyCharm_projs

0
Comment actions Permalink

Thanks for the update.

Is `import numpy` resolved in the Editor?

Please provide more details about the scenario. Do you import numpy in the Python Console or run code from Editor to console?

If possible, please attach a sample project so I can try to reproduce.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0
Comment actions Permalink

I imported in the console. I don't know why because I didn't change settings, but it is now working. I imported numpy just now with no problem. Could exiting the program have reset PyCharm?

0
Comment actions Permalink

That's odd.

Yes, it could be there was something with indexing. When restarted PyCharm reindexed the project and probably that is what resolved the issue.

Thank you for letting me know anyway.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0
Comment actions Permalink

Hi,

I recently installed on a fresh windows 10 installation (with all the updates) the following:

Anaconda3-2018.12-Windows-x86_64.exe

 

and then:

pycharm-community-2018.3.3.exe

 

I turned on PyCharm and created a new project with existing interpreter C:\Users\<username>\AppData\Local\Continuum\anaconda3\python.exe

 

I created a new python file and set the interpreter the same as the project default.

I typed "import numpy as np" and tried to run. It didn't work. Then I tried directly in the console and the same result.

The message says that it couldn't load the DLL and that it is probably broken.

A colleague tried the same thing with the same result.

 

Please help,

Viktor

0
Comment actions Permalink

Hi Viktorpopescu,

The problem is caused by known issue https://youtrack.jetbrains.com/issue/PY-27234. It should be fixed in 2019.1 version. We have just realised our EAP build which has a fix for it. Would you mind give it a try?

You can download it from https://www.jetbrains.com/pycharm/nextversion/

0
Comment actions Permalink

Hi,

 

I've recently downloaded and installed Pycharm V 2019.3 EAP for Python 3.7. I'm using it with Anaconda and I am running into the same issues above. When I type "import numpy as np" into the console and the editor, I see the same error

Traceback (most recent call last):
File "C:\Users\anagr\AppData\Roaming\Python\Python37\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-d4cdadb62aa7>", line 1, in <module>
import numpy
File "C:\Program Files\JetBrains\PyCharm Community Edition 193.4099.14\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\anagr\AppData\Roaming\Python\Python37\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Program Files\JetBrains\PyCharm Community Edition 193.4099.14\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\Users\anagr\AppData\Roaming\Python\Python37\site-packages\numpy\_distributor_init.py", line 26, in <module>
WinDLL(os.path.abspath(filename))
File "C:\Users\anagr\Anaconda3\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 is not a valid Win32 application

I've tried installing a different version of numpy, uninstall and reinstall Pycharm, nothing seems to work.

 

Thanks,

0
Comment actions Permalink

In general the cause of the problem could be the following:

You started new project with new virtual environment. So probably you install numpy from the terminal, but it s not in your venv. So

- either install it from PyCahrm Interface: Settings -> Project Interpreter -> Add the package

- or activate your venv and -> pip install numpy

0
Comment actions Permalink

Hello, noticed a similar problem on my end, found this by googling, and it's some what relevant.

It seems the scratch.py wasn't connected to the console pip installs as i thought it would, and everyone is suggesting the correct steps. I checked all those things, everything checked out.

One note, someone mentioned testing import works in console. this helped a bit.

i kicked off python in the same pip install console within pycharm 3.7 python project and was able to see the import numpy as np is working, a deeper dive I found making a python in the virtual environment directory was a quick work around to getting the imports to work in the python editor. granularity explained below.

  1. bottom left using terminal, open and pip install pandas that will install pandas + other things.

  2. type python hit enter
  3. the python terminal starts >>>
(venv) bash-3.2$ python 
Python 3.7.0 (default, Jun 29 2018, 20:14:27)
[Clang 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pandas as pd
  1. type import numpy as np (this step shows the pip install works and it's connected to this instance)
    import numpy as np
  2. at this point i tried using a scratch.py
  3. Notice the scratch py isn't working with the imports, even though we have the installation and tested it's working
  4. Open your project folder, make a new file in the venv directory by right clicking the directory and selecting new.
  5. Make a python file here, in the virtual evironment, this will be connected to your 'python console' pip installation of panda
  6. Seen in screenshot below

excuse my mistakes, seems this might be more of a directory/access issue that is remediable when putting a python file in a different directory.

best,

tyler garrett

0

Please sign in to leave a comment.