Import VTK in Python Interpreter - python

Goal: Trying to use VTK library in Python Interpreter.
What I did: I have installed VTK using CMake with option VTK_WRAP_PYTHON and Shared_Library enabled and build the VTK in visual studio and it has finished with all builds successfully.
Then I made the Python_Path.
Problem: When I try to import vtk library into python, I get the following error message:
>>> import vtk
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import vtk
File "...\VTK\VTKvisual\Wrapping\Python\vtk\__init__.py", line 42, in <module>
from vtkFilteringPython import *
ImportError: No module named vtkFilteringPython
Any thoughts that why this is happening?
Thanks

It looks like you've added the location of the VTK package directory, containing .py files such as "filtering.py" and "vtkFilteringPython.pyd", to your PYTHONPATH.
However, now you need to add both this directory and also the directory containing vtkFilteringPythonD.dll and the other DLLs to your PATH. The location of this directory depends on whether you've just run the build, or also the INSTALL target. Usually it's in "VTK\bin" or "VTK\bin\BUILDTARGET" somewhere, where BUILDTARGET is for example Debug or Release.

Try running sudo apt-get install python-vtk

If you're only using the Python wrappers, right now, you can just install it from PyPI. Just do pip install vtk and you'll get the current version (which is now 8.1).
Look here for the announcement.

Related

How to get numpy working properly in Anaconda Python 3.7.6

I am trying to use NumPy in Python. I have just installed Anaconda Python 3.7, and that all seemed to go smoothly. However, I cannot import numpy(using the line import numpy). When I do, I get the following error:
C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
from . import multiarray
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
from . import overrides
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
from . import core
File "C:\Users\jsmith\anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\jsmith\anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was:
DLL load failed: The specified module could not be found.
I can see it in the Enviorments tab of Anaconda Navigator, and when I try to use it in Eclipse(Pydev) it shows up under forced builtins. I took a look at my PYTHONPATH, and both my enviorment in Eclipse and my base python directory (jsmith/anaconda3) are in it. I have tried importing other libraries I see under forced builtins,and those work fine, yet numpy seems to be the only one with issues. Calling pip install numpy tells me it is already installed with version 1.18.1. I looked at this stack overflow page, and ran the first command in the answer(conda create -n test numpy python=3.7 --no-default-packages) in anaconda prompt. This worked, and then I realized the test was specific to the question, and tried base instead, and got this error:
CondaValueError: The target prefix is the base prefix. Aborting.
However calling conda activate base did nothing.
As mentioned in the comments by #cel uninstalling and reinstalling numpy using pip uninstall numpy and pip install numpy made it work.
I better way is to
import os
import sys
os.path.dirname(sys.executable)
This will give you the path to your environment. Put the path into the settings for python
Open the Anaconda Prompt:
Then, you have to go to the Conda Environment that you want to use in PowerBI. Am having an environment 'temp', so I activate it first in the 'Anaconda Prompt':
(base) C:\Users\ashish>conda activate temp
Then I go to the directory having the "PowerBI" executable file in the installation folder:
(temp) C:\Users\ashish>cd "C:\Program Files\Microsoft Power BI Desktop\bin"
Then, I launch PowerBI from the Prompt:
(temp) C:\Program Files\Microsoft Power BI Desktop\bin>PBIDesktop.exe
This fixes the NumPy error you are getting. If you want any other package to use with PowerBI, install that package in the respective "Conda Environment" (in my case it is "temp").
Make sure the Python home directory (Anaconda3) has been added to the 'Power BI Desktop' global options in the Python scripting section too.

Python cv2 linking problems while downgrading OpenCV from 3.0.0 to 2.4.11

So my case is a tricky one.
I first installed OpenCV2.4.8 and started it using for python2.7. Later I planned to migrate to OpenCV3.0.0. Both the times during installation I followed the official documentation procedure. Everything was working fine until I realized that OpenCV3 doesn't have SIFT() and SURF() modules. After a bit of searching I found they are present in opencv_contrib. First I tried to install that but for some reason I couldn't.
Later I found that these modules are present in OpenCV2.4.11 and planned to install that. Again following the official procedure I installed OpenCV2.4.11 got the same SIFT() importerror. Upon checking the OpenCV __version__ in python2 and python3 I found the following
python2: "2.4.8"
python3: "3.0.0"
For checking the version I used the following code:
from cv2 import __version__
print(__version__)
Unfortunately I don't have a lot of memory in /home, so I had deleted OpenCV2.4.8 and OpenCV3.0.0 build folders after installing. Therefore, I tried to manually remove OpenCV2.4.8 and OpenCV3.0.0 and deleted all opencv the libs from /usr/local/libs/ and sub-directories and all the opencv bins from /usr/local/bins/ (following answer in this question).
After removing all opencv files I again reinstalled OpenCV2.4.11 and tried to run my code. It failed at the import step in python2 giving
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.2.4: cannot open shared object file: No such file or directory
in python3
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libopencv_core.so.3.0: cannot open shared object file: No such file or directory
I again checked if OpenCV2.4.11 is present or not and its there but the python hasn't updated the previously stored link to opencv lib. I'm stuck at this error since 2 days with no solution. Any help will be appreciated.
EDIT:
Is there some shared library lookup file which python uses to store all the locations of shared libraries? If not how does this work (how python recognizes where to look for opencv as opencv is not listed in pip freeze)
EDIT2:
I found another mistake. I hadn't enabled -D BUILD_SHARED_LIBS=ON before. This time I kept it ON and rand sudo ldconfig after make and make install. Now I have a libopencv_core.so.2.4 in my /usr/local/lib/. It is a symlink to libopencv_core.so.2.4.11 present in the same folder. After ldconfig when I checked for python2 import cv2 didn't show any error but __version__ still shows '2.4.8'. I double checked for any OpenCV2.4.8 .so file and there are none. How is it still pointing to version '2.4.8'?
Steps for removal:
remove opencv libs by : sudo apt-get purge libopencv*
Verify that whether cv2 is uninstalled by trying import cv2 in python. It should show no cv2 module present
Install opencv2.4.11 by following this sh file
Run sudo ldconfig after sudo make install
Things should usually work but it didn't work in my case because cv2.so was missing from /usr/local/lib/python2.7/dist-packages/. For that manually copy from /<opencv-2.4.11 unzip locaiton>/release/lib/cv2.so to /usr/local/lib/python2.7/dist-packages/. Use sudo for permissions.
Now import cv2 will work and __version__ is '2.4.11'.

