Import module CairoPlot fails in Python - 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.

Related

Package listed with pip but cannot be imported

I am writing my own package for a test with setup.py. I tried to install it on my own computer with python3 setup.py install, and there was no error. I checked with pip3 list and found it there,
steplib 0.1.0
However, when I tried importing it in a python interpreter, I could not,
>>> import steplib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'steplib'
Using help('modules') confirmed this as it was not shown in the list.
Am I doing anything wrong? Do I have to register it first before using it?
edit
My site packages contains steplib-0.1.0-py3.7.egg-info. It does not have any sub-packages (it is a test package):
steplib
__init__.py
steplib.py
setup.py
Ideally module should go into your site packages. Do you see it there?
If its there then check your package path. You package may be steplib, but have you checked if you are importing right package and module there. For example within your steplib folder you might have additional package and module within it. Say package is X and module is Y. Then you can import it as below.
from X import Y
Make sure you have init.py in your package to qualify that as a package.
Did you install the package in the python directory under Lib?

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'.

Custom python install location: tkinter problems

I'm using Ubuntu 14.04. While I have to retain my "main" python install as 2.7.6, I need to install 2.7.9 to be able to use ssl.SSLContext, to get Flask to deal with HTTPS requests.
However, if I just do:
sudo make install
or
sudo make altinstall
in the Python-2.7.9 directory, I ultimately get:
make: *** [libinstall] Error 1
EDIT: this appears at the end of sudo make install:
...
Compiling /usr/local/lib/python2.7/xml/sax/saxutils.py ...
Compiling /usr/local/lib/python2.7/xml/sax/xmlreader.py ...
Compiling /usr/local/lib/python2.7/xmllib.py ...
Compiling /usr/local/lib/python2.7/xmlrpclib.py ...
Compiling /usr/local/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1
So I installed it to a custom directory by modifying the call to ./config, which did not yield the libinstall error.
However, when I try to import Tkinter into Python 2.7.9 (running from the custom directory) I obtain:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/repos/Python279/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
If I just go ahead and install the vanilla way (i.e., to a non-custom directory) and simply ignore the libinstall error I get, upon importing Tkinter:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: /usr/lib/python2.7/lib-dynload/_tkinter.so: undefined symbol: PyFPE_jbuf
Does anyone have any idea what is going on?
Following furas' suggestion, installing via the
Python 2.7 PPA maintained be Felix Krull worked spectacularly. Thanks Furas!
EDIT Some notes:
Because this PPA installs python2.7 (specifically v. 2.7.11, as of 1/29/2016), this obviated the need for a custom python install location
While the PPA website mentions that this doesn't include python-tk, provided you have installed it, python plays with it just fine (solving my problem)
First of all source code from a program must be configured, compiled, then installed. You can do this by:
./configure # Or ./config depending on the file name
make
make install
Second of all when you tried to import the module _tkinter you wanted to import the .py file which was called Tkinter.py
Try to use:
import Tkinter

Error during library import in Python (Windows)

I am trying to configure svn hook for email notification using mailer.py script from apache, but it always crash on import of svn libs. I try two ways of installing svn and python. I try to install everything manually using command line and use CollableNet installer that have preinstalled Python and all libs I need but result is the same.
Now I try to import one library from hole package that I need using python in command line and I have such response:
>>> import svn.core
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named svn.core
I try to fix it using:
1) import sys; sys.path.append("C:\csvn\lib\svn-python\svn")
and
2) C:\csvn\lib\svn-python\svn>python "\__init__.py" install
But it didn't help.
For now I have no package with setup.py to install it.
I spend a lot of time on this task, and going crazy a little). Please give me any suggestion how to fix it.

Import VTK in Python Interpreter

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.

Categories

Resources