JacquesLucke / blender_vscode

Visual Studio Code extension for Blender development.
MIT License
545 stars 74 forks source link

Executing task fails, Cannot install ptvsd-4.3.2 despite me installing it manually #75

Closed Twiggeh closed 3 years ago

Twiggeh commented 3 years ago

I've installed ptvsd with pip & I enabled blender.allowModifyExternalPython as well. I am not sure what to do here.

pip list | grep ptvsd  
ptvsd               4.3.2      
> Executing task: /usr/bin/blender --python /home/twiggeh/.vscode-oss/extensions/jacqueslucke.blender-development-0.0.12/pythonFiles/launch.py <

Read prefs: /home/twiggeh/.config/blender/2.83/config/userpref.blend
Warning: class FILE_OT_batch_export contains a property which should be an annotation!
/home/twiggeh/.config/blender/2.83/scripts/addons/batchExport.py:16
    assign as a type annotation: FILE_OT_batch_export.filepath
[{'load_dir': '/run/media/twiggeh/Storage/projects/BlenderAddons', 'module_name': 'BlenderAddons'}]
Collecting ptvsd
  Using cached ptvsd-4.3.2-py2.py3-none-any.whl (4.9 MB)
Installing collected packages: ptvsd
Successfully installed ptvsd-4.3.2
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.8/shutil.py", line 788, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/tmp/pip-target-8f_jz32e/lib/python/ptvsd' -> '/usr/lib/python3.8/site-packages/ptvsd'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 186, in _main
    status = self.run(options, args)
  File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 453, in run
    self._handle_target_dir(
  File "/usr/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 510, in _handle_target_dir
    shutil.move(
  File "/usr/lib/python3.8/shutil.py", line 798, in move
    copytree(src, real_dst, copy_function=copy_function,
  File "/usr/lib/python3.8/shutil.py", line 554, in copytree
    return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
  File "/usr/lib/python3.8/shutil.py", line 455, in _copytree
    os.makedirs(dst, exist_ok=dirs_exist_ok)
  File "/usr/lib/python3.8/os.py", line 223, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/usr/lib/python3.8/site-packages/ptvsd'

################################################################################
>   could not install ptvsd
################################################################################

Saved session recovery to '/tmp/quit.blend'
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
JacquesLucke commented 3 years ago

I'm not entirely sure what is wrong. This like looks suspicious: OSError: [Errno 18] Invalid cross-device link: '/tmp/pip-target-8f_jz32e/lib/python/ptvsd' -> '/usr/lib/python3.8/site-packages/ptvsd'. Not sure what it is doing there exactly.

Does it work when you run import ptvsd in the Python Console within Blender? Does Blender use the Python version from the system or its own (usually things might be a bit easier when it uses its own, because then there are less cases to worry about)?

Twiggeh commented 3 years ago

I think its using the systems' python install but I am not sure how to check that.

import ptvsd gave the error no module named ptvsd image

The "no module named ptvsd" is not exclusive to ptvsd, flask doesn't work either, but requests does. image

If I run the task runner with sudo permissions it launches blender & there are no issues, but i can't figure out how to do that from within the extension

JacquesLucke commented 3 years ago

You are using the system python version (which 3.8.3 in your case). Blender comes with Python 3.7.7 currently.

Can you run import sys; import pprint; pprint.pprint(sys.path) in Blender, to check where it looks for modules?

requests probably works, because it is bundled with Blender.

Twiggeh commented 3 years ago

output of import sys; import pprint; pprint.pprint(sys.path)

>>> import sys; import pprint; pprint.pprint(sys.path)
['/usr/share/blender/2.83/scripts/startup',
 '/usr/share/blender/2.83/scripts/modules',
 '/usr/lib/python38.zip',
 '/usr/lib/python3.8',
 '/usr/lib/python3.8/lib-dynload',
 '/usr/lib/python3.8/site-packages',
 '/usr/share/blender/2.83/scripts/freestyle/modules',
 '/usr/share/blender/2.83/scripts/addons/modules',
 '/home/twiggeh/.config/blender/2.83/scripts/addons/modules',
 '/usr/share/blender/2.83/scripts/addons',
 '/home/twiggeh/.config/blender/2.83/scripts/addons',
 '/usr/share/blender/2.83/scripts/addons_contrib']
JacquesLucke commented 3 years ago

If I interpret you terminal output correctly, pip installed flask and probably also ptvsd in ./local/lib/python3.8/site-packages. However, Blender does not look in that path, because that path is not in sys.path. Instead, Blender uses a global Python installation which has it's site packages in /usr/lib/python3.8/site-packages. You could try to make pip install the packages in the global directory instead. I just tested it on my system, and it seems to work when I just use sudo pip .... This is probably related to this message in your terminal output: Defaulting to user installation because normal site-packages is not writeable.

Twiggeh commented 3 years ago

Ok so it works if I force VSC to run in sudo mode. I will try running pip with sudo!

Twiggeh commented 3 years ago

It worked! Thank you a lot :D The Solution was uninstalling and reinstalling the packages with sudo

(Despite it saying that the requirement was already fullfilled in /usr/lib/python... )

HubKing commented 3 years ago

You are using the system python version (which 3.8.3 in your case). Blender comes with Python 3.7.7 currently.

I am getting a similar error but I am using Blender 2.90.1. Does it work with Blender 2.90.1? The Python version in my path seems to be 3.8.5.

found bundled python: c:\Program Files\Blender Foundation\Blender 2.90\2.90\python
[]
Collecting ptvsd
  Using cached ptvsd-4.3.2-cp37-cp37m-win_amd64.whl (5.1 MB)
Installing collected packages: ptvsd
Successfully installed ptvsd-4.3.2
ERROR: Exception:
Traceback (most recent call last):
  File "c:\Program Files\Blender Foundation\Blender 2.90\2.90\python\lib\shutil.py", line 566, in move
    os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\(user name)\\AppData\\Local\\Temp\\pip-target-nylmyiga\\lib\\python\\ptvsd' -> 'c:\\Program Files\\Blender Foundation\\Blender 2.90\\2.90\\python\\lib\\site-packages\\ptvsd'

When I checked the path 'C:\Users\(user name)\AppData\Local\Temp\pip-target-nylmyiga\lib\python\ptvsd' (with \ replaced with ), there was no such directory as pip-target-nylmyiga.