Build an environment for Blender built-in Python

Blender has built-in Python and can execute various scripts. However, the installed modules are limited to numpy etc., and it takes a little work to add your favorite module, so I will explain it.

For Windows

With the default settings, Blender should be stored in the following location:

C:\Program Files\Blender Foundation\Blender\2.80

Python below this is built-in. (It's different from Python that I installed individually)

C:\Program Files\Blender Foundation\Blender\2.80\Python\python.exe

image.png

You can also find pip.exe (module to install) in the following location.

C:\Program Files\Blender Foundation\Blender\2.80\python\Scripts

image.png

**! The version may be 2.81 or 2.80, so please adjust it yourself **

This pip does not have a path (it does not refer to this pip), so at the command prompt, for example,

pip install pandas

I can't pass it. (If another Python is installed, it will be installed there)

If you don't have a pass, you can just refer to the location directly.

C:\Program Files\Blender Foundation\Blender\2.80\python\Scripts\pip install pandas

If you do, it will not be OK ..., and in fact, it will take another effort, and this will not work due to the administrator privileges of Windows.

C:\Program Files\Blender Foundation\Blender\2.80\python\Scripts\pip install pandas --user

This will work. image.png

Please note that the working directory is

>>> import os
>>> os.getcwd()
'C:\\Program Files\\Blender Foundation\\Blender'

Therefore, if you perform an operation such as creating a file and referencing it, an error will occur if you do not have administrator privileges. Start Blender with administrator privileges, or create and browse files under the user directory.

For Mac

For Mac, Blender should be stored in the following location:

/Applications/Blender.app/Contents/Resources/2.81

image.png

**! The version may be 2.81 or 2.80, so please adjust it yourself **

However, for some reason pip is not installed. You need to install pip.

Open the terminal,

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
/Applications/blender.app/Contents/Resources/2.81/python/bin/python3.7m get-pip.py

**! The version of python is 3.7 or 3.5, so please adjust it individually **

Will generate pip.

The rest is the same,

/Applications/blender.app/Contents/Resources/2.81/python/bin/pip install pandas

Installation is complete.

image.png

_tkinter trap

By the way, when I try to import pyplot on Windows, I get the following error.  image.png

It is said that there is no _tkinter. Looking at the contents of the tkinter / __ init__.py that was imported immediately before,

image.png

"If this fails, your Python may not be tuned for Tk."

This may not be the case with normal (?) Python installed separately, so it may be a problem specific to built-in Python.

For the time being, there is a trick to copy the separately installed python under C: \ Program Files \ Blender Foundation \ Blender \ 2.80 \ ** together with the folder ** (the original python folder was renamed). And evacuate). With this, you can bring the environment as it is. However, I couldn't draw the graph with pyplot.show (). This method may be useful if the built-in Python just can't pip the module.

On MacOS, I don't get this error, but I still couldn't draw with pyplot.show ().

Drawing a graph in Blender seems difficult (although it doesn't seem necessary much).

Recommended Posts

Build an environment for Blender built-in Python
Build an interactive environment for machine learning in Python
Build an environment for machine learning using Python on MacOSX
Python environment for projects
For beginners to build an Anaconda environment. (Memo)
Building an environment for executing Python scripts (for mac)
Building an Anaconda environment for Python with pyenv
How to build an environment for using multiple versions of Python on Mac
Build an Anaconda virtual environment
Build a python environment for each directory with pyenv-virtualenv
[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04
Build python3 environment with ubuntu 16.04
Python environment construction For Mac
Build Python environment on Windows
Build python environment with direnv
Python3 environment construction (for beginners)
Building an environment for natural language processing with Python
[ev3dev × Python] Build ev3dev development environment
Build python environment on windows
[For organizing] Python development environment
Build a Python environment offline
I tried to build an environment for machine learning with Python (Mac OS X)
Build an Ubuntu python development environment on Google Cloud Platform
Build a python environment on CentOS 7.7 for your home server
Build python virtual environment with virtualenv
Studying Python Part.1 Creating an environment
Build Mysql + Python environment with docker
Python development environment options for May 2020
Emacs settings for Python development environment
Python3 TensorFlow for Mac environment construction
Created an environment for Anaconda & Jupyter
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Build a python3 environment on CentOS7
An introduction to Python for non-engineers
[Sakura Rental Server] (For beginners) How to build an environment for Python, pyenv, and Flask. | For csh
[Docker] Build an environment of python (Flask) + GraphQL (graphene) + MySQL (sqlalchemy)
Built-in python
Build and test a CI environment for multiple versions of Python
Build a local development environment for Lambda + Python using Serverless Framework
Try using virtualenv, which can build a virtual environment for Python
Build and try an OpenCV & Python environment in minutes using Docker
Build python 1.0
Anyone can understand how to build an initial environment for Python on Mac September 2016 (pyenv + virutalenv)
[Python] Building an environment with Anaconda [Mac]
Python development environment for macOS using venv 2016
Build Jupyter Lab (Python) environment with Docker
Python 2.7, 3.4, 3.5 extension module build environment on Windows
Method to build Python environment in Xcode 6
Python project environment construction procedure (for windows)
Blender 2.82 or later + python development environment notes
Build Python3 and OpenCV environment on Ubuntu 18.04
Build a python environment on MacOS (Catallina)
Note when creating an environment with python
Python environment tool comparison chart for Rubyist
Let's create a virtual environment for Python
Creating amateur python environment settings (for MAC)
I want to build a Python environment
Build an LNPP environment on Amazon Linux 2
[Mac] Building a virtual environment for Python
Build Python environment with Anaconda on Mac
To reference environment variables in Python in Blender