Home > front end >  AttributeError: module 'ntpath' has no attribute 'sep'
AttributeError: module 'ntpath' has no attribute 'sep'

Time:11-08

When I want to debug my python files which used os.path.relpath(),pycharm on my computer tells me:

collecting ... collected 0 items / 2 errors
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\main.py", line 268, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\main.py", line 321, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\main.py", line 332, in pytest_collection
INTERNALERROR>     session.perform_collect()
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\main.py", line 644, in perform_collect
INTERNALERROR>     self.ihook.pytest_collectreport(report=rep)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_hooks.py", line 265, in __call__
INTERNALERROR>     return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\pluggy\_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 328, in pytest_collectreport
INTERNALERROR>     self.report_test_failure(test_id, report)
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 223, in report_test_failure
INTERNALERROR>     self.ensure_test_start_reported(test_id)
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\teamcity\pytest_plugin.py", line 186, in ensure_test_start_reported
INTERNALERROR>     self.teamcity.testStarted(test_id, flowId=test_id, captureStandardOutput=capture_standard_output, metainfo=metainfo)
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\_jb_runner_tools.py", line 181, in testStarted
INTERNALERROR>     commands = _TREE_MANAGER_HOLDER.manager.level_opened(self._test_to_list(testName), _write_start_message)
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\_jb_runner_tools.py", line 51, in manager
INTERNALERROR>     self._fill_manager()
INTERNALERROR>   File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.2.3\plugins\python-ce\helpers\pycharm\_jb_runner_tools.py", line 59, in _fill_manager
INTERNALERROR>     from _jb_serial_tree_manager import SerialTreeManager
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 1002, in _find_and_load_unlocked
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 945, in _find_spec
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\assertion\rewrite.py", line 92, in find_spec
INTERNALERROR>     if self._early_rewrite_bailout(name, state):
INTERNALERROR>   File "C:\ProgramData\Anaconda3\envs\my2ndconda\lib\site-packages\_pytest\assertion\rewrite.py", line 193, in _early_rewrite_bailout
INTERNALERROR>     path = PurePath(os.path.sep.join(parts)   ".py")
INTERNALERROR> AttributeError: module 'ntpath' has no attribute 'sep'

My version of Python is 3.10.6, pytest's version is 7.1.2, and version of Windows is Windows 11 22H2 22621.674. How to solve the problem?


Now I discovered this is because of conda environment, but conda list of the environment is so long and not fit to place here, please see this link:

https://pastebin.ubuntu.com/p/9H8FNfjX3c/

CodePudding user response:

I changed python interpreter to python venv and updated conda's version, and the problem disappeared.

  • Related