使用时出现错误"没有此类文件或目录"单击



我使用点击8.1.3来解析我的命令,我的cli.py是这样的:

@click.option('--output_dir', default=os.curdir, help='when outdated is true,choose directory which you want to put your cache file')
@click.option('--cache_dir', default=os.curdir, help='when outdated if false,choose directory where put cache file')
def main(outdated, nodes_path, river_path, cur_sta, up_sta, cutoff, upstream, downstream, cache_dir, output_dir):
……

但当我试图从C:UsersUserNameDesktoptest-cache这样的目录中读取缓存文件时,出现了错误:

PS C:UsersUserNameDesktoptest_cache2> calcstream --nodes_path XXX --river_path YYY --cur_sta 0 --up_sta 10 --cache_dir C:UsersUserNameDesktoptest-cache --outdated False
Traceback (most recent call last):
File "C:Python310librunpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:Python310librunpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:Python310Scriptscalcstream.exe__main__.py", line 7, in <module>
File "C:Python310libsite-packagesclickcore.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "C:Python310libsite-packagesclickcore.py", line 1055, in main
rv = self.invoke(ctx)
File "C:Python310libsite-packagesclickcore.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:Python310libsite-packagesclickcore.py", line 760, in invoke
return __callback(*args, **kwargs)
File "C:Python310libsite-packagesdijkstra_condacli.py", line 35, in main
upstream_node_on_mainstream(nodes_reader, network_reader, cur_sta, up_sta, outdated, cache_dir, output_dir)
File "C:Python310libsite-packagesdijkstra_condadfs_path_test.py", line 463, in upstream_node_on_mainstream
origin_graph = get_upstream_stations_graph(node_reader, network_reader, number_src, outdated)[2]
File "C:Python310libsite-packagesdijkstra_condadfs_path_test.py", line 348, in get_upstream_stations_graph
upstream_graph = get_upstream_stations(node_reader, network_reader, number, outdated, cutoff, cache_dir, output_path)[0]
File "C:Python310libsite-packagesdijkstra_condadfs_path_test.py", line 243, in get_upstream_stations
stations_graph = build_graph(node_reader, network_reader, outdated, cache_dir, output_path)
File "C:Python310libsite-packagesdijkstra_condadfs_path_test.py", line 205, in build_graph
nearest_point_line_dict = tie_outside_node(node_reader, network_reader, outdated, cache_dir, output_path)[1]
File "C:Python310libsite-packagesdijkstra_condadfs_path_test.py", line 115, in tie_outside_node
source_point_frame = pd.read_csv(os.path.join(cache_dir, 'source_project_points.csv'))
File "C:Python310libsite-packagespandasutil_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "C:Python310libsite-packagespandasutil_decorators.py", line 317, in wrapper
return func(*args, **kwargs)
File "C:Python310libsite-packagespandasioparsersreaders.py", line 950, in read_csv
return _read(filepath_or_buffer, kwds)
File "C:Python310libsite-packagespandasioparsersreaders.py", line 605, in _read
parser = TextFileReader(filepath_or_buffer, **kwds)
File "C:Python310libsite-packagespandasioparsersreaders.py", line 1442, in __init__
self._engine = self._make_engine(f, self.engine)
File "C:Python310libsite-packagespandasioparsersreaders.py", line 1729, in _make_engine
self.handles = get_handle(
File "C:Python310libsite-packagespandasiocommon.py", line 857, in get_handle
handle = open(
FileNotFoundError: [Errno 2] No such file or directory: '.\source_project_points.csv'

程序似乎仍然使用os.curdir(C:\Users\UserName\Desktop\test_cache2(来查找source_project_points.csv,我确信source_project_points.csvC:UsersUserNameDesktoptest-cache中,那么如何解决问题呢?

这是我的项目链接。

现在我知道了,不应该在业务代码中设置默认参数,而应该用@click.option(default=)编写。

相关内容

  • 没有找到相关文章

最新更新