pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.53k stars 1.19k forks source link

[BUG] TypeError: expected str, bytes or os.PathLike object, not NoneType. File "<frozen os>", line 824, in fsdecode #4692

Open fridary opened 1 month ago

fridary commented 1 month ago

setuptools version

75.2.0

Python version

3.11.8

OS

Ubuntu 20.04.6 LTS

Additional environment information

Server: Intel(R) Xeon(R) CPU E5-2695 v4 @ 2.10GHz Python: 3.11.8 (conda) pip: 24.2 (latest) pandas-ta: 0.4.19b0 (latest) attributedict: 0.3.0

Description

Problem: I can not import pandas-pta lib because of error below. I created issue on official page https://github.com/twopirllc/pandas-ta/issues/831, but author said I need to ask here. Error is because of importing attributedict lib. Without it everything works.

Expected behavior

print('ok')

How to Reproduce

# Version: 0.3.0
from attributedict.collections import AttributeDict

# Version: 0.4.19b0
import pandas_ta as pta

if __name__ == "__main__":
    print('ok')

Output

Traceback (most recent call last):
  File "/home/sirjay/python/ethereum/test_pta/eth_newHeads.py", line 4, in <module>
    import pandas_ta as pta
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pandas_ta/__init__.py", line 7, in <module>
    from pandas_ta.maps import EXCHANGE_TZ, RATE, Category, Imports, version
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pandas_ta/maps.py", line 4, in <module>
    from pkg_resources import get_distribution, DistributionNotFound
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3672, in <module>
    @_call_aside
     ^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3656, in _call_aside
    f(*args, **kwargs)
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3685, in _initialize_master_working_set
    working_set = _declare_state('object', 'working_set', WorkingSet._build_master())
                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 652, in _build_master
    ws = cls()
         ^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 645, in __init__
    self.add_entry(entry)
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 701, in add_entry
    for dist in find_distributions(entry, True):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2281, in find_distributions
    importer = get_importer(path_item)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/pkgutil.py", line 416, in get_importer
    path_item = os.fsdecode(path_item)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 824, in fsdecode
TypeError: expected str, bytes or os.PathLike object, not NoneType
abravalheri commented 1 month ago

Hi @fridary, the code you highlighted iterates over sys.path, so it is indeed surprising that it is finding a None object.

Could you please double check that all the entries in sys.path are not None in your environment, before and after importing the attributedict?

fridary commented 1 month ago

@abravalheri is it what you are asking for?

Before importing attributedict:
/home/sirjay/python/ethereum
/home/sirjay/miniconda3/envs/eth/lib/python311.zip
/home/sirjay/miniconda3/envs/eth/lib/python3.11
/home/sirjay/miniconda3/envs/eth/lib/python3.11/lib-dynload
/home/sirjay/.local/lib/python3.11/site-packages
/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages

After importing attributedict:
/home/sirjay/python/ethereum
/home/sirjay/miniconda3/envs/eth/lib/python311.zip
/home/sirjay/miniconda3/envs/eth/lib/python3.11
/home/sirjay/miniconda3/envs/eth/lib/python3.11/lib-dynload
/home/sirjay/.local/lib/python3.11/site-packages
/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages
None found in sys.path!

Traceback (most recent call last):
  File "/home/sirjay/python/ethereum/test31_del.py", line 21, in <module>
    import pandas_ta as pta
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pandas_ta/__init__.py", line 7, in <module>
    from pandas_ta.maps import EXCHANGE_TZ, RATE, Category, Imports, version
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pandas_ta/maps.py", line 4, in <module>
    from pkg_resources import get_distribution, DistributionNotFound
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3672, in <module>
    @_call_aside
     ^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3656, in _call_aside
    f(*args, **kwargs)
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 3685, in _initialize_master_working_set
    working_set = _declare_state('object', 'working_set', WorkingSet._build_master())
                                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 652, in _build_master
    ws = cls()
         ^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 645, in __init__
    self.add_entry(entry)
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 701, in add_entry
    for dist in find_distributions(entry, True):
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/site-packages/pkg_resources/__init__.py", line 2281, in find_distributions
    importer = get_importer(path_item)
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sirjay/miniconda3/envs/eth/lib/python3.11/pkgutil.py", line 416, in get_importer
    path_item = os.fsdecode(path_item)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen os>", line 824, in fsdecode
TypeError: expected str, bytes or os.PathLike object, not NoneType
import sys

# Check before importing
print("Before importing attributedict:")
for path in sys.path:
    if path is None:
        print("None found in sys.path!")
    else:
        print(path)

from attributedict.collections import AttributeDict

print("\nAfter importing attributedict:")
for path in sys.path:
    if path is None:
        print("None found in sys.path!")
    else:
        print(path)

import pandas_ta as pta
abravalheri commented 1 month ago

Yes, thank you very much.

So, for some reason,attributedict (or any of its dependencies) is adding None to sys.path, which seems to be the root cause of the problem (if you remove the None entry, the code will probably work).

That does not seem quite right, does it? According to the docs, sys.path is supposed to contain a list of strings: https://docs.python.org/3/library/sys.html#sys.path , so adding None to sys.path can be considered a detective behaviour.

You should probably try contacting attributedict about that (or narrow down to one of its dependencies).