Search code examples
pythonpipblenderbpy

Cannot install package bpy using pip


Problem description: In VS Code, run the command pip install bpy (as indicated in https://pypi.org/project/bpy/) and get the following error message:

PS C:\Users\(...)\Local\Programs\Python\Python38> pip install bpy
Collecting bpy
  Using cached bpy-0.0.0a0.tar.gz (19 kB)
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\(...)\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\(...)\\Local\\Temp\\pip-install-xln6pb4c\\bpy\\setup.py'"'"'; __file__='"'"'C:\\Users\\(...)\\Local\\Temp\\pip-install-xln6pb4c\\bpy\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\(...)\Local\Temp\pip-pip-egg-info-0pdk7e9q'
         cwd: C:\Users\(...)\Local\Temp\pip-install-xln6pb4c\bpy\
    Complete output (16 lines):
    Traceback (most recent call last):
      File "c:\users\(...)\local\programs\python\python38\lib\tokenize.py", line 342, in find_cookie
        codec = lookup(encoding)
    LookupError: unknown encoding: future_fstrings
    During handling of the above exception, another exception occurred:
      File "<string>", line 1, in <module>
      File "c:\users\(...)\local\programs\python\python38\lib\tokenize.py", line 394, in open
        encoding, lines = detect_encoding(buffer.readline)
      File "c:\users\(...)\local\programs\python\python38\lib\tokenize.py", line 381, in detect_encoding
        encoding = find_cookie(second)
      File "c:\users\(...)\local\programs\python\python38\lib\tokenize.py", line 350, in find_cookie
        raise SyntaxError(msg)
    SyntaxError: unknown encoding for 'C:\\Users\\(...)\\Local\\Temp\\pip-install-xln6pb4c\\bpy\\setup.py': future_fstrings
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. code here

------- What I tried (without success): -------

Installed wheels (pip install wheel), then downloaded the package from pypi.org to manually install: pip install 'C:\Users(...)\Downloads\bpy-2.82.1.tar.gz' got the same error.

------- Conclusion: -------

Cannot use bpy outside of Blender. I found some workarounds (which I have yet to try) on another post on Blender Stack Exchange Thanks Anand and phd for the very useful links!


Solution

  • Unfortunately the ‘bpy’ module cannot be used outside of Blender.

    More details are here: https://creativepolygon.com/development/starting-with-bpy-blender-python-part-1-installation