3

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!

5 Answers 5

13

From what I understand it is actually possible to run bpy outside blender and information that claims otherwise was written for older versions. I have to admit though that I am still in progress of installing bpy which is not an easy task and I cannot verify this, yet.

In your case, a pip module is missing. You can install it with pip install future_fstrings. Have a look at https://pypi.org/project/bpy/ for more guidelines.

EDIT: I was able to install bpy under Windows and Linux. It throws some errors on Linux but works fine under Windows. And absolutely works standalone!

6

I used a lot of trial and error and found out that using a Python version of 3.7.6 and pip version of 20.2.4, I was able to install bpy version - 2.82.1 by pip install bpy. I am using Windows 10 and Anaconda prompt.

2
  • 1
    worked for me as well. version 3.7.6 was the one that ended up working for me as well
    – SujithaW
    Jan 5, 2021 at 8:16
  • 1
    Only thing that ever seems to work! Thanks a ton! Sep 5, 2022 at 18:23
1

I guess you can't install bpy because you're installing bpy by python 3.8 version. You have do downgrade your python version to 3.7

Check out https://pypi.org/project/bpy/

then you can see bpy module requires version of Python >=3.7, <3.8

0

TL:DR- install from prebuilt wheel, not from standard pip install bpy && bpy_post_install


Errors installing on macos:

I have been trying to install it for the last 8 hours or so.

My installation steps thus far:

  • I built the blender app from source, following instructions on blender.org
  • According to the bpy github repo- bpy depends upon bpy-build (though it's not in the prerequisites).
  • The bpy-build github repo doesn't have great installation instructions, and the setup.py script specifically declares the OS as windows. So, I basically just skipped this- a possible cause of the install failures.
  • In two different attempts, I used both pyenv and virtualenv, to create a python 3.7 dev environment. Both resulted in a hanging install for pip install bpy during the running of setup.py. The actual error from the pip install is:
Collecting bpy
  Using cached https://files.pythonhosted.org/packages/4b/ed/ba6092b691acc5b157891421d9fde4a9dd5dcc8a8b93a4e8119fec261391/bpy-2.82.1.tar.gz
Installing collected packages: bpy
  Running setup.py install for bpy ... error
    ERROR: Command errored out with exit status 1:
     command: /<path-to-venv>/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/setup.py'"'"'; __file__='"'"'/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-record-ti3q9j4a/install-record.txt --single-version-externally-managed --compile --install-headers /<path-to-venv>/venv/include/site/python3.7/bpy
         cwd: /private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/
    Complete output (58 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/blenderpy
    copying blenderpy/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/blenderpy
    copying blenderpy/pre_uninstall.py -> build/lib.macosx-10.9-x86_64-3.7/blenderpy
    copying blenderpy/post_install.py -> build/lib.macosx-10.9-x86_64-3.7/blenderpy
    running build_ext
    Preparing the build environment
    Searching for compatible Blender online (this will take a while)
    Found compatible Blender version 2.82
    Cloning Blender source from git (this will take a while)
    Cloning precompiled libs from svn (this will take a while)
    cmake -DWITH_PYTHON_INSTALL=OFF -DWITH_PYTHON_MODULE=ON -DWITH_OPENMP=OFF -DWITH_AUDASPACE=OFF -S/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/build/temp.macosx-10.9-x86_64-3.7/blender -B/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/build/temp.macosx-10.9-x86_64-3.7/build
    -- The C compiler identification is AppleClang 12.0.5.12050022
    -- The CXX compiler identification is AppleClang 12.0.5.12050022
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Detected OS X 11.3 and Xcode 12. at /Applications/Xcode.app
    -- OSX_SYSROOT_PREFIX: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform
    -- Setting deployment target to 10.11, lower versions are not supported
    CMake Warning at CMakeLists.txt:580 (message):
      WITH_OPENAL requires WITH_AUDASPACE which is disabled


    CMake Warning at CMakeLists.txt:584 (message):
      WITH_JACK requires WITH_AUDASPACE which is disabled


    -- WITH_DRACO requires WITH_PYTHON_INSTALL to be ON, disabling WITH_DRACO for now
    -- Performing Test SUPPORT_SSE_BUILD
    -- Performing Test SUPPORT_SSE_BUILD - Success
    -- SSE Support: detected.
    -- Performing Test SUPPORT_SSE2_BUILD
    -- Performing Test SUPPORT_SSE2_BUILD - Success
    -- SSE2 Support: detected.
    -- Found Git: /usr/bin/git (found version "2.30.1 (Apple Git-130)")
    CMake Error at build_files/cmake/platform/platform_apple.cmake:38 (message):
      Mac OSX requires pre-compiled libs at:
      '/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/build/temp.macosx-10.9-x86_64-3.7/blender/../lib/darwin'
    Call Stack (most recent call first):
      CMakeLists.txt:808 (include)


    -- Configuring incomplete, errors occurred!
    See also "/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/build/temp.macosx-10.9-x86_64-3.7/build/CMakeFiles/CMakeOutput.log".
    See also "/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/build/temp.macosx-10.9-x86_64-3.7/build/CMakeFiles/CMakeError.log".
    error: command 'cmake' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /<path to venv>/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/setup.py'"'"'; __file__='"'"'/private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-install-m6rixhki/bpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/4n/wsjhxhbn0pb11r7cyqcvtxcc0000gn/T/pip-record-ti3q9j4a/install-record.txt --single-version-externally-managed --compile --install-headers /<path to venv>/venv/include/site/python3.7/bpy Check the logs for full command output.

**** The breakthrough **** While writing this, I noticed the option in the bpy github page to install via pre-build wheel rather than the usual pip install bpy && bpy_post_install. You have to go to some 'sketchy' sites to download the file, but after I downloaded it and installed it that way I was able to run blender scripts outside of the blender app!!

-3

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

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.