blender_vscode icon indicating copy to clipboard operation
blender_vscode copied to clipboard

[WinError 183] Cannot create a file when that file already exists

Open Teriander opened this issue 5 years ago • 6 comments

I'm having the same issue that was previously discussed, but the solution was very vague or non-existent. I have no idea how to solve this. I receive the following error when trying to run "Blender: Start", which results in an instant crash of Blender. Blender loads for 2 seconds, then crashes.

Executing task in folder Blender: d:\Program Files\Blender Foundation\Blender\blender.exe --python C:\Users\efelder\.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\launch.py 

Read prefs: C:\Users\efelder\AppData\Roaming\Blender Foundation\Blender\2.80\config\userpref.blend
found bundled python: d:\Program Files\Blender Foundation\Blender\2.80\python
archipack: ready
Traceback (most recent call last):
 File "d:\Program Files\Blender Foundation\Blender\2.80\scripts\modules\addon_utils.py", line 351, in enable
   mod = __import__(module_name)
ModuleNotFoundError: No module named 'Blender'
[{'load_dir': 'd:\\Program Files\\PythonProjects\\PythonProjects\\Blender', 'module_name': 'Blender'}, {'load_dir': 'd:\\Program Files\\PythonProjects\\PythonProjects\\TestAddon', 'module_name': 'TestAddon'}]
Traceback (most recent call last):
 File "C:\Users\efelder\.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\launch.py", line 18, in <module>
   allow_modify_external_python=os.environ['ALLOW_MODIFY_EXTERNAL_PYTHON'] == "yes",
 File "C:\Users\efelder\.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\include\blender_vscode\__init__.py", line 14, in startup
   path_mappings = load_addons.setup_addon_links(addons_to_load)
 File "C:\Users\efelder\.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\include\blender_vscode\load_addons.py", line 20, in setup_addon_links
   create_link_in_user_addon_directory(source_path, load_path)
 File "C:\Users\efelder\.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\include\blender_vscode\load_addons.py", line 43, in create_link_in_user_addon_directory
   _winapi.CreateJunction(str(directory), str(link_path))
FileExistsError: [WinError 183] Cannot create a file when that file already exists
Saved session recovery to 'C:\Users\efelder\AppData\Local\Temp\quit.blend' 

If the solution is to delete a file that already exist, well that's great. Which file and where??

Teriander avatar Aug 13 '19 17:08 Teriander

Ok, so I figured it out.

...\AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons

Remove the folder with your project name that already exist here (if its there). This should be considered a bug, because it breaks the launch of Blender from VSCode, and that shouldn't happen.

Teriander avatar Aug 13 '19 20:08 Teriander

What would your preferred behavior be? The exception could be caught and handled, but your best case scenario is that blender will continue loading and an older version of your addon will get loaded (likely unnoticed).

possible solutions:

  • assuming elevated privledges, create_link_in_user_addon_directory could delete the folder for you and then create the symbolic link without you knowing anything happened. but do you really want a python script deleting things for you?
  • handle the exception, output a warning that will largely be ignored because it'll be buried in startup log output, and people will inevitably wonder why the changes they're making in vscode aren't showing up in Blender
  • ???

By the way, the load_addons module is pretty straightforward- if you have ideas on how to solve the problem I'm sure Jackques would welcome the pull request.

eldeesmith avatar Aug 15 '19 05:08 eldeesmith

Eldeesmith,

A simple solution would be a print in the error of the location of the problem folder. Not sure how difficult that would be. But considering I'm not the first person to have this problem since an identical post was created, it would make sense to provide more detail of the problem.

Currently we're just notified Cannot create a file when that file already exists , without any reference to what file and where. But I agree, having Python delete the folder automatically probably isn't ideal. But at least it could indicate what file and folder is the problem.

Teriander avatar Aug 15 '19 05:08 Teriander

Sure, not hard to do- though I think it will actually cause more problems than it solves because the importance of the error gets buried and blender is allowed to continue loading. Try it for yourself:

replace function with the same name in load_addons.py, located in %userprofile%.vscode\extensions\jacqueslucke.blender-development-0.0.12\pythonFiles\include\blender_vscode\

def create_link_in_user_addon_directory(directory, link_path):
	 if os.path.exists(link_path):
		try:
			os.remove(link_path)
		except PermissionError as ex:
			print (f"ERROR: Could not remove path {link_path} due to insufficient priveledges.\n{ex}")

	if sys.platform == "win32":
		import _winapi
		try:
			_winapi.CreateJunction(str(directory), str(link_path))
		except FileExistsError as ex:
			print (f"ERROR: Could not create a symbolic link to {link_path} because {directory} already exists! Delete it and try again!\n{ex}")
	else:
		os.symlink(str(directory), str(link_path), target_is_directory=True)

eldeesmith avatar Aug 15 '19 05:08 eldeesmith

This issue triggered when I had relocated my workspace folder. So if the folder name already exist previously, it will not execute blender and give the warning.

Perhaps the most simplest solution could be a note on the extensions details page that simply states "If you receive a [WinError 183] error, delete the folder with your workspace name at \AppData\Roaming\Blender Foundation\Blender\2.80\scripts\addons"

If the error is not avoidable through back-end programming.

Teriander avatar Aug 15 '19 14:08 Teriander