ChatGPT解决这个技术问题 Extra ChatGPT

ImportError: No module named 'bottle' - PyCharm

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'"

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?
actually, I think I need to set the PYTHONPATH, any idea how can i do that?
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.
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?
I solved it, just like in the picture. Thanks anyway! :)

T
Thomasleveil

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


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.
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?
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.
"Project Interpreter" is now under Settings > Project: [your project] > Project Interpreter. Or alternatively just use the search feature with Ctrl + Shift + A.
How can I do this for a locally developed module?
I
Ivan Talalaev

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


V
Vinay Vemula

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


V
Vikas Goel

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


M
MarsYoung

https://i.stack.imgur.com/KlW2o.png


i
ibrahim mert

https://i.stack.imgur.com/do7Vh.png


B
Bruce Leat

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


H
Hakun

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.