69

I installed bottle on python3.4 with pip install. In terminal, when I do:

$ python3.4
>>>import bottle # shows no import error
>>> 

but when I do it in PyCharm, it says "import bottle ImportError: No module named 'bottle'"

Mike G
  • 4,142
  • 9
  • 43
  • 64
Tinno TL
  • 693
  • 1
  • 5
  • 7
  • 2
    If your PyCharm configured to use the same `python3.4` that you use from the terminal? Have you set up a virtualenv or venv or user site-packages or `PYTHONPATH`? – abarnert Sep 26 '14 at 22:38
  • actually, I think I need to set the PYTHONPATH, any idea how can i do that? – Tinno TL Sep 26 '14 at 22:57
  • 1
    It looks like you have to click the gear next to the interpreter, then click `More…`, then click the same interpreter again in the list that pops up, then click the paths button (the fan-out icon that's rightmost of the 5 buttons on the bottom left), then you get a list of Interpreter Paths, where you can click the + button to add another one. – abarnert Sep 26 '14 at 23:06
  • But if you need to set `PYTHONPATH`, that's often a sign that you're doing something that might be better done with a `virtualenv`/`venv`, and PyCharm has some pretty nice support for that, so… have you considered that first? – abarnert Sep 26 '14 at 23:06
  • I solved it, just like in the picture. Thanks anyway! :) – Tinno TL Sep 26 '14 at 23:48
  • So it wasn't PYTHONPATH, just the wrong interpreter? You should still look into using a virtualenv, but glad you've solved the problem. – abarnert Sep 26 '14 at 23:52

8 Answers8

129

in your PyCharm project:

  • press Ctrl+Alt+s to open the settings
  • on the left column, select Project Interpreter
  • on the top right there is a list of python binaries found on your system, pick the right one
  • eventually click the + button to install additional python modules
  • validate

enter image description here

Thomasleveil
  • 82,296
  • 14
  • 115
  • 107
  • your welcome, also note a useful trick in the Settings panel, click the gear button above the `+` button and pick "Create VirtualEnv" to create a new environment in which the modules you will install later on won't mess up your python installation system-wide. This is also useful is you want to test different versions of a same module. – Thomasleveil Sep 26 '14 at 23:50
  • So you have to install the module on your system a second time? That seems a little ridiculous. Can't you just link to the module you already have or something? – user124384 Apr 22 '17 at 18:09
  • What's ridicule is to have applications break because of an upgrade of a module needed for another application. The isolation provided by virtualenv allows you to avoid the issue without adding complexity. – Thomasleveil Apr 23 '17 at 05:57
  • 5
    "Project Interpreter" is now under Settings > Project: [your project] > Project Interpreter. Or alternatively just use the search feature with Ctrl + Shift + A. – Matthew Woo Jul 25 '17 at 23:58
  • How can I do this for a locally developed module? – chris Mar 13 '18 at 22:30
  • @ChrisAnderson, go to `Project structure` in the menu and add the folder containing that module sources to the sources – Thomasleveil Mar 13 '18 at 22:55
  • I don't understand @Thomasleveil ... I installed the module using pip and PyCharm gave me error. I followed your answer and it works. But why? And also: pip becomes useless when using PyCharm? – gedamial Sep 26 '19 at 20:22
  • I have similar question like @gedmial. In my case everything was working. It suddenly stopped. I just re-cloned repo at different location it started working. But I didn't understood why this could have happened. – Pankaj Chimbalkar May 02 '20 at 06:19
  • This solution worked for me. I found that there were several python.exe installed by different IDEs, I selected the one I installed recently and it worked. Thank you. – Rahul Varadkar Jul 22 '20 at 13:39
  • Yes this worked for me. I had several copies of python.exe on my local machine and I need to select the correct one.to run my code without any errors. and it Worked. Thank you. – Rahul Varadkar Jul 22 '20 at 14:43
73

In some cases no "No module ..." can appear even on local files. In such cases you just need to mark appropriate directories as "source directories":

Mark as source lib directory

Ivan Talalaev
  • 5,312
  • 9
  • 36
  • 46
11

The settings are changed for PyCharm 5+.

  • Go to File > Default Settings
  • In left sidebar, click Default Project > Project Interpreter
  • At bottom of window, click + to install or - to uninstall.
  • If we click +, a new window opens where we can decrease the results by entering the package name/keyword.
  • Install the package.
  • Go to File > Invalidate caches/restart and click Invalidate and Restart to apply changes and restart PyCharm.

    Settings

    Install package

Vinay Vemula
  • 3,497
  • 1
  • 20
  • 24
5

I am using Ubuntu 16.04. For me it was the incorrect interpretor, which was by default using the virtual interpretor from project.

So, make sure you select the correct one, as the pip install will install the package to system python interpretor.

enter image description here

Vikas Goel
  • 941
  • 2
  • 15
  • 37
4

pycharm 2019.3 ,my solution is below: enter image description here

MarsYoung
  • 451
  • 1
  • 4
  • 12
1

I had virtual env site package problem and this helped me, maybe it will help you too enter image description here

0

In the case where you are able to import the module when using the CLI interpreter but not in PyCharm, make sure your project interpreter in PyCharm is set to an actual interpreter (eg. /usr/bin/python2.7) and not venv (~/PycharmProject/venv/...)

Bruce Leat
  • 11
  • 1
0

I had the same problem, I tried all fixes like installing from the project interpreter and installing from python console, nothing worked. What worked was just going to the project folder from the terminal and installing it from there.

Hakun
  • 61
  • 6