0
$\begingroup$

thx for the patience. I'm not very familiar with python and I am trying to use a tabulate import but get errors.

Traceback (most recent call last): File "\CheckObejctSize.py", line 5, in ModuleNotFoundError: No module named 'tabulate' Error: Python script failed, check the message in the system console

I've read a whole bunch of threads on what to do, but none have helped. I was going to use the blender/pip to add tabulate but I can't seem to even find pip.

I found a thread that suggested:

import ensurepip ensurepip.bootstrap() pybin = bpy.app.binary_path_python subprocess.check_call([pybin, '-m', 'pip', 'install', 'tabulate']) 

which produced Defaulting to user installation because normal site-packages is not writeable Looking in links: c:\Users\Jon\AppData\Local\Temp\tmp99hzlnij Requirement already satisfied: setuptools in c:\program files\blender foundation\blender 3.0\3.0\python\lib\site-packages (57.4.0) Requirement already satisfied: pip in c:\program files\blender foundation\blender 3.0\3.0\python\lib\site-packages (21.2.3) Traceback (most recent call last): File "\CheckObejctSize.py", line 10, in AttributeError: 'bpy.app' object has no attribute 'binary_path_python' Error: Python script failed, check the message in the system console

Why can't I find pip when it seems that it's already there and how can I get tabulate import working in Blender 3.0 scripting?

$\endgroup$

1 Answer 1

0
$\begingroup$

Convoluted but I got it to work:

  • Download the get-pip.py file from the web. https://bootstrap.pypa.io/get-pip.py
  • Place it in ...Blender Foundation\Blender 3.0\3.0\python\bin
  • Run Blender Foundation\Blender 3.0\3.0\python> .\bin\python.exe ./bin/get-pip.py

You will see:

Collecting pip Downloading pip-22.0.3-py3-none-any.whl (2.1 MB) ---------------------------------------- 2.1/2.1 MB 8.3 MB/s eta 0:00:00 Collecting wheel Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB) Installing collected packages: wheel, pip WARNING: The script wheel.exe is installed in 'C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Attempting uninstall: pip Found existing installation: pip 21.2.3 Uninstalling pip-21.2.3: Successfully uninstalled pip-21.2.3 WARNING: The scripts pip.exe, pip3.9.exe and pip3.exe are installed in 'C:\Program Files\Blender Foundation\Blender 3.0\3.0\python\Scripts' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-22.0.3 wheel-0.37.1 
  • This will have created a Scripts directory, now I can use pip3 to install
  • Blender Foundation\Blender 3.0\3.0\python> ./Scripts/pip3 install tabulate

With Subsequent Blender upgrades I ran into problems again, and now I have this script which has been working

# From https://b3d.interplanety.org/en/installing-python-packages-with-pip-in-blender-on-windows-10/ import subprocess import sys import os python_exe = os.path.join(sys.prefix, 'bin', 'python.exe') target = os.path.join(sys.prefix, 'lib', 'site-packages') print('target is: ' + target) print('sys.path is: ') for i in sys.path: print(i, end="") # print('sys.path is: ' + sys.path) print('HELLO') print('sys.executable is: ' + sys.executable) subprocess.call([python_exe, '-m', 'ensurepip']) subprocess.call([python_exe, '-m', 'pip', 'install', '--upgrade', 'pip']) subprocess.call([python_exe, '-m', 'pip', 'uninstall', 'pip', 'setuptools']) subprocess.call([python_exe, '-m', 'pip', 'install', '--upgrade', 'numpy', '-t', target]) subprocess.call([python_exe, '-m', 'pip', 'install', '--upgrade', 'tabulate', '-t', target]) subprocess.call([python_exe, '-m', 'pip', 'install', '--upgrade', 'scipy', '-t', target]) print('FINISHED') 
$\endgroup$
1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.