简体   繁体   中英

How can I tell if I have successfully imported a package for python (e.g. Pandas) in VS code?

I am using VS code, I am trying to do a project using Jupyter notebook on VS code. I tried typing [import pandas as pd] after installing pandas using pip. I pressed the run button and nothing visible changed except the bracket for the cell turning to 1. [-] -> [1]

How can I know if this import was successful?

Edit: Ok I understand how to tell now, Thank You everyone!

if you use

import pandas as pd 

if it runs without ModuleNotFoundError: No module named 'pandas' it should be working.

Generally speaking, you do not have to worry much about this issue, no output means you have imported a module successfully or it will give some err like ModuleNotFoundError .

If you want to confirm this, there are 2 ways I can provide:

  1. just try to use this module, for example
pd.__version__

if it gives a version number and doesn't report any err, you success.

  1. execute
import sys
sys.module.keys()

and if pandas is in the output list, it has been imported.

you can use an example to test if it works, try this

dates = pd.date_range('20130101', periods=6)
print(dates)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM