problem to import modules

Answered

Hi, I am running the latest python3.7 and pycharm2019.  I have installed modules successfully via pip install numpy, for example.  however, in the pycharm editor, "import numpy" does not work.

ModuleNotFoundError: No module named 'numpy'

for that matter, other modules like scipy, pandas do not work either.

 

thanks in advance for any help and suggestion.

16 comments
Comment actions Permalink

Hi Dave,

How did you install it?
Do you see these packages in Settings/Preferences | Project | Project Interpreter?

0
Comment actions Permalink

Hi Sergey, thanks for the reply.

at command line, i did :

pip install numpy

and it installed successfully.  at the commend line, i can import numpy, and i do: dir (), numpy shows up

 

0
Comment actions Permalink

hi Sergey, let me just add, please see below, at the command line

>>> import numpy
>>> dir ()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'numpy']
>>>

it works at the command line. 

i did check the env. and made sure the windows environment variable path is set correctly for python:

c:\Users\dave_\AppData\.....

 

0
Comment actions Permalink

Hi Sergey, while I am at it.  let me add one more thing. It seems working on my jupyter notebook:

it just does not work on my PyCharm.
 
 
 
 
 
 
import thinkdsp
import pandas
import numpy
import matplotlib
import scipy
 
 
 
 
 
 
 
 
 
 
import qiskit
 
 
 
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-578b7f7e9727> in <module>
----> 1 import qiskit

ModuleNotFoundError: No module named 'qiskit'

0
Comment actions Permalink

Do you see these packages in File | Settings| Project | Project Interpreter?

I suspect you use different interpreter. Most likely you installed all packages to some system interpreter, while in PyCharm you use some virtual environment.

0
Comment actions Permalink

I do have the same issue (Pycharm 2019.1, fresh Anaconda 3 install and all packages updated (conda update --all))

Using the base Anaconda3 python with numpy etc. installed, but Pycharm can't run any script with python 3.7 because of this issue. I can see the packages in the project interpreter as well.

 

0
Comment actions Permalink

Hi Sergey, here is my interpreter setting.

Hi Aichmueller, my experience is similar to yours.

0
Comment actions Permalink

I added numpy module to my setting, and it worked!  thanks you guys.

0
Comment actions Permalink

@ M Aichmueller

Does it help if you start PyCharm from anaconda (same environment)?

Another way is to do the following:

- run import os in the system terminal using the same interpreter

- run print(os.environ['PATH'])

- copy the result and add as PATH environment variable to your Run/Debug Configuration

- do the same for Python Console settings to get it working too

 

Does any of it help?

0
Comment actions Permalink

Hey Sergey,

launching Pycharm from the anaconda prompt didnt change the outcome.

I cant append the output of the print to a user defined path variable in the environment of the configuration as the prompt doesnt seem to see the clipboard, unless something has been copied from within this prompt (e.g. from the system variables tab below it). Any other way of getting that information into a user PATH variable?

0
Comment actions Permalink

>launching Pycharm from the anaconda prompt didnt change the outcome.

You did it similar to this one, right? https://youtrack.jetbrains.com/issue/PY-27234#focus=streamItem-27-3349234.0-0

>I cant append the output of the print to a user defined path variable in the environment of the configuration as the prompt doesnt seem to see the clipboard, unless something has been copied from within this prompt (e.g. from the system variables tab below it).

So you cannot copy the output from the terminal?

>Any other way of getting that information into a user PATH variable?

Unfortunately, there are only two ways of fixing https://youtrack.jetbrains.com/issue/PY-27234, but if none of them work, you probably face another issue.

 

0
Comment actions Permalink

@Sergey Karpov: I stand corrected, readded the environment and redid the pycharm launch from the conda prompt and it actually worked now. So I can run it with this rather pesky workaround.

The issue you linked however says it has been fixed. Is this still being worked on though? Since I personally wouldn't consider this workaround anything more than a very temporary solution.

0
Comment actions Permalink

>The issue you linked however says it has been fixed. Is this still being worked on though? Since I personally wouldn't consider this workaround anything more than a very temporary solution.

Agree, it's not a solution at all. It appears that our fix doesn't work in some cases.
May I ask you to submit another issue (we would like to investigate them separately) to https://youtrack.jetbrains.com/issues/PY and attach your idea.log from Help | Show Log in... and the entire error message (just copy the whole console output)?

0
Comment actions Permalink

I have the exact same issue using Python 3.7 and Pycharm 2019

0
Comment actions Permalink

@Jasconsult

Please report it to https://youtrack.jetbrains.com/issues/PY and attach idea.log file from Help | Show Log in... along with a screenshot showing the problem.

0
Comment actions Permalink

Will do. Thanks

0

Please sign in to leave a comment.