How do I upgrade kernmagic to fix this ipython error? - ipython

I recently upgraded my Enthought Python distribution with
sudo easy_install -U ipython
However, when I start up ipython with the ipython command, I get an error:
David-Faux-MacBook-Air:core davidfaux$ ipython
Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep 7 2011, 09:16:50)
Type "copyright", "credits" or "license" for more information.
IPython 0.13.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
[TerminalIPythonApp] Error in loading extension: kernmagic
Check your config files in /Users/davidfaux/.ipython/profile_default
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/ipython-0.13.1-py2.7.egg/IPython/core/extensions.pyc in load_extension(self, module_str)
90 __import__(module_str)
91 mod = sys.modules[module_str]
---> 92 return self._call_load_ipython_extension(mod)
93
94 def unload_extension(self, module_str):
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/ipython-0.13.1-py2.7.egg/IPython/core/extensions.pyc in _call_load_ipython_extension(self, mod)
122 def _call_load_ipython_extension(self, mod):
123 if hasattr(mod, 'load_ipython_extension'):
--> 124 return mod.load_ipython_extension(self.shell)
125
126 def _call_unload_ipython_extension(self, mod):
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/kernmagic/__init__.py in load_ipython_extension(ip)
28
29 def load_ipython_extension(ip):
---> 30 activate(ip)
31 activate_aliases(ip)
/Library/Frameworks/Python.framework/Versions/7.2/lib/python2.7/site-packages/kernmagic/__init__.py in activate(ip, *args)
14 continue
15 magic_name = name[len('magic_'):]
---> 16 ip.shell.define_magic(magic_name, getattr(mymagics, name))
17
18 def activate_aliases(ip, *args):
AttributeError: 'TerminalInteractiveShell' object has no attribute 'shell'
I googled around, and many posts I found said to comment out this line in an ipython configuration file.
c.TerminalIPythonApp.extensions = ['kernmagic']
I find it sketchy to comment out an ipython file though... later, I found that kernmagic fixed the issue with ipython.
How do I upgrade kernmagic in my ipython distribution so that this error goes away?

This worked for me:
hg clone https://bitbucket.org/robertkern/kernmagic
cd kernmagic
python setup.py build
python -c "import setuptools;execfile('setup.py')" bdist_egg
egginst dist/kernmagic-0.0.0-py2.7.egg

You can comment/remove the line in your configuration file, there is no issues with that if you do not use kernmagic. Actually the .ipython/profile_xxx folder are made for people to change things.
Otherwise if you really want to upgrade kern magic, I suggest you uninstall, remove the files and reinstall it from the current source.
Also IIRC the kern magic issue does not come with raw IPython only with EPD, so you shouldn't be afraid of removing it from config files and system.

For those who are not running EPD's distribution of python (or if Rich's solution didn't work):
First of all, I'm running Python 2.7.5 |Anaconda 1.6.0 (x86_64)|, on Mac OS X 10.8.4.
As Matt has stated, it is easiest to simply comment out the line that looks like this:
# A list of dotted module names of IPython extensions to load.
c.TerminalIPythonApp.extensions = ['kernmagic']
I found this in:
~/.ipython/profile_default/ipython_config.py
It should be located around 1/3 of the way down. It's worth pointing out that this is a temporary solution - I have no idea what kernmagic does or if it's an important ipython extension.

Enthought has updated kernmagic, so Enthought's enpkg fixed the same problem for me on EPD 7.3 and ipython 0.13.1:
sudo enpkg kernmagic

I've just created a quick-and-dirty port of kernmagic to python3. It may also work when this problem arises under python-2.x.
Here is a link to the code. All you need to do is drop the entire kernlab folder into your site-packages directory. It seems to be a pure python library, so it ought to work on any platform.
Good luck!

I also faced this problem, I'm on windows environment, I found that line in
C:\Users\Li\.ipython\profile_default\ipython_config.py
As stated, it is easiest to simply comment out the line that looks like this:
# A list of dotted module names of IPython extensions to load.
c.TerminalIPythonApp.extensions = ['kernmagic']

Related

ModuleNotFoundError: No module named 'windows'

