Numpy.matrix not recognized - python-2.7

New to python; running windows. I am using python27, and ran the following code. It failed, even though it recognized numpy. Then, I made sure that numpy was installed by running pip install numpy. Reran the code and had the same problem: numpy was recognized, and a list of classes in the auto-suggest populates, but not numpy.matrix. I can't seem to find any indication that this should be a problem. It seems to just work...
import numpy
board = numpy.matrix([0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0])
It compiles, but the numpy.matrix still has a red line under it. the popup message when I mouse over it says: undefined variable from import: matrix
How do I enable the matrix class?
Or am I dealing with a Liclipse error? (Liclipse is my IDE)
Numpy is getting imported from:
module 'numpy' from 'C:\Python27\lib\site-packages\numpy\__init__.pyc'

Related

pep8 gives strange failures when typing module is combined with matplotlib or tensorflow

I'm getting a strange errors when running pep8 in Python2.7 on files using the typing module.
If I make a file my_file.py containing
import typing
import tensorflow
Then py.test -k pep8 my_file.py gives Segmentation fault (core dumped). Removing either of the two imports, or reversing their order, stops the error. This only seems to happen in pep8, not when running normally in Python.
It causes a different error with matplotlib:
import typing
import matplotlib
Here, py.test -k pep8 pepcheck_file_a.py gives E RuntimeError: maximum recursion depth exceeded while calling a Python object.
As I mentioned, in either case, reversing the import order to:
import tensorflow
import typing
Stops the error.
It's annoying in a large codebase to have to make sure that typing is always imported after various other packages (one has to manually rearrange the imports in each file).
Is there some easier solution to this?

Using pyinstaller on parmap causes a tkinter matplotlib import error. Why?

Update
If I try downgrading from Pyinstaller 3.2 to 3.1 I instead get the following traceback when I try to run the executable.
I tried adding --hidden-import=collect_submodules('pkg_resources._vendor') to pyinstaller as noted here but it had no effect. Same error. This appears to be due to an issue with setuptools. I'm using 26.0.0. Downgrading to 19.3 that many sources say fixes the issue does indeed fix this issue but then I'm back to the issue I have below.
I have a python 2.7 pyqt4 project I'm trying to turn into an .exe using pyinstaller. I use:
pyinstaller --additional-hooks-rir=. --clean --win-private-assemblies pipegui.py
pipegui.py can be found on github here
I get a working executable and the app appears functional. Here is what the terminal spits while pyinstaller is freezing. However the app crashes when I run particular parts of my program. It crashes and the terminal goes in a loop continually outputting the same traceback below with "Poolworker-X" at the very top continually incrementing:
As you can see tkinter is implicated, despite the word "tkinter" appearing nowhere in my project (using pyqt4). I am making use of matplotlib though and from answers discussed here and here I have added the following to the top of pipegui.py my main script:
from Tkinter import *
import Tkinter
import FileDialog
This however seems to be a step in the wrong direction because after freezing with this (and the same flags as before) my executable wont even open and instead I get this:
Here is pyinstaller's pretty-much identical output while freezeing. Remember all I did was add those 3 import statements above. That's it.
I also tried pyinstaller --additional-hooks=. --clean --win-private-assemblies --hidden-import=Tkinter pipegui.py and it made no difference. I'm completely perplexed as to why trying to import tkinter is doing this. Will fixing this traceback lead me closer to solving the other?
I only figured out after trying all this that the only parts of my executable that are crashing are parts that make use of parmap multiprocessing. Classes that make use of matplotlib but not parmap are working fine.
So please note my question is how the first traceback can be fixed and also why are both matplotlib and tkinter popping up in the traceback despite my code where the crash occurs making use of niether?
Extra notes
I use --clean --win-private-assemblies to fix error code 14001 as per here
Repiklis provided the solution in the comments. Further note that as of January 15 2017 Pyinstaller version 3.2.1 was released. I now use this and it solves this issue along with others like this and this that I could previously only solve by using the developer version. So I highly recommend upgrading to the latest version if you haven't already.

Importing Numpy in embedded Python c++ application

