Why aren't python packages from Anaconda being

2019-08-12 01:52发布

问题:

I've recently been using Blender to render 3D models of objects and training an SVM to recognize pictures of object taken from some perspective. To train said SVMs I need to use "sklearn", which comes by default with Anaconda.

Long story short, I want Blender (which runs Python 3.4.2) to use the packages and modules present in my anaconda installation (which runs Python 3.4.3).

I've tried a variety of things following this website: https://www.blender.org/api/blender_python_api_2_60_1/info_tips_and_tricks.html#bundled-python-extensions

1.) I deleted the "python" folder within the Blender.app. According to the above website, Blender should fallback to using the version of python installed in the system (i.e. the one installed thru anaconda? Right?) but instead I get this: 2.) So I go onto option number 2. So, what I do is go to the anaconda folder and copy the two folders "bin" and "lib" into Blender.app/Contents/Resources/2.76/python/ (replacing the lib and bin folders that are already there)

So far everything is good, I open Blender (no error) and then I write a simple script:

from sklearn import svm 

When I try to run it I get the following error message:

Error: Python script fail, look in the console for now...

Traceback (most recent call last): File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/Scripts/MarkTwo.blend/SimulationMarkOne.py", line 5, in File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/svm/init.py", line 13, in from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC, \ File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/svm/classes.py", line 4, in from .base import _fit_liblinear, BaseSVC, BaseLibSVM File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/svm/base.py", line 9, in from . import libsvm_sparse File "sklearn/svm/libsvm_sparse.pyx", line 5, in init sklearn.svm.libsvm_sparse (sklearn/svm/libsvm_sparse.c:7612) File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/utils/init.py", line 16, in from .class_weight import compute_class_weight, compute_sample_weight File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/utils/class_weight.py", line 7, in from ..utils.fixes import in1d File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/sklearn/utils/fixes.py", line 318, in from scipy.sparse.linalg import lsqr as sparse_lsqr File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/scipy/sparse/linalg/init.py", line 113, in from .matfuncs import * File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/scipy/sparse/linalg/matfuncs.py", line 20, in import scipy.misc File "/Users/cusgadmin/... Perception/blender-2.76b-OSX_10.6-x86_64/blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages/scipy/misc/init.py", line 44, in from . import doccer ImportError: cannot import name 'doccer' Error: Python script fail, look in the console for now...

At which point I don't know what else to do. I used the Python console embedded in Blender to explore the sub-packages in sklearn and surprisingly I am getting non-matching sub-packages..

I am very confused and do not know how to proceed. Any help is greatly appreciated folks.

Best, MrRed

回答1:

Alright folks, I found a solution and I hope this will help future generations after me and so on ;)

Anyway, I managed to be able to import the libraries by doing the following:

  1. Keep all the same files Blender came with (DO NOT delete the python folder as the website suggests!)
  2. Go to the subfolder "site-packages" located at: "Blender.app/Contents/Resources/2.76/python/lib/python3.4/site-packages"
  3. There, copy the contents of "anaconda/lib/python3.4/site-packages" and paste them in the previously mentioned folder
  4. (I copied everything within "anaconda/lib/python3.4/site-packages" except for the "numpy" and "requests" folders, and I also did not copy the file "numpy-1.9.1-py3.4.egg-info" over the folder.)

Hope this helps, and if it does, you're welcome :)