I'm using Blender 2.78 (64bit) with Python 3.5.2 on Windows 7 (64bit). My situation is that I want to use opencv in combination with python in Blender. I went in serious trouble trying so and was working for days without any obvious success..
However from googling I found that there is a way to install pip as a module for blenders python and with pip I was able to install modules such as numpy oder scipy. This indeed also worked with opencv as it got successfully installed (including positive checks). It looked fine. But as I tried to import cv2 in a Console in Blender I got the error like the thread starter above:
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
File "C:\Program Files\Blender Foundation\Blender\2.78\python\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I then tried to start blender python in an external shell and retried the import process resulting in the same error.
Next was retrying the complete procedure for my system python (same version 3.5.2) and everything worked perfectly.
From now on I was a bit confused as "pypi.python.org/pypi/opencv-python" towards opencv-python states that everything is linked statically and everything you have to do is what I have done. Looking in the FAQ the error is mentioned. You get the advise to check visual c++ redistributable and c runtime library. I did so, however, both is up to date and on system python opencv works perfectly that way.
Next try. As the system python works perfectly with opencv I removed blender python and pasted a copy of the system python instead. According to "blender.stackexchange.com/questions/5287/using-3rd-party-python-modules"
this is an alternative from using blenders own python.
Numpy, Scipy imports work perfectly. Importing cv2 leads to the same error as before.
If I now start the system-python copy that now is blenders python from a command shell cv2 can be imported.
Where is the difference here in the environment blender creates and the one from the shell??
I have installed a tool named listDlls to list all the dlls loaded by specific processes in order to compare blender-python and python. You can see some differences but I dont understand the matter of those except from the absence of the cv2 pyd in blenders python.
Any ideas?
First list is the python-process list, second the blender list:
https://ufile.io/uidy1
https://ufile.io/1eshi
Related
I can't import modules of any kind. I know that I have the modules installed, and that they are inputted correctly, but it still does not work, and gives me this full error when trying to import numpy as np:
C:\Users\alecd\Desktop\Code\PYTHON\chess>C:/Users/alecd/AppData/Local/Microsoft/WindowsApps/python.exe c:/Users/alecd/Desktop/Code/PYTHON/chess/chess_board.py
Traceback (most recent call last):
File "c:/Users/alecd/Desktop/Code/PYTHON/chess/chess_board.py", line 3, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I keep all my code in a lot of folders, and when I take the code out of the folders it works. However I don't want all of my code to be in one massive folder. I tried creating a new PYTHONPATH, which I believe will work but I would have to append all of my scripts every time, which would be pretty inefficient.
I actually had the same problem a week ago and found out that I installed 2 python envs at once. One was from original website(python.org) the other was from Microsoft Store. I kept installing modules on one and using another to run my code.
If you are using some kind of text editor(I was using Visual Studio Code) you need to select the right environment for compiler.
On Visual Studio Code you change compiler from left-bottom corner
VSCode
I'm getting the error
Traceback (most recent call last):
File "ghs.py", line 1, in <module>
import stdio
ImportError: No module named stdio
When I try to run my script. I can run my script on other machines just fine. I have installed python using homebrew. And I've tried everything I can think of to get it to recognize my modules! I've uninstalled and reinstalled using brew. I've tried changing the path (though I don't fully understand this). I get no issues using brew doctor.
I've also tried using a python virtual environment but to no avail.
Any ideas on how to fix this issue or else 'start fresh' from a fresh version of python?
When you import a module, Python looks for it at the directory your code is, and the directory in which the built-in libraries are (C:\Users\pc\AppData\Local\Programs\Python\Python35-32\Lib in my case, I'm using Windows 10 and Python 3.5). If it can't find it, it raises ImportError.
I couldn't find a module named stdio in my computer. I also know some C++ and as far as I know, stdio is the library for inputs and outputs(prints). In python, there is no need to import such a library.
You can use try,except statement to test if your code works without importing the module like this.
try:
import stdio
except:
#rest of your code goes here
You will need to indent your whole code however this can be done easily with a text editor in which you can edit more than one line at a time.
I'm having problems trying to use Metakit for Python on Windows. It always report this error:
Traceback (most recent call last):
File "<pyshell#86>", line 1, in <module>
import metakit
File "C:\Python27\lib\site-packages\metakit.py", line 22, in <module>
from Mk4py import *
ImportError: No module named Mk4py
I've already:
Downloaded metakit.py and Mk4py.dll from http://equi4.com/pub/mk/ (official release)
Copied metatkit.py to C:\Python27\lib\site-packages\
Copied Mk4py.dll to C:\Python27\DLLs\
I have installed Python 2.7.5 win32 version
Any idea to solve this problem?
I also had the same problem and couldn't get the system to work with the provided dlls. I also tried compiling metakit from source to make it work and installing it from an the official source via egg, which failed in the same way (as it compiles from source).
Using my older windows XP machine with visual studio 2002 I managed to build it from source and install it with just a minor change of the setup script (changing every instance of msvc60 to msvc70 in the setup script). However, copying those files to my windows 8 machine still failed, and even copying what appeared to be the changes were unsuccessful.
In the end I copied my entire python directory from the xp machine to the windows 8 machine and now it is working without issues.
Obviously i could provide my dlls but I doubt they would be any more successful than the provided ones.
My next step is to reduce my reliance on having to use metakit as it seems very poorly supported.
I'm using Mountain Lion at the moment.
I've installed Blender (because it's a dependency of OpenGrasp), and downloaded OpenGrasp. However, I try to load the robot editor up and I get this:
$ python GraspRobotEditor.py
Traceback (most recent call last):
File "GraspRobotEditor.py", line 34, in <module>
import Blender
ImportError: No module named Blender
How do I point Python to the Blender python interface? the Getting Started guide doesn't instruct you much here.
(I'm sure this is a trivial problem to solve but I'd like to see this documented on StackOverflow anyway.)
From the error you it can't find the python module Blender which represents the python hook to Blender. So there could be a few This could be any number of reasons to do with your setup.
The first is that the Blender module is runtime generated whileBlender is running. The specific 'Blender' module used is part of the Blender 2.4x series. According to the link you provided there, they mention porting to newer versions but checking their snv the code is definitely written for 2.49.
Blender 2.49b was the last stable release - http://download.blender.org/release/ Ensure you are using that.
The next thing is whether it can be run via the the Run Script command
TL:DR
Start up blender
Switch to the text workspace
Open the script and see if it can be run directly.
If not you will need to install the folder to the Blender modules directory of your install and then try running it.
Edit: Was looking at into the SVN some more and there does appear to be a version 2 for blender 2.5+ which can be put into a zip file and installed via the add-on installer. According to the bl_info it was build for 2.58 but what support level you would need to try out yourself.
so I'm on a Windows 8 and I'm doing some image analysis for my research. It requires running this python script (I did not write it) called "calculate_distances.py". I am also using CellTool (http://pantheon.yale.edu/~zp2/Celltool/) and Numpy which I have successfully installed.
When I try to run my calculate_distances script, I get this error:
Traceback (most recent call last):
file "calculate_distances.py" line 4, in <module>
import celltool.simple_interface as si
ImportError: No module named celltool.simple_interface
Here is my calculate_distances.py script:
#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# Import various celltool modules
import celltool.simple_interface as si
import celltool.contour.contour_class as contour_class
from celltool.utility.path import path
import celltool.utility.datafile as datafile
import numpy
# Designate your working directory - ie, replace '/parent_directory/' with the path that contains your contour files
#parent_dir=path('/parent_directory/')
parent_dir=path('./')
# Identify and load all of the contour files
contour_files=parent_dir.files('*.contour')
contours=si.load_contours(contour_files)
all_distances=numpy.arange(len(contours[0].points))
# Calculate the normal displacement of the cell boundary at every contour point.
n=1
while n<len(contours):
contour_class.Contour.global_reorder_points(contours[n],contours[n-1])
displacement_vectors = contours[n-1].points - contours[n].points
normals = contours[n-1].inward_normals()
distances = (normals * displacement_vectors).sum(axis=1)
all_distances=numpy.vstack((all_distances,distances))
n=n+1
# Save a csv file with the normal displacement of the boundary at each contour point (columns) at each time point (rows)
datafile.write_data_file(all_distances,parent_dir/'distances.csv')
I have no idea what the error means, as I'm a first-time programmer. First I thought I needed to install a C++/fortran compiler, so I installed Simple Fortran, but it still does not work. Everything works fine on Mac system (after I installed GNU fortran) but for some reason it's not working on Windows. Is it because my CellTool is not installed in the right location? Or is it something with the script?
Any ideas? Thanks very much for your help!!
You have two options then.
Try adding CellTool installation directory to your PYTHONPATH environment variable, if you haven't already (create this variable if necessary).
Search for something like celltool.dll or libcelltool.dll (or even celltool.py). See if it helps. If not :
Compile the source by following those few steps... Install MinGW (installer here), checking C/C++ (gcc/g++) and Fortran when asked by the installer. Then add C:/MinGW/bin (or whereever you installed MinGW) to your PATH environment variable. Download and unpack CellTool source package from the web site. Finally open a command shell (search for cmd program), change directory to the newly unpacked directory and build by typing :
python setup.py install
This should properly compile and install the celltool python package to the site-packages directory of your Python installation.
Option 2 is the sure/safe (but not easiest, I agree) way to get it work.