zachary cohen
zachary cohen

Reputation: 65

Can't import modules in python after installing them with pip

I am trying to use the pyserial module in my python project, so i installed it with pip install pyserial. After doing that, I did import pyserial in my python interpreter and it gave me this error:

error

Pyserial appears in my pip list list, and when i do pip show pyserial it gives this result:

pip list

Upvotes: 2

Views: 4396

Answers (3)

WaLid LamRaoui
WaLid LamRaoui

Reputation: 2455

I think you're using a wrong import statement, import pyserial will give you and should give you the above error .

The correct import statement is import serial, so try this instead.

Always it's a good thing to read the documentation, you can read more about pyserial on the docs here

Upvotes: 3

12944qwerty
12944qwerty

Reputation: 1925

Pycharm has a different way to install packages. You shouldn't install them via pip. I'm not sure why pip doesn't always install packages properly is though.

Instead, you can install it by opening the tool page in the main menu. This is available for PyCharm 2021.1 and later.

View -> Tool Windows -> Python Packages -> Search

You can also open the project interpreter to install packages.

Settings (CTRL+ALT+S) -> Project_Name -> Python Interpreter -> + (symbol at bottom) -> Search

See this article for a more complete tutorial.

Upvotes: 2

zachary cohen
zachary cohen

Reputation: 65

I fixed this problem in PyCharm by typing import serial and it gave me an option to auto-install it. I took that option, and it worked.

Upvotes: 1

Related Questions