3

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.

5
  • 2
    Try pd.__version__. Commented Apr 9, 2018 at 11:30
  • 4
    Don't name your file pandas.py Commented Apr 9, 2018 at 11:43
  • Hi Burhan, The file isn't named pandas.py. I've given it some random file name. Commented Apr 9, 2018 at 11:48
  • jpp - I get the same error when i run it without the print command like you mentioned. Commented Apr 9, 2018 at 11:52
  • using pd.__version__ worked in version 0.25.1 Commented Apr 5, 2021 at 23:00

1 Answer 1

6

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__)
Sign up to request clarification or add additional context in comments.

2 Comments

In my case: pd.__file__ is located at anaconda3/lib/python3.7/site-packages/pandas/__init__.py and yet I have this error
@wander95 I recommend posting a new question with the details of your situation; what version of Pandas you have, what version of Anaconda you have, what Python script you are trying to run, and the method or command you use to invoke that script.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.