blenderplayer and 3rd party libraries

Blender player is a nice way to create stand alone .blend files that can be distributed to other people.

However, for most interesting programming, one would use in python libraries such as numpy, etc. All the python libraries out there is what makes python so powerful. Blender does not come with e.g. numpy pre-installed, .but 3rd party libraries can be installed.

However, when the .blend file is distributed, it still depends on those libraries... The problem is that now the end-user, which might not be tech-savvy needs to install the 3rd party libraries alone... Is there any way to fix this?

This question relates to the (unanswered :S) How to bundle python libraries into addon? in that a solution to it might be a solution to this one, but "how-to-bundle-python-libraries-into-addon" refers to plugins, not .blends for the standalone player, and further this question is more general, any way to distribute the 3rd-party libraries would be ok (e.g. could one put them in the .blend directory and set some paths to point there?).

I had the problem on a .blend file, and that was because I was using an old version of Blender , newer versions will have numpy etc. (my old version was using the system's python, now python comes with a nice python that has common stuff like numpy included, so the question becomes less important.

To see if numpy was not there i did on a script from inside blender:

import os
import sys
print ('sys.executable',sys.executable)
print ('---')
print ('sys.path',sys.path)
print ('===')
try:
print ('PYTHONPATH', os.environ['PYTHONPATH'])
except:
print ('no PYTHONPATH')
import numpy as np
print('done!:)')


to which I got:

sys.executable /usr/bin/blender
---
===
no PYTHONPATH
Traceback (most recent call last):
File "/Text", line 11, in <module>
ImportError: No module named 'numpy'
Error: Python script fail, look in the console for now...


)

Blender 2.79 gives:

sys.executable /home/ntg/software/blender-2.79-linux-glibc219-x86_64/blender
---
sys.path:
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/scripts/startup
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/scripts/modules
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/python/lib/python35.zip
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/python/lib/python3.5
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/python/lib/python3.5/plat-linux
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/python/lib/python3.5/site-packages
/home/ntg/software/blender-2.79-linux-glibc219-x86_64/2.79/scripts/freestyle/modules
===
os.path: /opt/pub/anaconda2/bin:/home/ntg/bin:/home/ntg/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
===
no PYTHONPATH
done!:)


Blender does not come with e.g. numpy pre-installed

Yes it does, unless you configure WITH_PYTHON_INSTALL_NUMPY:BOOL=OFF and build it yourself.

Python modules can simply be imported from whatever is listed on the PYTHONPATH environment variable. If it doesn't automatically work by placing .py files next to your .blend file, you can modify PYTHONPATH to point to that location.

You can bundle 3rd-party modules with your game, but you do have to think about the following:

• You have to adhere to the license of the module, so probably you'll have to include their license, give them credit, etc.
• Be careful with binary modules. Make sure you test (so don't read documentation and assume it'll work, but actually test it) that they work with the version of Python that's built into Blender. On Windows this may be an issue, since (AFAIK) we build Python with different options than the python.org build, and as a result the pre-built binary Python modules may not load in Blender.
• If you do decide to use binary (i.e. .pyd, .so, or .dll extensions) Python modules, make sure you include the versions for all platforms you want your game to run on.
• Thanx for the answer! In my system (sonya mint 18.2, Blender 2.76b), it seems numpy is not there(will add info to the question), however the PYTHONPATH might solve the problem, will have to check and be back – ntg Nov 20 '17 at 10:27
• Try a recent Blender release from download.blender.org/release; the version of Blender you're using now is already two years old. – dr. Sybren Nov 20 '17 at 11:42
• Lol, and It is the one that comes with the latest version of ubuntu :) Good point, will do. – ntg Nov 20 '17 at 13:19
• Indeed! Using the latest version of blender (2.79) allows me to load numpy! Still not sure what happens if there is some obscure library I need, but my problem is solved :) (thanx, did +1) – ntg Nov 20 '17 at 13:28