TylerGubala/blenderpy

Error installing bpy through pip

Opened this issue · 4 comments

I have tried to install bpy thorugh termial (pip) and also by PyCharm, but i obtain always this error regardless i have updated all the
other libraries just in case. I don't know ho to resolve this. Please help me :(

Collecting bpy
  Using cached bpy-0.0.0a0.tar.gz (19 kB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Building wheels for collected packages: bpy
  Building wheel for bpy (setup.py): started
  Building wheel for bpy (setup.py): finished with status 'error'
  Running setup.py clean for bpy
Failed to build bpy
Installing collected packages: bpy
  Running setup.py install for bpy: started
  Running setup.py install for bpy: finished with status 'error'

  error: subprocess-exited-with-error
  
  python setup.py bdist_wheel did not run successfully.
  exit code: 1
  
  [20 lines of output]
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\blenderpy
  copying blenderpy\post_install.py -> build\lib.win-amd64-3.9\blenderpy
  copying blenderpy\__init__.py -> build\lib.win-amd64-3.9\blenderpy
  warning: build_py: byte-compiling is disabled, skipping.
  
  running build_ext
  Preparing the build environment
  Searching for compatible Blender online (this will take a while)
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v1 is an invalid version and will not be supported in a future release
    warnings.warn(
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v2 is an invalid version and will not be supported in a future release
    warnings.warn(
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v3 is an invalid version and will not be supported in a future release
    warnings.warn(
  error: [WinError 2] Impossibile trovare il file specificato
  [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for bpy
  error: subprocess-exited-with-error
  
  Running setup.py install for bpy did not run successfully.
  exit code: 1
  
  [22 lines of output]
  running install
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
    warnings.warn(
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  creating build\lib.win-amd64-3.9\blenderpy
  copying blenderpy\post_install.py -> build\lib.win-amd64-3.9\blenderpy
  copying blenderpy\__init__.py -> build\lib.win-amd64-3.9\blenderpy
  warning: build_py: byte-compiling is disabled, skipping.
  
  running build_ext
  Preparing the build environment
  Searching for compatible Blender online (this will take a while)
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v1 is an invalid version and will not be supported in a future release
    warnings.warn(
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v2 is an invalid version and will not be supported in a future release
    warnings.warn(
  C:\Users\corra\AppData\Local\Programs\Python\Python39\lib\site-packages\pkg_resources\__init__.py:122: PkgResourcesDeprecationWarning: softbody-stable-v3 is an invalid version and will not be supported in a future release
    warnings.warn(
  error: [WinError 2] Impossibile trovare il file specificato
  [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

Encountered error while trying to install package.
bpy
note: This is an issue with the package mentioned above, not pip.

I have the same problem (basically the same error message) trying to pip install bpy on mac python 3.9

Just went through this.
The pip page specifies >=3.7 and <3.8 so I'd suggest the following steps

  • Install python 3.7 in a new virtual environment (via miniconda / conda / anaconda or whatever)
  • jump to that environment (confirm you're on the right version with python --version - mine was Python 3.7.13)
  • pip install future_fstrings because it's going to complain about that
  • pip install bpy && bpy_post_install

Same problem for me.
Funny there's no 3.7 installer for windows, the only version this package works with:
https://www.python.org/downloads/windows/
(@AdamStormhardtGH I assume this is why you suggested the virtual environment.)

An update on this.

I ended up abandoning a pip installation after seeing some more issue and just leveraging the bpy installed as part of the blender package.

This lets me:

  • Sidestep the entire process of having to install bpy via pip.
  • Just update blender as needed and remain up to date
  • Not wrestle with version incompatibility
  • Not mess around with having to host a blender specific Venv (as much as I'd like to, i found this pretty flaky, at least on my OSX M1 Studio)

My new commands are using subprocess to just call the python command.

import subprocess

blender_job_command = f"blender {cwd}/src/blend/template_scene.blend --python {cwd}/src/scripts/my_main_python_script.py" 
subprocess.Popen(blender_job_command, shell=True, stdout=subprocess.PIPE)

Note that this has kinda made me have to work more modularly and pull a lot of the blender interaction out into more discrete steps, but it's pretty reliable.

If you're interested in doing this

Setup (MAC) - sorry I'm not sure how this will translate to windows =/. Maybe the windows linux subsystem will be compatible but I have not tested this :

  • Find the location of the python version hosted in blender. For mac it's /Applications/Blender.app/Contents/Resources/3.1/python/bin/python3.10
  • Now install appropriate libraries for that version. There are 2 options here:
Option 1: Locally (default)

Doing pip installs will default to local, which is okay if you want to add an environment variable in the next step.

  • tell blender it needs to look at your .local file with:
import os
sys.path.append(f'~/.local/lib/python3.10/site-packages/') #python packages registration. This lets us use pandas etc 
Option 2: System level
  • sudo -H pip install <package_name>
  • The -H tells pip not to install into the .local location. Note that I found I needed sudo in order for my terminal to respect -H
  • All libraries should just work now when running your script

Not an ideal fix, but it's removed some of the headaches around this bpy stuff. I haven't worked with a library which acts like this before. Hopefully it becomes a little more universally installable in the future.