kuanb / peartree

peartree: A library for converting transit data into a directed graph for sketch network analysis.
MIT License
201 stars 23 forks source link

ImportError: cannot import name '_cchardet' from partially initialized module 'cchardet' & AttributeError: module 'peartree' has no attribute 'get_representative_feed' #161

Closed huibuhui closed 3 years ago

huibuhui commented 4 years ago

Hi, Thank you very much for your fantastic work! I've got the following error message when importing peartree. I apologize if this has nothing to do with peartree but I can't find other examples to solve such issues.
I've also uninstalled and reinstalled all the versions of peartree and partridge. I use Python 3.8.5 on Windows and here is my code.


import sys sys.path.append("C:/Users/a/Anaconda/lib/site-packages/") import peartree as pt

  1. SITUATION 1. When the peartree versions are from 0.4.5 to 0.6.3 and the partridge version =1.1.1, I got the following error message

`ImportError Traceback (most recent call last)

in 1 import sys 2 sys.path.append("C:/Users/a/Anaconda/lib/site-packages/") ----> 3 import peartree as pt #try install and uninstall 0.4.4 or all version, uninstall and then reinstall 0.6.3 4 print(pt.__version__) C:/Users/a/Anaconda/lib/site-packages\peartree\__init__.py in 3 4 from peartree.__version__ import __version__ # noqa: F401 ----> 5 from peartree.paths import ( 6 load_feed_as_graph, 7 get_representative_feed, C:/Users/a/Anaconda/lib/site-packages\peartree\paths.py in 3 import networkx as nx 4 import numpy as np ----> 5 import partridge as ptg 6 7 from .graph import (generate_empty_md_graph, generate_summary_graph_elements, C:/Users/a/Anaconda/lib/site-packages\partridge\__init__.py in 1 from .__version__ import __version__ ----> 2 from .readers import ( 3 load_feed, 4 load_raw_feed, 5 read_busiest_date, C:/Users/a/Anaconda/lib/site-packages\partridge\readers.py in 11 12 from .config import default_config, empty_config, reroot_graph ---> 13 from .gtfs import Feed 14 from .parsers import vparse_date 15 from .types import View C:/Users/a/Anaconda/lib/site-packages\partridge\gtfs.py in 9 from .config import default_config 10 from .types import View ---> 11 from .utilities import detect_encoding, empty_df, setwrap 12 13 C:/Users/a/Anaconda/lib/site-packages\partridge\utilities.py in 1 from typing import Any, Dict, Iterable, Optional, Set, BinaryIO, Union 2 ----> 3 from cchardet import UniversalDetector 4 import networkx as nx 5 import numpy as np C:/Users/a/Anaconda/lib/site-packages\cchardet\__init__.py in ----> 1 from cchardet import _cchardet 2 from .version import __version__ 3 4 5 def detect(msg): **ImportError: cannot import name '_cchardet' from partially initialized module 'cchardet' (most likely due to a circular import) (C:/Users/a/Anaconda/lib/site-packages\cchardet\__init__.py)`** --------------------------------------------------------------------------- 2. SITUATION 2. When peartree == 0.4.4 and the partridge version =1.1.1, the error message is different: `ImportError Traceback (most recent call last) in 1 import sys 2 sys.path.append("C:/Users/a/Anaconda/lib/site-packages/") ----> 3 import peartree as pt #try install and uninstall 0.4.4 or all version, uninstall and then reinstall 0.6.3 4 print(pt.__version__) C:/Users/a/Anaconda/lib/site-packages\peartree\__init__.py in 1 from peartree.__version__ import __version__ # noqa: F401 ----> 2 from peartree.paths import ( 3 load_feed_as_graph, 4 get_representative_feed, 5 load_synthetic_network_as_graph) # noqa: F401 C:/Users/a/Anaconda/lib/site-packages\peartree\paths.py in 4 import partridge as ptg 5 ----> 6 from .graph import (generate_empty_md_graph, generate_summary_graph_elements, 7 make_synthetic_system_network, populate_graph) 8 from .toolkit import generate_random_name C:/Users/a/Anaconda/lib/site-packages\peartree\graph.py in 8 9 from .settings import WGS84 ---> 10 from .summarizer import (generate_edge_and_wait_values, 11 generate_summary_edge_costs, 12 generate_summary_wait_times) C:/Users/a/Anaconda/lib/site-packages\peartree\summarizer.py in 7 import partridge as ptg 8 ----> 9 from .parallel import RouteProcessor, make_new_route_processor_manager 10 from .toolkit import nan_helper 11 from .utilities import log **ImportError: cannot import name 'make_new_route_processor_manager' from 'peartree.parallel' (C:/Users/a/Anaconda/lib/site-packages\peartree\parallel.py)`** --------------------------------------------------------------------------- 3. SITUATION 3. If I uninstall peartree == 0.4.4 and reinstall peartree ==0.6.3 and the partridge version =1.1.1,, the error message is: `AttributeError Traceback (most recent call last) in 1 import sys 2 sys.path.append("C:/Users/a/Anaconda/lib/site-packages/") ----> 3 import peartree as pt #try install and uninstall 0.4.4 or all version, uninstall and then reinstall 0.6.3 4 print(pt.__version__) C:/Users/a/Anaconda/lib/site-packages\peartree\__init__.py in 3 4 from peartree.__version__ import __version__ # noqa: F401 ----> 5 from peartree.paths import ( 6 load_feed_as_graph, 7 get_representative_feed, C:/Users/a/Anaconda/lib/site-packages\peartree\paths.py in 5 import partridge as ptg 6 ----> 7 from .graph import (generate_empty_md_graph, generate_summary_graph_elements, 8 make_synthetic_system_network, populate_graph) 9 from .synthetic import SyntheticTransitNetwork C:/Users/a/Anaconda/lib/site-packages\peartree\graph.py in 7 8 from .settings import WGS84 ----> 9 from .summarizer import (generate_edge_and_wait_values, 10 generate_summary_edge_costs, 11 generate_summary_wait_times, C:/Users/a/Anaconda/lib/site-packages\peartree\summarizer.py in 420 421 def generate_edge_and_wait_values( --> 422 feed: ptg.gtfs.Feed, 423 target_time_start: int, 424 target_time_end: int, **AttributeError: module 'partridge.gtfs' has no attribute 'Feed'`** --------------------------------------------------------------------------- 4. SITUATION 4. So I tried to install another version of partridge ==1.0.0. This time peartree=0.6.3. The above "import error" is gone. It looks like "peartree=0.6.3" & partridge ==1.0.0 is a good combination. But then when I start to the analysis and run the following code: `path = 'C:/Users/a/data/gtfsfeed_zips/ac transit.zip' feed = pt.get_representative_feed(path)` I got the following message: `AttributeError Traceback (most recent call last) in 1 path = 'C:/Users/a/data/trimmed_gtfs_feed.zip' ----> 2 feed = pt.get_representative_feed(path) **AttributeError: module 'peartree' has no attribute 'get_representative_feed'`** --------------------------------------------------------------------------- At this stage, I no longer know what else to try. I would appreciate for any feedback or comment. Best, Hsiao-Hui
huibuhui commented 4 years ago

Problem solved after removing from cchardet import _cchardetin the file: "C:\Users\a\Anaconda\Lib\site-packages\cchardet/ini.py"

kuanb commented 3 years ago

Sorry for the delay and thanks for the update @huibuhui - looks like your issue was resolved, so closing this issue.