ImportError: No module named 'bottle' in PyCharm

Question:

I installed bottle on Python 3.4 with pip install. In the 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’

Asked By: Tinno TL

||

Answers:

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

Answered By: Thomasleveil

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:

Settings

Install package:

Install package

Answered By: Vinay Vemula

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

Answered By: Ivan Talalaev

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

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

IDE settings

Answered By: Vikas Goel

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/…)

Answered By: Bruce Leat

PyCharm 2019.3, my solution is below:

enter image description here

Answered By: MarsYoung

I had virtual env site package problem and this solved it:

enter image description here

Answered By: ibrahim mert

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.

Answered By: Hakun

For me, none of the above worked, and curiously even within one file some imports worked, some didn’t:

from folder1.folder2.folder3.my_python_file import this_function  # worked
from folder1.folder2.folder3.my_python_file import that_function  # didn't work

Follow the above advice, but if it doesn’t fix it additionally, (in PyCharm) click File >> Repair IDE and confirm all the 6 steps one after another.

Answered By: safex
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.