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'"
python3.4
that you use from the terminal? Have you set up a virtualenv or venv or user site-packages or PYTHONPATH
?
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.
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?
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
https://i.stack.imgur.com/tJeqK.png
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":
https://i.imgur.com/qaZchts.png
https://i.imgur.com/imkzUJr.png
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
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.
https://i.stack.imgur.com/dnbKj.png
https://i.stack.imgur.com/KlW2o.png
https://i.stack.imgur.com/do7Vh.png
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/...)
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.
Success story sharing
+
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.