I can't import the installed external library.

Asked 2 years ago, Updated 2 years ago, 51 views

I wanted to read and process csv in Python and do something like analysis.
I installed Python 3.7 and pycharm.

I read in the article that the loading of csv is pandas, so I tried to import it with pandas first, but I couldn't... Specifically, below.

When I ran pip show pandas at the terminal, the following came out, so I think it was installed.

Name:pandas
Version—0.25.1
Summary—Powerful data structures for data analysis, time series, and statistics
Home-page: http://pandas.pydata.org
Author—None
Author-email: None
license:BSD
Location: /Users/user/anaconda3/lib/python 3.7/site-packages
Requirements: numpy, python-dateutil, pytz
Required-by —Seaborn

However, typing import pandas as pd in Python returns the following error:

ModuleNotFoundError: No module named 'pandas'

I have a similar question, but I couldn't solve it.

python python3 pandas

2022-09-29 22:35

3 Answers

I thought of a procedure to investigate the cause.Please try it if you like.

(1) Add the following code to the script to examine the contents of sys.path:

import sys
print(sys.path)

(2) Check if the displayed content contains the pathname of the pandas, and
 If not, add the following code to see if the symptom is reproduced:

sys.path.append("pandas path")

(2) If the symptom does not reproduce, add the path of the pandas to the configuration file and it should be OK.
 ※ The configuration file is tool dependent and cannot be specifically answered.


2022-09-29 22:35

Below is anaconda.
(Excerpt) Location: /Users/user/anaconda3/lib/python 3.7/site-packages
Also, Pycharm.
I think it is quite complicated.
If it's anaconda, it's anaconda, and if it's Pycharm, it's only Pycharm. I think it's safe.
Module management tools such as pip and conda do a lot of things.
I think it's hard to tell where and what's installed and where it's enabled.

Until you get used to it,
I think it's better to ride only in one environment.


2022-09-29 22:35

I don't know for sure, but it may be because I used python, which was originally included in pycharm.
If you have installed pycharm and python separately, I think it would be okay if you could make the installed python available in pycharm.

How do I change it?

File->Setting->Project Interpreter

Open to and press the gear mark on the right to select Add.
Open the ... mark next to the base interpreter and specify the path of the python you installed.

If the change is troublesome, press the ten marks next to the Project interpreter screen and type Pandas on the form, so you can install the pycharm on the existing python by selecting the package you want and pressing install package.


2022-09-29 22:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.