I would like to have a script invoke numpy from a c++ embedded python runtime by setting the runtime path to know about the numpy module located within site-packages.
However I get the error:
cannot import name 'multiarray'
from \Lib\site-packages\numpy\core__init_.py on the line
from . import multiarrray
I have tried to set the os.path to be xxx\numpy\core but it still cannot seem to find the multiarray.pyd file during the import statement
I have read through similar questions posed but none of the answers seem relevant to my case.
I am using Python 3.4.4 (32 bit) and have installed Numpy 1.11.1 using the wheel
numpy-1.11.1-cp34-none-win32.whl
python -m pip install numpy-1.11.1-cp34-none-win32.whl
Completed without any errors.
Seems like the failure message maybe more general than just an incomplete PYTHONPATH?
Also think it might be broader than Numpy in that ANY .pyd based package that is imported from the embedded environment will have this problem?
Any help appreciated.
Did you ensure all your NumPy includes: \numpy\core\include\numpy\ were present during the build? That's the only time I get those types of errors was if the build couldn't find all the NumPy includes... although during embedding I found that the numpy entire directory (already built on your build machine) has to be inside a directory under Py_SetPath(python35.lib;importlibs); assuming importlibs is a directory with NumPy inside and anything else you want to bundle.
Seems like the answer was to install python 3.4.1 to match the python34.dll version of 3.4.1.

mvpa2.suite: Runtime warning and erro in Python 2.7.6

I just installed mvpa2 module on my ubuntu 14.04, Python 2.7.6. following the instruction at http://www.pymvpa.org/installation.html using sudo aptitude install python-mvpa2
Command import mvpa2 works well, but when I run from mvpa2.suite import * , I get the followin warning in my terminal:
/usr/local/lib/python2.7/dist-packages/sklearn/pls.py:7: DeprecationWarning: This module has been moved to cross_decomposition and will be removed in 0.16
"removed in 0.16", DeprecationWarning)
And also fallowing error:
TypeError: __init__() got an unexpected keyword argument 'rho'
Appreciate your help!
actually this warning comes from the import done by mdp, which PyMVPA optionally uses... you can safely ignore it (no upgrade of PyMVPA would help anyhow), because even if it gets completely removed, then mdp would simply skip that import and you would remain 'golden'.
That problem is due to an incompatibility of the python-mvpa2 and scikit-learn versions. You can check more details on that in this page, because depends on which scikit-learn version you have what will be the parameters to call a given function.
A short solution is to uninstall your python-mvpa2 and scikit-learn, and install them directly from their github repos:
[python-mvpa2] https://github.com/PyMVPA
[scikit-learn] https://github.com/scikit-learn/scikit-learn
I just did it and now the example doc/examples/som.py (for my case) is working perfectly.

py2exe can't find msvcp90.dll

I'm working on converting a simple GUI script written with Python 2.7 and Pyqt4 into a standalone executable using py2exe. I keep getting "no such file exists" errors, and I've managed to fix a few, though this one seems stubborn. It can't find msvcp90.dll, and returns an error message with a short traceback to distutils and then back to my py2exe script, which isn't very enlightening.
I've installed the MS C++ redistributable runtime, as recommended in
py2exe fails to generate an executable
but my script still can't locate the .dll. Below is my py2exe script, with the name of my script blocked out:
from distutils.core import setup
from py2exe.build_exe import py2exe
import sys, os, zmq
sys.argv.append('py2exe')
os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]
setup(
options = {'py2exe':{'bundle_files':1,"includes":["zmq.utils",
"zmq.utils.jsonapi","zmq.utils.strtypes"]}},
console = [{'script':"#######.py"}],
zipfile = None
)
I've already fixed an issue with zmq (which isn't ever used by my script, or my GUI, for that matter, as far as I know). What am I doing wrong?
Right, I've managed to get my app to build, and although the question is now moderately old, it's my hope this is eventually of use to someone.
Firstly, py2exe is probably the wrong tool. It's old and AFAICT unmaintained. Consider PyInstaller instead. Using PyInstaller is literally as simple as installing it, installing PyWin32, and then going python %path_to_pyinstaller%/pyinstaller.py --onefile --windowed source.py. PyInstaller deals with all the mess of side by side assemblies and so on without you having to do anything.
In short, use PyInstaller.
However, to answer your question, this worked for me:
The question you've linked to - in particular this answer is the right start. Find the right DLLs and copy them to C:\Python27\DLLs
Ditch your existing setup.py file. If you're not using zmq, there's no reason to import it. Also, for a windowed application you want windows= not console=. My file goes (for packaging show.py):
#!/usr/bin/python
from distutils.core import setup
import py2exe
setup(options={'py2exe':{'bundle_files':1}},
windows=['show.py'])
(This is pinched off http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/)