I've been trying to install pyserial for blender, but I can only install it to python32 on my C drive, is there anything i can do to have it install to blender or have blender import from python32
The best and recommended way to install Python modules is to use pip, the Python package manager. Otherwise: Download get-pip.py from https://bootstrap.pypa.io/get-pip.py. Run python get-pip.py.
In the Preferences, there is the toggle to Auto Run Python Scripts. This means the Trusted Source option in the File Browser will be enabled by default, and scripts can run when blend-files are loaded without using the File Browser.
Blender has its own python installation and libraries. You can try to install your packages to blender directly. My dir for example: ...\Blender 2.63\2.63\scripts\modules
Otherwise, you can always hardcode the paths directly in your code with sys.path.append("...")
More info about installing modules available here, read about python setup.py install --home=<dir>
For windows, with no special permissions, and from blender python script only:
Install package you want from blender script (tqdm
for example given below):
import pip
pip.main(['install', 'tqdm', '--user'])
From blender console watch the path where pip actually installs packages in your configuration (WARNING: The script tqdm.exe is installed in 'C:\Users\<Username>\AppData\Roaming\Python\Python39\Scripts' which is not on PATH
):
In blender script add the path where your blender's pip installs packages to PATH
:
import sys
packages_path = "C:\\Users\\<Username>\\AppData\\Roaming\\Python\\Python39\\Scripts" + "\\..\\site-packages"
sys.path.insert(0, packages_path )
Successfully import your package in the script:
import tqdm
To show Blender terminal in v2.93 click Window -> Toggle System Console
The whole script
# 1. launch in blender python interpreter
import pip
pip.main(['install', 'tqdm', '--user'])
# 2. watch blender's python path in console output at this moment
# 3. insert it to packages_path below
# 4. uncomment the next code and launch script in blender interpreter again
# import sys
# packages_path = "C:\\Users\\<Username>\\AppData\\Roaming\\Python\\Python39\\Scripts" + "\\..\\site-packages" # the path you see in console
# sys.path.insert(0, packages_path )
# import tqdm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With