wxPython import error with Windows install

I have installed Python 3.4 and wxPython Phoenix on Windows 10. I go into Eclipse and add wxPython to the external libs in my project, but when I try to import it, I get this error:
Traceback (most recent call last):
File "C:\Users\linus\workspace\MiCS 1.2\main.py", line 1, in <module>
import wx
File "C:\Python34\Lib\site-packages\wx\__init__.py", line 17, in <module>
from wx.core import *
File "C:\Python34\Lib\site-packages\wx\core.py", line 6, in <module>
from ._core import *
ImportError: DLL load failed: The specified module could not be found.
I did some searching and tinkering and still can't figure out what's causing it. It shouldn't be the msvcp or msvcr DLLs as I have Office running just fine (or is that an incorrect assumption?) Any help is appreciated. Thanks.
How did you install wxpython?
As of now, the top page of the official site has wxpython 3.0 only for python27. So, I suspect you might not have installed it properly.
If you have your python34 at C:/Python34 then, cd to C:/Python34/Scripts first so that we make sure to use the pip for this python.
According to this post (https://groups.google.com/forum/#!topic/wxpython-dev/LmGIrQyh7jc), try
pip install -U --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
This should find the corresponding whl file for your python version and CPU architecture.
Or, you could manually download whl file at http://wxpython.org/Phoenix/snapshot-builds/
If you have 32 bit Python34, then look for ******-cp34-none-win32.whl
and simply do:
pip install path/to/the/whl/that/you/just/downloaded/wxPython_Phoenix-3.0.3.dev1839+4ecd949-cp34-none-win32.whl
After this, if you can import wx in the normal cmd then the problem should be coming from eclipse.

"cannot import name smbserver" when using impacket with smbrelayx.py

I know this is not an actual info-sec question, but I am having problems with getting the smbrealyx.py module to work. For some reason I get the following error when I try to execute the aforementioned python program.
Traceback (most recent call last):
File "smbrelayx.py", line 43, in <module>
from impacket import smbserver, smb, ntlm, dcerpc, version
File "/usr/lib/python2.7/dist-packages/impacket/smbserver.py", line 18, in <module>
from impacket import smbserver, version
ImportError: cannot import name smbserver
I am not familiar with python programming and I was hoping someone could help me fix this issue.
Looks like you have an old impacket version installed and you are using a newer version of smbrelayx.py.
First of it'd be great to know what version you have. You can easily do that by typing inside a Python interpreter the following:
from impacket import version
print version.BANNER
Assuming you have an old version, first of all it'd be great to remove the existing version. Depending on your Unix distro it might be just as easy as to remove the python-impacket package, or you can manually remove the library files by getting to know where those files are located:
import impacket
print impacket.__file__
That will give you the path where the library is installed. I'd suggest to remove the entire directory.
Now that your system is clean, you have two options:
Install a stable version: Grab the latest stable version from here. Uncompress it in a temp directory and then run:
python setup.py install
That will install the libraries and example scripts (e.g. smbrelayx.py)
Install the development version: You will need to git clone the development version first by running:
git clone https://github.com/CoreSecurity/impacket
Once the repo is cloned, inside the impacket directory type:
python setup.py install
That will install the libraries and example scripts (e.g. smbrelayx.py)

Import module CairoPlot fails in Python

I'm using cairo plot to draw charts with python. I followed the instruction as stated on the website to install Cairplot, http://linil.wordpress.com/2008/09/16/cairoplot-11/ :
sudo apt-get install bzr
bzr branch lp:cairoplot/1.1
The installation completes successfully.
I then try to import the modules in python:
>>> import CairoPlot Traceback (most recent call last): File "<stdin>",
line 1, in <module> ImportError: No
module named CairoPlot
>>> import cairo
>>>
Importing cairo is fine, but I can't figure out why I am not able to import CairoPlot.
bzr branch lp:cairoplot/1.1 creates a directory called 1.1 in your current working directory. Inside you'll find CairoPlot.py. Move CairoPlot.py into a directory which is listed in your PYTHONPATH, or edit your PYTHONPATH to include (the unfortunately named) 1.1.
Is the directory where CairoPlot is installed in your $PYTHONPATH? Do you need to run any setup scripts, like setuptools?
The repository appears to include a setup.py file, so you likely need to run setuptools to fully install the module.

Categories

Resources