Module not found in PyCharm but externally in Python

Answered

Hi!

 

I have a kind of curious problem with importing a certain module in PyCharm. I am using PyCharm 2016.3.2
on a Mac. I need the module 'neuron'. When I want to import it via 'import neuron' in PyCharm, it does not find it:

Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin

import neuron
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named neuron

If I launch the interpreter separately in a console, it works:

bg-chl315:~ carl$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import neuron
NEURON -- VERSION 7.4 (1380:90539e842093) 90539e842093
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

 

Those are the same Python 2.7 executables. I also invalidated the cache and restarted PyCharm once without effect. Also the module is 'found' to the extent that it shows up in the pull-down list of module propositions:

 


 

 

Any ideas welcome. Thank you!

 

2
21 comments

I unchecked the following 2 boxes (I couldn't run python commands from pycharm but could from command line so I knew it was a PyCharm thing) But my PyCharm interpreter was same as command line interpreter so I guessed it would be some other setting in PyCharm, and just started changing sh*t, and uncheckign this made it work again.

 

7

The below solution worked for me, select option 'Inherit global site-packages' 

 

4

Please, run this script in Pycharm and in Terminal: https://gist.github.com/vlasovskikh/968240f877117cb6c882 and provide both outputs here. Thank you.

1

Same here with:

import pandas.

If I run the code from the terminal it's all good but PyCharm does not see it.

PyCharm CE 2017.2.4 on mac os 10.13.2

 

thanks

1

I solved it for psutil on Python 3.6 by opening a terminal in PyCharm and installing the development packages:

 

sudo apt-get install python3.6-dev

 

Jo

1

Hi, ok:

 

PyCharm:

{'PATH': ['/Applications/NEURON-7.4/nrn/x86_64/bin',
'/usr/local/bin',
'/usr/bin',
'/bin',
'/usr/sbin',
'/sbin',
'/opt/X11/bin'],
'pkg_resources.working_set': [NEURON 7.4 (/Applications/NEURON-7.4/nrn/lib/python),
wsgiref 0.1.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7),
Python 2.7.10 (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload),
backports-abc 0.5 (/Library/Python/2.7/site-packages),
certifi 2017.1.23 (/Library/Python/2.7/site-packages),
cycler 0.10.0 (/Library/Python/2.7/site-packages),
functools32 3.2.3.post2 (/Library/Python/2.7/site-packages),
matplotlib 2.0.0 (/Library/Python/2.7/site-packages),
mpi4py 2.0.0 (/Library/Python/2.7/site-packages),
nose 1.3.7 (/Library/Python/2.7/site-packages),
numpy 1.12.0 (/Library/Python/2.7/site-packages),
pip 9.0.1 (/Library/Python/2.7/site-packages),
psutil 5.0.1 (/Library/Python/2.7/site-packages),
pyparsing 2.1.10 (/Library/Python/2.7/site-packages),
python-dateutil 2.6.0 (/Library/Python/2.7/site-packages),
pytz 2016.10 (/Library/Python/2.7/site-packages),
PyWavelets 0.5.1 (/Library/Python/2.7/site-packages),
singledispatch 3.4.0.3 (/Library/Python/2.7/site-packages),
six 1.10.0 (/Library/Python/2.7/site-packages),
subprocess32 3.2.7 (/Library/Python/2.7/site-packages),
tornado 4.4.2 (/Library/Python/2.7/site-packages),
vboxapi 1.0 (/Library/Python/2.7/site-packages),
virtualenv 15.1.0 (/Library/Python/2.7/site-packages),
altgraph 0.10.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
bdist-mpkg 0.5.0 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
bonjour-py 0.3 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
macholib 1.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
modulegraph 0.10.4 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
py2app 0.7.3 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
pyOpenSSL 0.13.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
scipy 0.13.0b1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
setuptools 18.5 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
xattr 0.6.4 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
zope.interface 4.1.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),
pyobjc-core 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Accounts 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-AddressBook 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-AppleScriptKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-AppleScriptObjC 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Automator 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-CFNetwork 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Cocoa 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Collaboration 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-CoreData 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-CoreLocation 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-CoreText 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-DictionaryServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-EventKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-ExceptionHandling 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-FSEvents 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-InputMethodKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-InstallerPlugins 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-InstantMessage 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-LatentSemanticMapping 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-LaunchServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Message 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-OpenDirectory 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-PreferencePanes 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-PubSub 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-QTKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Quartz 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-ScreenSaver 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-ScriptingBridge 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-SearchKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-ServiceManagement 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-Social 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-SyncServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-SystemConfiguration 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),
pyobjc-framework-WebKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC)],
'sys.path': ['/Applications/PyCharm.app/Contents/helpers/pydev',
'/Applications/NEURON-7.4/nrn/lib/python',
'/Applications/PyCharm.app/Contents/helpers/pydev',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Python/2.7/site-packages',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Users/carl/PycharmProjects/PyPN3'],
'sys.prefix': '/System/Library/Frameworks/Python.framework/Versions/2.7',
'sys.version_info': sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)}

 

