0

I dont know why but today I am unable to import pandas to my project.

import pandas as pd
import tkinter.filedialog
import os


xlfile = tkinter.filedialog.askopenfilenames(filetypes=[("Excel files", ".xlsx .xls")],
                                                      title='Select Amazon order file')
df_orders = pd.read_excel(xlfile, header=None)
print(df_orders)

It gives me a traceback

Traceback (most recent call last):
  File "C:\Users\...\testtestt.py", line 4, in <module>
    import pandas as pd
  File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\__init__.py", line 186, in <module>
    __version__ = v.get("closest-tag", v["version"])
AttributeError: 'NoneType' object has no attribute 'get'

This is a small extract from pandas\__init__.py in my system, where the error occurs

from pandas.io.json import _json_normalize as json_normalize

from pandas.util._tester import test
import pandas.testing
import pandas.arrays

# use the closest tagged version if possible
from ._version import get_versions

v = get_versions()
__version__ = v.get("closest-tag", v["version"])
__git_version__ = v.get("full-revisionid")
del get_versions, v

I tried uninstalling pandas and reinstalling it. But no use. Why do I get AttributeError: 'NoneType' object has no attribute 'something'? I guess this is a similar problem. But that doesn't give the solution to my error.

Derik002
  • 145
  • 13
  • I don't know why it's doing that, since the `get_versions()` method always returns something or the other ( [here's the source](https://github.com/pandas-dev/pandas/blob/6925fd04690c94dc1fc03db1e1eddac8d479bef6/pandas/_version.py#L511) ) – Novus Edge May 31 '21 at 09:25
  • I would recommend mentioning this as an issue over on the [repo](https://github.com/pandas-dev/pandas) – Novus Edge May 31 '21 at 09:26
  • You can also try and downgrade to an older pandas version and see if that works – Novus Edge May 31 '21 at 09:26
  • Is is possible that you use a virtual environment of sorts that has not been activated? – Paul P May 31 '21 at 10:09
  • Looks at the parts of the traceback message which you haven't posted here. It will tell you where your script look for the `pandas` library and give you clues as to what the problem is. It's not related to the question you linked in any meaningful way. If you're using a virtual environment the traceback should point there or if you have multiple installations of Python it should be point to the one you're using to run your script. Check your path variables etc. to save time open a terminal, launch python and type `import pandas`. That's the only part of your code you need to fix. – Jason May 31 '21 at 13:19
  • @p3j4p5 I think it has to do something with the virtual environment. What should I do about that? to fix this error? I don't get much idea about the virtual environment. – Derik002 May 31 '21 at 18:57
  • @Jason ```>>> import pandas Traceback (most recent call last): File "", line 1, in File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\__init__.py", line 186, in __version__ = v.get("closest-tag", v["version"]) AttributeError: 'NoneType' object has no attribute 'get'``` I tried in cmd and got this. – Derik002 May 31 '21 at 19:02
  • Do you have a file `_version.py` in the same folder as `__init__.py`? Its contents should be version information as `.json`. Your error is telling that `pandas` initiation method is returning nothing when I checks your version of `pandas`. It then tries to get information from this empty object and throws an error. Somehow your installations of `pandas` is wonky. The easiest way to fix this would be to use `pip install --force-reinstall --no-cache-dir` (run from your activated `venv` if you're using one). – Jason May 31 '21 at 19:25
  • Regarding the virtual environment, I would start with reading the [documentation](https://docs.python.org/3/library/venv.html#creating-virtual-environments) on it. It's possible you already have one, so you need to look for a directory called `venv` (or similar) and then run the commands specified in the documentation to activate it. – Paul P May 31 '21 at 20:17
  • @p3j4p5 It's unclear whether OP is using a virtual environment or not as they haven't provided these details. If they are using a virtual environment they might not be using the `venv` module in which case creating and using a virtual environment through the `venv` module would serve to confuse OP further (if they're using `conda` for instance). – Jason Jun 01 '21 at 09:55
  • I still couldn't fix this. idk what is wrong. I'm using Pycharm to write scripts and at the beginning of creating a project, it asks me to use a new environment using 'Virtualenv' or use 'Pipenv'. I tried both and still getting this traceback. I tried importing pandas onto cmd still getting the same error. – Derik002 Jun 02 '21 at 11:01

0 Answers0