question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "Cannot create a file when that file already exists" for custom config file

See original GitHub issue

The traceback

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\Wasi Master\AppData\Roaming\Python\Python39\Scripts\ptpython.exe\__main__.py", line 7, in <module>
  File "C:\Users\Wasi Master\AppData\Roaming\Python\Python39\site-packages\ptpython\entry_points\run_ptpython.py", line 159, in run
    config_file, history_file = get_config_and_history_file(a)
  File "C:\Users\Wasi Master\AppData\Roaming\Python\Python39\site-packages\ptpython\entry_points\run_ptpython.py", line 106, in get_config_and_history_file
    pathlib.Path(d).mkdir(parents=True, exist_ok=True)
  File "C:\Program Files\Python39\lib\pathlib.py", line 1323, in mkdir
    self._accessor.mkdir(self, mode)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'C:\\Users\\Wasi Master\\AppData\\Local\\prompt_toolkit\\ptpython\\config.py'

Looking at the Path.mkdir documentation

If exist_ok is true, FileExistsError exceptions will be ignored (same behavior as the POSIX mkdir -p command), but only if the last path component is not an existing non-directory file.

But the clause “but only if the last path component is not an existing non-directory file.” is a bit confusing for me since I’m not a native English speaker. Am I doing something wrong? Thanks in advance 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
wasi-mastercommented, Apr 8, 2022

OH! this was just a mistake on my end. I accidentally ended up putting a file path instead of a folder path in my PTPYTHON_CONFIG_HOME environment variable. Sorry for wasting your time, I’m clumsy at times

0reactions
wasi-mastercommented, Apr 8, 2022

Okay, I’ll first do some debugging on my end and notify you 😃

So the config file directory is getting picked up by ptpython correctly, so that shouldn’t be a issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot create a file when that file already exists when using ...
I am trying to move the directory from one location to another location on the same drive. I am getting " ...
Read more >
"Cannot create a file when that file already exists ... - Super User
This error may occur if another service is already using a Named Pipe or RPC trigger for the same endpoint or interface as...
Read more >
[FIXED] Cannot Create a File When That File Already Exists
If you want to Get Rid of Cannot Create a File When That File Already Exists Error Issue then just Check this cannot...
Read more >
Cannot create a file when that file already exists - MSDN
Cannot create a file when that file already exists. According to the error message, it seems you don't have the permission to modify...
Read more >
Cannot create a file when that file already exists - Forum
2008-04-09 14:01:07,001 [1] INFO SettingsController - Component 'SolarWinds Custom MIB Polling Service' from 'Orion Network Performance Monitor' plugin will be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found