Terminal:

{'PATH': ['/Applications/NEURON-7.4/nrn/x86_64/bin',

          '/usr/local/bin',

          '/usr/bin',

          '/bin',

          '/usr/sbin',

          '/sbin',

          '/opt/X11/bin'],

'pkg_resources.working_set': [NEURON 7.4 (/Applications/NEURON-7.4/nrn/lib/python),

                               wsgiref 0.1.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7),

                               Python 2.7.10 (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload),

                               backports-abc 0.5 (/Library/Python/2.7/site-packages),

                               certifi 2017.1.23 (/Library/Python/2.7/site-packages),

                               cycler 0.10.0 (/Library/Python/2.7/site-packages),

                               functools32 3.2.3.post2 (/Library/Python/2.7/site-packages),

                               matplotlib 2.0.0 (/Library/Python/2.7/site-packages),

                               mpi4py 2.0.0 (/Library/Python/2.7/site-packages),

                               nose 1.3.7 (/Library/Python/2.7/site-packages),

                               numpy 1.12.0 (/Library/Python/2.7/site-packages),

                               pip 9.0.1 (/Library/Python/2.7/site-packages),

                               psutil 5.0.1 (/Library/Python/2.7/site-packages),

                               pyparsing 2.1.10 (/Library/Python/2.7/site-packages),

                               python-dateutil 2.6.0 (/Library/Python/2.7/site-packages),

                               pytz 2016.10 (/Library/Python/2.7/site-packages),

                               PyWavelets 0.5.1 (/Library/Python/2.7/site-packages),

                               singledispatch 3.4.0.3 (/Library/Python/2.7/site-packages),

                               six 1.10.0 (/Library/Python/2.7/site-packages),

                               subprocess32 3.2.7 (/Library/Python/2.7/site-packages),

                               tornado 4.4.2 (/Library/Python/2.7/site-packages),

                               vboxapi 1.0 (/Library/Python/2.7/site-packages),

                               virtualenv 15.1.0 (/Library/Python/2.7/site-packages),

                               altgraph 0.10.2 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               bdist-mpkg 0.5.0 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               bonjour-py 0.3 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               macholib 1.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               modulegraph 0.10.4 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               py2app 0.7.3 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               pyOpenSSL 0.13.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               scipy 0.13.0b1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               setuptools 18.5 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               xattr 0.6.4 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               zope.interface 4.1.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python),

                               pyobjc-core 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Accounts 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-AddressBook 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-AppleScriptKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-AppleScriptObjC 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Automator 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-CFNetwork 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Cocoa 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Collaboration 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-CoreData 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-CoreLocation 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-CoreText 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-DictionaryServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-EventKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-ExceptionHandling 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-FSEvents 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-InputMethodKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-InstallerPlugins 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-InstantMessage 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-LatentSemanticMapping 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-LaunchServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Message 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-OpenDirectory 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-PreferencePanes 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-PubSub 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-QTKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Quartz 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-ScreenSaver 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-ScriptingBridge 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-SearchKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-ServiceManagement 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-Social 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-SyncServices 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-SystemConfiguration 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC),

                               pyobjc-framework-WebKit 2.5.1 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC)],

'sys.path': ['',

              '/Applications/NEURON-7.4/nrn/lib/python',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',

              '/Library/Python/2.7/site-packages',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',

              '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC'],

'sys.prefix': '/System/Library/Frameworks/Python.framework/Versions/2.7',

'sys.version_info': sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0)}

 

Apparently the PyChar does not have the path to the neuron module in the sys.path variable and in the working_set. When manually adding the path /Applications/NEURON-7.4/nrn/lib/python to the interpreter, the module loads but by program crashes. I just realized that python also crashes if a script based on the neuron module is started externally in the console.

0

Maybe you're updating your PYTHONPATH variable in your .bashrc file? 
Also, if your script crashes when started externally in console, of course, it will crash within PyCharm's console.

0

