ImportError: No module named NetCDF - c++

I am trying to sort the following error but not getting the correct answer till now. Actually I am using Ubuntu 10.04 and I have installed netcdf-3.6.2 but even then i found this error, although I added the header like
import Scientific.IO.NetCDF
from Numeric import *
from NetCDF import *
But it does not make any impact and shows the following error:
ImportError: No module named NetCDF

If the module is Scientific.IO.NetCDF, then you need to do from Scientific.IO.NetCDF import * (and you don't need to do import Scientific.IO.NetCDF first). Also, importing everything is often a bad style, and should be avoided.

Related

Python/pyserial cx_freeze Compilation error: no module named tools

I am trying to compile a python code with cx_freeze in Windows 7, python 2.7, but it keeps giving me trouble because of pyserial. I tried to import the pyserial tools module in many different ways but I keep getting compilation errors:
import serial
import serial.tools
from serial.tools import list_ports
#I also tried:
#import serial.tools.list_ports
#from serial import tools
#import serial.tools.list_ports
#from serial import tools
The error message varies between:
ImportError: No module named tools
and
ImportError: No module named tools.list_ports
Any ideas on how to solve this issue? Thanks.

AttributeError: After converting python script to EXE by Pyinstaller

I have made a python script for calculations purposes, importing libraries, Tkinter, Pmw, sympy, math, tkfiledialog, webbrowser.
Now, by using Pyinstaller I convert it into an EXE application.
When I run it, it gives the error:
WindowsError: [Error 3] The system cannot find the path specified: 'C:\\Python27\\Earthing\\dist\\Earthing\\Pmw/*.*'
So, I copy and paste the entire Pmw directory on this location. However, after doing this, I get the error:
AttributeError: 'module' object has no attribute 'OptionMenu'
Now, how do I resolve this error? Please do help me sort this out.
I ran into the same problem. It is due to what I would call 'dynamic imports', made mostly in PmwLoader.py (placed in lib subfolder): PmwLoader loads all the files, and the they become attributes of Pmw global library.
The solution I found was to manually delete the line 'import Pmw' in all the wanted Pmw files (I only used PmwComboBox and PmwScrolledFrame). PmwCombobox and PmwScrolledFrame notably need to import other Pmw files, so I had to replace
import Pmw
by
import PmwBase
import PmwScrolledListBox
import PmwEntryField
import PmwTimeFuncs
and then do the same in PmwScrolledListBox and PmwEntryFiled.
The the fun is to solve the bugs --notably replace a lot of the MegaWidget by PmwBase.MegaWidget, and so on.
In the end, it does not take more than one hour.
Good luck!
t.

Spynner -- No Module named cookielib

I have written the below mentioned basic script using Python Spynner.
It works fine when running through IDLE.
However, when I try to convert it into exe using Pyinstaller and run the exe, It gives me the following error.
ImportError: No module named cookielib
I have searched a lot for solution but couldn't find any. Any help would be appreciated.
I am using Python2.7 (windows 7 32 bit)
Here is the code,
import spynner
b=spynner.Browser()
b.hide()
b.load('http://www.google.com')
b.snapshot().save('file.png')
b.close()

import C++ module, if fail: import Python version?

I have a Python pyd module written in C++. I also have a Python version of the module (which is much slower).
My question is, as I want the program to run on multiple OSs, can I try to import the C++ version in the program and import the slower Python version if that one fails (other OS, architecture)?
Yes, you can import some thing like this:
try:
import CppModule as Module
except ImportError:
import PurePythonModule as Module
Yes you can:
try:
import CppModule
except ImportError:
import PythonModule
Edit: This answer, while not incorrect, is not really useful. As #Best Games' answer shows, this only really useful if you import the module using a common name.

Matplotlib and WSGI/mod_python not working on Apache

Everything works as supposed to on the Django development server. In Apache, the django app also works except when matplotlib is used. Here's the error I get:
No module named multiarray.
Exception Type: ImportError
Exception Value: No module named multiarray
Exception Location: /usr/share/pyshared/numpy/core/numerictypes.py in <module>, line 81
Python Executable: /usr/bin/python
Python Version: 2.6.4
From the python shell, both statements work: import numpy.core.multiarray and import multiarray. Any ideas?
Thanks
As I'm looking over the numpy files, I found the multiarray module, which has an extension of 'so'. My guess, is that mod_python is not reading these files.
Problem solved. Here's what I did.
First of all, before I was getting the import error:
"No module named multiarray."
I was getting an error like this:
": Failed to create /some/dir/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"
By adding the pyshared folder to the PythonPath variable, this error went away and I got the import error.
So here's how I fixed it:
Removed the pyshared folder from the PythonPath variable.
Before importing the matplotlib module, add these lines:
import os
os.environ['HOME']='/some/writable/dir'
Next, before import matplotlib.pyplot or pylab, add these lines:
import matplotlib
matplotlib.use('Agg')
# 'Agg' or whatever your backend is.
This is documented here.
That's is! It's working on python2.5 for me now. But I believe it'll work on 2.6 as well.
On Win32 I solved a similar problem (not being able to load pyd modules through ISAPI_WSGI (IIS)) by downgrading from py2.6.5 to py2.5. It seems like this might be a Python bug that has been re-introduced. See for example this discussion.