X in this example represents any module or package you install.
The problem:
I have a problem with a package called 'X'.
In PyCharm I get an error ImportError: No module named 'X'.
My code runs from the terminal without any problem. Any help ?
or
I installed X on python3.4 with pip. In terminal, when I import X, everything is fine, but when I import it in PyCharm, it says: ImportError: No module named 'X'"
. Any help ?
This is basically everyday question, just with different module or a package instead name instead of X.
And it's not problem in a package or module you install, it's in a PyCharm Project Interpreter you are currently using for your project.
The following answer is usually solution to this specific problem.
SHORTER VERSION:
If you have squiggly line below module you import...
...move on name of module and press Alt+Enter and select Install package X
.
This should (probably !!!) install module you thought you installed, but got ImportError
.
LONGER:
If you want to use module X:
Go to File -> Settings -> Project:NameOfProject -> Project Interpreter
.
The window that opens has some specific regions:
Add...
when gear icon is clicked, and make sure to set proper path to python.exe
of your virtual environment.ImportError no module named 'X'
, make sure to check if package is listed here!!!. If not, it's not installed in the current python environment and it should be installed (continue reading).A little + represents Install
. It can be used to install packages. Simply click on + sign, search for a package and click Install Package
at the bottom after you found it. You can also specify the version you want of a package. In example below, we searched for flask
package.
A package should be installed and listed now in installed packages.