I have a similar problem. Trying to run https://pythonhosted.org/pyobjc/examples/core/Scripts/HelloWorld/index.html in PyCharm. It runs fine, but the code has a lot of red underlines, and the code editor can't find the files to import. The first failing import (in the editor) is Foundation, which is in my site-packages. 

I have added site-packages to the project structure as source files and marked both that directory and the subdirectory Foundations as source files. It doesn't help.

For a short while, a few times, the editor has found the files to import, but then it forgets it again. It's not something I've been able to reproduce in a consistent way.

0

I don't see a resolution to this, but have the same problem when trying to load ftfy package:

https://github.com/LuminosoInsight/python-ftfy/issues/92

This seems to be a PyCharm issue. Could someone please attend to this?

 

UPDATE: I worked around it by creating a Python virtual environment with inherited global site-packages. Now the import seems to load properly.

0

HiOLEG MELNIKOV! Yes, it looks like PyCharm bug, could you please create an issue in our issue tracker? https://youtrack.jetbrains.com/issues/PY

0

For whatever it is worth, I am having the same problem.  

from pygcode import Line
  • I am running Windows 10
  • I used pip to install pygcode. 
  • I can see the package in the site-packages directory
  • The site-packages directory is in my system path
  • PyCharm does not see it when I try to do an import.
  • If I run it directly in a script from the command line it works fine
  • I am running PyCharm 2017.3.3 Build PC-173.4301.16

Note:  I am not an expert PyCharm user.   Is there a project path I need to update in PyCharm?  (I looked but could not find one)

0

I have the same problem with psutil

PyDev console: starting.
Python 2.7.10 (default, Jul 15 2017, 17:16:57)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
import psutil
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Applications/PyCharm Edu.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named psutil

Any ETA or resolution to the issue?

0

Having a similar issue:

# noinspection PyUnresolvedReferences
from distutils.version import LooseVersion
using latest pycharm with virtual env.
0
Avatar
Permanently deleted user

I think your problem like mine. I tested import matplotlib in python shell, it is OK. But shows error in Pycharm. This is because Pycharm don't know the path of site-packages.

  1. You should add path of site-packages (for me C:\Program Files\Python 3.5\lib\site-packages) to PATH or
  2. In your code add these

    import sys    
    sys.path.append(r"C:\Program Files\Python 3.5\lib\site-packages")
    import matplotlib.pyplot as plt
    

I think it will help you :)

0

Another way to add the path to packages without modifying the code is to add it to Interpreter Paths list which can be found in the interpreter settings.

0
Avatar
Sistemista Senior4

Thank to Uvaisbsc

My issue concern openpyxl and this resolve for me, thanks a lot

0

I have the same problem, with Django 2.2.7, and Python 3.7.4 for example.

If I start a console from the root directory and launch a shell, it works. If I launch it from the manage.py tool in PyCharm, I get a similar "module not found" error.

 

I finally made it work simply by

  • opening the settings
  • selecting the 'Django Console' page (under Build, Execution, Deployment/Console)
  • clicking on the 'Starting script' window
  • clicking on OK

I had also ticked on the 'Always show debug console' on the Console settings, then ticked it off.

My impression is that any change in those settings seems to solve the problem, even if the change is reverted after that. It must be a settings which is not correctly formed until the user triggers a validation when touching a settings in one of those pages (not unlike Aiden3189, who also changed an option there).

Other attempts to restart / invalidate the cache / use another interpreter, or a virtual environment, ... failed. It's very likely an IDE bug, nothing else.

0

I had the same problem here in PyCharm on mac. I solved it by going in system preferences for pycharm while having the project that I am working on open (namely: UdemyCources) and then Project: UdemyCourses (in my case) then Project Interpreter then clicking on the gear in front of the Project Interpreter box and clicking on add and just clicking ok on the next window in order to get pycharm to update it's packages for the current project. I add the picture and I hope it works for you too.

0

Uvaisbsc solution worked fine for me.

I often develop parts of the project on an Ubuntu machine (faster) and then copy-paste to RPi4.

And I got into the habit of deleting venv at the target controller and rebuilding it as per instructions quoted by Uvaisbsc .

And then check the list of pakages (as highlighted by Lashkari M J above) to be sure that everything is in place.

I originally had the same problems with "smbus" and GPIO imports

0

Winfixit's solution works. pip install from pycharm terminal solves the problem.

0

Hi, the solution of  Uvaisbsc is nice, thank you. The problem is that i did not create the project with pycharm but copying existing files to a new directory created by the finder. And i did not have any virtualenv...

0

Please sign in to leave a comment.