I'm working on a project and I need to use the PyMouse module.
pip install pymouse
installed pymouse correctly, so I assumed all was fine.
However, when importing PyMouse:
from pymouse import PyMouse
I got the following error running my program:
Traceback (most recent call last):
File "4opeenrij.py", line 1, in <module>
from pymouse import PyMouseEvent
File "C:\Users\lcdew\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pymouse\__init__.py", line 92, in <module>
from windows import PyMouse, PyMouseEvent
ModuleNotFoundError: No module named 'windows'
I can't seem to figure out what might cause this error message. Any help would be much appreciated.
Additional info:
I'm using Python 3.7 32 bit
Current pip version: 18.1
I have Windows 10
working on a 64-bit operating system
I had I look into this and became puzzled at first, so looked deeper.
It turns out that pymouse is absolutely full of errors. More that I bothered to find.
The error you got is just one of many errors caused by bad coding.
The code says:
from windows import PyMouse, PyMouseEvent
And it should say:
from .windows import PyMouse, PyMouseEvent
Also, PyUserInput, a sister package that is free from the pymouse errors, requires pyhook, which is unsupported by python 3. After a lot of looking around, the conclusion that there is no way around the problems found, except maybe installing a really early version.
You could also try the keyboard module.
You might want to take a look at pynput module. It works on python 3.8, doesn't have any incompatible dependencies, and doesn't seem to have any errors. Once you have the module installed, this page gives some good examples of various ways to manage the mouse.

autoreconf -fi error: possibly undefined macro: AC_DEFINE If this token and others are legitimate, please use m4_pattern_allow

My set up of autoconf is fairly new:
m4 (GNU M4) 1.4.17 and came with ubuntu
autoconf (GNU Autoconf) 2.69
My configure.ac is fairly simple:
30 ACX_PTHREAD([
31 AC_DEFINE([HAVE_PTHREAD], [1], [Define if you have POSIX threads libraries and headers])
32 gtest_LIBS="$PTHREAD_LIBS $LIBS"
33 gtest_CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
34 gtest_CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS"
35 gtest_CC="$PTHREAD_CC"
36 gtest_CXX="$PTHREAD_CXX"])
Running autconf gave me the error:
autoreconf -fi
libtoolize: putting auxiliary files in '.'.
libtoolize: copying file './ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
configure.ac:31: error: possibly undefined macro: AC_DEFINE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
I believe that my ACX_PTHREAD macro is giving me trouble. I looked into the definition of this macro and did not find anything strange. There are suggestions that this is caused by the missing pkg.m4 in other situations. I verified that the latest version pkg-config is installed on my system. The pkg.m4 is present on my system: /usr/share/aclocal. I have been researching a solution for this problem and could not get anywhere.
My problem turned out to be due to the lack of axc_pthread.m4 file. This is how I discovered it:
autoreconf -fi gave the error message. If I run autoreconf -i then the program will run silently without any error messages. The run ./configure will reveal the problem at the line where ACX_PTHREAD(...) is copied verbatim to the configure file. This indicates that the ACX_PTHREAD macro is not defined in my system.
The download link is at: http://ac-archive.sourceforge.net/ac-archive/acx_pthread.html. After some research, there seems to be many sources providing this macro definition. Not sure which one is better. But I am eager to get this problem solved. After coping this file into my projects's m4 directory, my problem got resolved. Hope this may help others. The problem with autoconf is that usually a problem shows a wrong symptom.

I had installed perl module, parse::recdescent, still I m getting module not installed error

I m trying to create charts for excel from perl script.
I have perl 5.22 version.
I installed perl module parse-recdescent.
I can verify its presence in my Unix box with the command instmodsh.. And I can see this module installed.
I had successfully set the path for perl5lib.
But still when my script comes at chart->add_series() function, its failing with error below
The Parse::recdescent module must be installed in order to write an excel formula at line x
I had installed this module same as all other modules which works fine.
All paths looks correct...
Please help me.
Update:
Error message: "The Parse::RecDescent module must be installed in order to write an Excel formula at charts4.ps line xxx
Here you can see i installed perl modules and Parse::RecDescent is there. I used instmodsh command...
Installed modules are: Parse::RecDescent
i am using PERL5LIB to set the paths of all modules..
my PERL5LIB looks like below:
/home/xxx/perl/Parse-RecDescent-1.967013/blib/lib/Parse
and you can see .pm is there in this path
$ cd /home/xxx/perl/Parse-RecDescent-1.967013/lib/Parse
$ ls -ltr total 440 -rw-r--r-- 221678 Sep 27 12:28 RecDescent.pm
FYI - This unix box has already a perl installed.. but i had installed my own version. and when i type perl -v it is giving my own version.. perl 5 vesrion 22 as expected. and i had installed many modules in the same way and all are working fine. except this... Want to know whats going wrong?
i am using PERL5LIB to set the paths of all modules..
my PERL5LIB looks like below:
/home/xxx/perl/Parse-RecDescent-1.967013/blib/lib/Parse
and you can see .pm is there in this path
$ cd /home/xxx/perl/Parse-RecDescent-1.967013/lib/Parse $ ls -ltr
total 440 -rw-r--r-- 221678 Sep 27 12:28 RecDescent.pm
Some weirdness here. You say that you have installed Parse::RecDescent, but this doesn't look like an installed version. This looks like a directory that is used as part of the installation process, not the final result. How did you install the module?
But despite the fact that this isn't really where you should be using this module from, it should still work if you set PERL5LIB correctly. You have an extra Parse on the end of your directory. As the module is in Parse/RecDescent.pm the correct value for PERL5LIB will be /home/xxx/perl/Parse-RecDescent-1.967013/blib/lib/.
I really recommend that you install this module properly.

