JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
559 stars 76 forks source link

Permission Error access Denied #17

Open finepointcgi opened 5 years ago

finepointcgi commented 5 years ago

Im running into a issue with opening up an addon im upgrading. I run blender run and it wont run in blender even when I run VS code as admin. Here is my log.

Executing task: c:\Users\fp\Downloads\blender-2.80-ea33b90a1bf-win64\blender-2.80.0-git.ea33b90a1bf-windows64\blender.exe --python C:\Users\fp.vscode\extensions\jacqueslucke.blender-development-0.0.10\pythonFiles\launch.py <

found bundled python: c:\Users\fp\Downloads\blender-2.80-ea33b90a1bf-win64\blender-2.80.0-git.ea33b90a1bf-windows64\2.80\python
Traceback (most recent call last):
File "C:\Users\fp\.vscode\extensions\jacqueslucke.blender-development-0.0.10\pythonFiles\launch.py", line 16, in <module>
allow_modify_external_python=os.environ['ALLOW_MODIFY_EXTERNAL_PYTHON'] == "yes",
File "C:\Users\fp\.vscode\extensions\jacqueslucke.blender-development-0.0.10\pythonFiles\include\blender_vscode\__init__.py", line 14, in startup
path_mappings = load_addons.setup_addon_links(addon_paths)
File "C:\Users\fp\.vscode\extensions\jacqueslucke.blender-development-0.0.10\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\fp\.vscode\extensions\jacqueslucke.blender-development-0.0.10\pythonFiles\include\blender_vscode\load_addons.py", line 39, in create_link_in_user_addon_directory
os.remove(link_path)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\fp\\AppData\\Roaming\\Blender Foundation\\Blender\\2.80\\scripts\\addons\\MB-Lab-master'
Saved session recovery to 'C:\Users\fp\AppData\Local\Temp\quit.blend'
Lynchon83 commented 5 years ago

I had the same problem, try to remove your addon from blender before launching blender from vscode.

ppinter1 commented 4 years ago

Oh, ffs!

I wasted hours on this before finding your post. Well spotted... thank you!

beqjanus commented 2 years ago

The underlying issue here is arguably not a problem with the vscode addon but with the Blender upgrade process. Whenever you instal a new version the options to bring over your existing settings is offered and most of us tend to accept that. As @Lynchon83 notes above, removing your VSCode managed blender addons before doing the upgrade circumvents the issue but this is side-stepping the underlying issue.

When you add an addon using the VSCode addon, a link is created in the %AppData%\Bledner Foundation\Blender\\scripts\addons folder. You can see this in the folder view of an explorer window (here showing my addon SLender alongside speedflow) image

During an upgrade this "link" is not maintained, instead a deep copy is made and when the addon tries to alter this things go pear-shaped.

Workarounds are: 1) remove the addons you are developing before upgrading (as above) 2) remove the folders that were copied over after the upgrade and then re-install the addon through vscode

I have added a task to the blender dev site, though whether the impact of this (just those of us using this extension) justifies the effort to change Blender upgrade behaviour is questionable, I figured it was worth raising in case there are other use cases where this might cause issues. https://developer.blender.org/T95208

It is interesting that @JacquesLucke used the _winapi.CreateJunctionPoint API call rather than a symlink, not sure that this would make any difference or whether there are other side effects if I were to change that and make a PR.

EvanAW commented 2 years ago

@beqjanus https://github.com/JacquesLucke/blender_vscode/pull/55 might give you some hints on how to go about solving this issue.

beqjanus commented 2 years ago

Thanks @EvanAW , my blender bug report was closed as "not a bug" which is probably fair though arguable as to whether silently converting lnks to copies is "expected behaviour". In any case, trying to fix it here is going to be the better direction.

The atexit() handler idea is ok but I agree with @JacquesLucke that (for my workflow) I'd like the links to persist., so perhaps making that optional. A vscode setting that makes link retention/removal a user preference.

One option for this bug is to improve the error reporting. It doesn't fix it but helps people solve the problem themselves.

kents00 commented 9 months ago

When creating your own addon, it is important to ensure that you do not include the .git file during installation. I discovered this while tracing my own addon and found that including the .git file can cause errors when attempting to remove your addon. If you encounter any issues with removal, you can also try launching Blender in administrator mode.

Mateusz-Grzelinski commented 1 week ago

Part of the issues related to Permission error were addressed in version [0.0.22] - 2024-09-04, but some corner cases are still worked in in #184 - but the design is not obvious and fixing all corner cases required changing default behavior.