About the python in blender.
Closed this issue · 4 comments
Hi, firstly, thank you very much for the tutorial on Blender's visualization. I have almost completed the steps, but I still encountered some problems.
I have installed blender 2.93, and the path of blender python is "/snap/blender/3688/2.93/python/bin/python3.9". I followed the instructions to install the needed packages, and if I use '/snap/blender/3688/2.93/python/bin/python3.9' to start the python, I can successfully import these packages. But if I use 'blender --background --python-expr "import xxx", the packages cannot be imported, causing the "No module" error. It seems that the Python interpreters launched in these two ways are not consistent. May I ask what is causing this situation and how I can resolve it.
Hope to get your help, thanks a lot.
Hello @yyvhang,
Can you check with the command "which blender
" that your blender
command is pointing to the version you installed (/snap/blender/3688/2.93
)?
Then check that your packages are well installed in your local folder: ~/.local/lib/python3.9/site-packages
.
If your packages are somewhere else, you can modify this line:
Line 5 in aedf871
Hello @yyvhang,
Can you check with the command "
which blender
" that yourblender
command is pointing to the version you installed (/snap/blender/3688/2.93
)?Then check that your packages are well installed in your local folder:
~/.local/lib/python3.9/site-packages
. If your packages are somewhere else, you can modify this line:Line 5 in aedf871
Thanks for the reply, I use "which blender" to check the blender path, and it does the "/snap/blender/3688/2.93" I installed. After adding the sys.path.append (os.path.expanduser("~/.local/lib/python3.9/site-packages"))
, rendering the .mp4 can work.
But when rendering the .png image, raising an error about the numpy version. I useblender --background --python-expr "import numpy;print(numpy.__version__)"
to check the version and it is 1.19.5. However, in the "~/.local/lib/python3.9/site-packages"
, the numpy version is 1.26.2. Do you know why this happened? Thanks again for your help!
Hello @yyvhang,
Can you check with the command "which blender
" that yourblender
command is pointing to the version you installed (/snap/blender/3688/2.93
)?
Then check that your packages are well installed in your local folder:~/.local/lib/python3.9/site-packages
. If your packages are somewhere else, you can modify this line:
Line 5 in aedf871
Thanks for the reply, I use "which blender" to check the blender path, and it does the "/snap/blender/3688/2.93" I installed. After adding the
sys.path.append (os.path.expanduser("~/.local/lib/python3.9/site-packages"))
, rendering the .mp4 can work. But when rendering the .png image, raising an error about the numpy version. I useblender --background --python-expr "import numpy;print(numpy.__version__)"
to check the version and it is 1.19.5. However, in the"~/.local/lib/python3.9/site-packages"
, the numpy version is 1.26.2. Do you know why this happened? Thanks again for your help!
I have solved this problem, when use sys.path.append (os.path.expanduser("~/.local/lib/python3.9/site-packages"))
, there are multiple 'site-packages' paths in the 'sys.path'. If you want to use the site-packages in ~/.local/lib/python3.9/site-packages
, you should change the order in 'sys.path', use this command could be better: sys.path.insert(0, '/home/user/.local/lib/python3.9/site-packages')
.
Hope this could help others with the same problem.
Thanks for your comment, it makes a lot of sense.
I just made a commit and changed the line to be:
sys.path.insert(0, os.path.expanduser("~/.local/lib/python3.9/site-packages"))
I will probably at some point remove the rendering code from TEMOS and create a dedicated library for rendering (and maybe update to blender 4). I will let you know!