简体   繁体   中英

AttributeError: module 'pandas' has no attribute '__version__'

Please note, this is not a duplicate question. I'm aware of how to find versions of libraries in python. What's caught my goat is the apparent anomaly when the __version__ command is called in two different ways.

Has anyone faced this before? When I type the following in IDLE, I get the output which specifies the pandas version.

>>>import pandas as pd
>>>print(pd.__version__)
0.22.0

When I put the same two lines of code into a program, save it and run it, I get the following error:

AttributeError: module 'pandas' has no attribute '__version__'

It does not make any sense to me. Appreciate any thoughts on this please.

It sounds like you're not importing the real pandas module when you run your script from a file. When I run your script in a file on my machine it prints the pandas version correctly.

Maybe you have a file called pandas.py or a directory called pandas in your current working directory when you run the script? Or maybe there is a pandas.py or a pandas directory in a directory in your PYTHONPATH environment variable? (Other than the real pandas, that is.) Try running this program and see if the output looks like the proper pandas source file, or something else.

import pandas as pd
print(pd.__file__)

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