Boost.Python __init__() should return None, not 'NoneType'

I have a whole bunch of working C++ code that I want to write Python bindings for. I'm trying to use Boost.Python since it seems to be the easiest way to get this working, but it isn't cooperating. Here's part of the code for the extension module I'm trying to build:
BOOST_PYTHON_MODULE(libpcap_ext) {
using namespace boost::python;
class_<PacketEngine>("PacketEngine")
.def("getAvailableDevices", &PacketEngine_getAvailableDevices);
}
Bjam seems to be a pain and refuses to recognize my Pythonpath or allow me to link with libpcap, so I'm using CMake. Here's my CMakeLists file, which can import and build everything just fine (outputs libpcap.so as expected):
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG")
#SET(CMAKE_BUILD_TYPE "RELEASE")
#SET(CMAKE_BUILD_TYPE "RELWITHDEBINFO")
#SET(CMAKE_BUILD_TYPE "MINSIZEREL")
ENDIF()
FIND_PACKAGE(Boost 1.55.0)
find_package(PythonLibs REQUIRED)
IF(Boost_FOUND)
INCLUDE_DIRECTORIES("${Boost_INCLUDE_DIRS}" "${PYTHON_INCLUDE_DIRS}")
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREADED ON)
SET(Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE(Boost 1.55.0 COMPONENTS python)
ADD_LIBRARY(pcap_ext MODULE PacketWarrior/pcap_ext.cc PacketWarrior/PacketEngine.h PacketWarrior/PacketEngine.cc PacketWarrior/Packet.h PacketWarrior/Packet.cc)
TARGET_LINK_LIBRARIES(pcap_ext pcap)
TARGET_LINK_LIBRARIES(pcap_ext ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
ELSEIF(NOT Boost_FOUND)
MESSAGE(FATAL_ERROR "Unable to find correct Boost version. Did you set BOOST_ROOT?")
ENDIF()
ADD_DEFINITIONS("-Wall")
And my pcap.py file that attempts to utilize the module:
import libpcap_ext
engine = libpcap_ext.PacketEngine()
print engine.getAvailableDevices()
But whenever I try to run the module, I get the following error:
Traceback (most recent call last):
File "../pcap.py", line 2, in <module>
engine = libpcap_ext.PacketEngine()
TypeError: __init__() should return None, not 'NoneType
I'm assuming it's because Boost.Python is trying to use Python 3 and my system default is Python 2.7.3. I've tried changing my user-config.jam file (in my boost_1_55_0 directory) to point to Python 2.7 and tried building:
# Configure specific Python version.
# using python : 2.7 : /usr/bin/python2.7 : /usr/include/python2.7 : /usr/lib ;
Boost.Python's installation instructions [0] seem to fail for me when I try to build quickstart with bjam (lots of warnings), so I tried following the Boost Getting Started instructions [1] to build a Python header binary, which is I think what is causing this problem. Any recommendations as to how to fix this would be amazing, I've spent hours on this.
This error is probably due to linking against the wrong Python library. Make sure your extension as well as the Boost Python library are linked against the Python installation you are using to import the module.
On Linux you can check against which libraries you've linked with ldd. On OS X otool -L does the same thing. So, for example
otool -L libpcap_ext.so
otool -L /path/to/libboost_python-mt.dylib
should list the Python library they are linked against.
With CMake you can use the variable PYTHON_LIBRARY to change which Python library is used. As an example, on the command line you can set it with
cmake -DPYTHON_LIBRARY="/path/to/libpython2.7.dylib" source_dir
Lastly, on OS X a quick and dirty way (i.e. without recompiling) to change the dynamically linked libraries is install_name_tool -change.

Coffeescript compilation fails for no apparent reason

When I try to compile this script (first.coffe):
some_object =
property_a : 123
property_b : "hello"
I get following error:
In first.coffee, Parse error on line 2: Unexpected 'INDENT'
but when I use "try coffeescript" functionality of coffeescript website, everything seems to work fine, because output is exactly this:
var some_object;
some_object = {
property_a: 123,
property_b: "hello"
};
What am I doing wrong? I work on Ubuntu, so coffescript was installed from repositories.
It might have something to do with your text editor. I know I've had trouble before with indent settings and line endings. Try opening it up in a different editor if you are using VIM.
Ubuntu 11.10 has an up-to-date CoffeeScript package. Older versions of Ubuntu may have a CoffeeScript package that is too old. If you are using an Ubuntu older than 11.10, uninstall that package and install a newer CoffeeScript.