I understand blender runs a version of python separate from the system python. I’m writing some scripts to collect a bunch of data on my objects, investigate it, and spit out some cool graphs. I usually do this in the context of a Jupyter notebook with Numpy, Pandas, and Matplotlib. Blender already has Numpy, so I just have to figure out how to get the other two in there.
The try/except is because you only need to install the package once, otherwise Blender will lag a ton each time you open it. If the package is already installed, the try just imports what you need from it. If it’s not, the except catches it and installs it. This process is a bit slow on the first time (initial install), but fortunately once it’s installed there’s no more lag
Had to modify it a little for my linux box, but this was perfect. Thank you!
[EDIT] In case someone is reading this down the road, everything is exactly the same except the executable in sys.prefix/bin/ isn’t ‘python.exe’ it’s just ‘python’ or ‘pythonX.Xx’. The python_exe variable can be whatever you want, naturally.
Caveat for Mac users – before you make any changes to a fresh install of Blender, make sure to launch it once so your Mac recognizes it as safe software. I’ve found if I modify anything in the app bundle before I run it, my Mac considers it as malware and won’t run it at all.
So anyway, installing Pandas and Matplotlib from the Terminal would be:
Forgive me for re-stating what is obvious to power users, but since this is in the Python Support channel, I’m throwing this out for our comrades who are still new to the basics (like me!) and come across threads like this at the start of their journey.
Nice! The little advantage about the script is: you can run it in any Blender version and it will install the library you want for that Blender version. If i do it by terminal, i always have to change the path to the “right” path manually And if the Blender developers change the path to Blender, the script still will work.
I am one of noobs mentioned above and I can’t for the life of me get a script running even after the things mentioned.
A simple run of this script
nets me ModuleNotFoundError: No module named 'scipy'
even after trying to install 8 ways from Sunday.
Running sudo /Applications/Blender.app/Contents/MacOS/Blender
to make sure I get to see the console, and after running I’m still getting ModuleNotFoundError despite getting Requirement already satisfied for scipy.
Hi and thanks a lot for these scripts!
However it does not work for me. I’m using Blender 4.2 under windows, and python.exe of blender does not want to install in the blender site-packages. It installs in the system python site-packages instead.
python_exe variable is C:\Program Files\Blender Foundation\Blender 4.2\4.2\python\bin\python.exe
but when trying to do any pip command, it tells me
Defaulting to user installation because normal site-packages is not writeable
and then i get messages telling me that the package is installed in the system python installation.
Tried to change the permissions of site-package folder and it does not work.
has anyone had the same issue?
Thanks for your help!