How to use the Anaconda environment on blender?

Viewed 1326

I'm having problems to use some modes like numpy and pandas on blender, apparently the blender's python do not allow us to install packages using pip; so I thought that I could resolve this issue changing its environment to the Anaconda or something like that. I looked for solutions, but all I founded worked on windows but I use ubuntu. If someone can help me, I really appreciate it.

2 Answers

Here is how I proceed:

Deactivate current python used by Blender

→ Go to your Blender files (for example: cd /usr/share/blender/3.0/)

→ Deactivate the current python version: mv python _python

Create a new anaconda environment

Warning

As mentioned here, the python version (major and minor) must match the one that Blender comes with. For Blender 3.0, python 3.9 is ok.

→ Enter : conda create --name=blender python=3.9

→ When the installation is finished, enter: conda activate blender

Link the Anaconda environment to Blender

→ If you have installed Anaconda with the default parameters, your conda env’ should be installed here: ~/anaconda3/envs/blender/

→ So, enter: sudo ln -s ~/anaconda3/envs/blender/ python

This creates a junction between the python folder in the Blender files and the folder in the Anaconda environments files.

Install new python packages

In a terminal, run: pip (or conda) install [package_name] under the blender anaconda environment (use: conda activate blender to switch environment)

I have rewritten these instructions from another tutorial I have written here The tutorial is for another tool, but I needed to setup quite the same environment as what you want, I guess.

after struggling with this several times, and coming across it right now, I figured I'd share my solution.

long story short: just install things into the default blender environment or install bpy into an anaconda environment

On linux you may be able to follow Failxxx's answer, or using mklink in Windows maybe the same (I couldn't get it to work, got weird "compiler" errors when trying to import bpy in blender).

You can also check here for various workarounds:

https://docs.blender.org/api/current/info_tips_and_tricks.html

In the end, I've had success building bpy as a module inside of an anaconda environment (follow tutorial in link), or installing whatever packages I want inside of my Blender python environment.

To do this.. find out where your Blender's python.exe is stored.. mine is here:

C:\Program Files\Blender Foundation\Blender 3.2\3.2\python\bin

then, open a cmd as admin (admin was extremely crucial for my machine?) in this directory and do something like:

python -m pip install pandas

this will install the package into your Blender python environment. Sometimes I had to uninstall and reinstall with admin incase anything had been installed to C:\Users\%USERNAME%\AppData\Roaming - Python or Blender folders.

if it's only a handful of packages, this is the best way in my opinion. Just know that this permanently alters the python environment that shipped with Blender.

Proof :) :

proof

Related