Ashkan-TBZ
Ashkan-TBZ

Reputation: 17

Why does python give me an error when i am importing modules?

I have installed today Python 3.8.1 (i had 3.7.* months ago, but don´t use it anymore) and I tried to write new code, but I have problems to import modules like matplotlib and so on. It will always mark the module name yellow and says:

unresolved import ‘matplotlib' Python(unresolved-import)

I checked if python is in the PATH included, I installed/reinstalled the matplotlib module but nothing works. I am using Win 10 64Bit, Python 3.8.1 64Bit and VS Code.

Upvotes: 1

Views: 261

Answers (3)

Vijayant
Vijayant

Reputation: 30

You may also use the following command in cmd in admin mode:

python -m pip install matplotlib

if you are running it on the command prompt after installing the python.

Upvotes: 0

Ashkan-TBZ
Ashkan-TBZ

Reputation: 17

I solved the problem by uninstalling python and deleting all existing files from python and installing a new clean version of the newest version of python. After this i used pip to install all required modules to code.

Thanks for the help!

Upvotes: 0

Amit
Amit

Reputation: 266

Best way to do that is in a virtualenv, have a look at this.

python3.8 -m venv env-name # this will create a folder with executables of python, pip.

To activate it you can run

source env-name/bin/activate # Linux/Mac
env\Scripts\activate.bat # For windows
pip install matplotlib # Matplotlib will be installed for the activated env only

Upvotes: 1

Related Questions