How to set up a windows cython environment from scratch? - cython

I have been searching on the internet for hours to find out how to make cython work with no success.
I am on windows , i use python3 with Anaconda and i also have Codeblocks using the mingw GCC compiler.
I would like to be able to run even the most basic code (like 'helloworld') with cython because untill now i've only encountered errors i don't understand. They may come from an unstable developping environment so this is why i ask this question.
The main errors happen when translating the .pyx code to .c and even when i achieve that there are even more errors on the .c generated.
here is my 'helloworld.pyx' :
print('Hello Wolrd')
here is my setup.py :
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize('helloworld.pyx'))
when i run python3 setup.py i get ModuleNotFoundError: No module named 'Cython'
when i run cython helloworld.pyx , I get a file helloworld.c
but when i run it in Codeblocks i get the error Python.h : no such file or directory
so i temporary fixed it by puting the absolute path in the include command but i still get errors.
i also tried using python setup.py build_ext --inplace but i get
running build_ext
building 'helloworld' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -DMS_WIN64 -IC:\Users\Julien\anaconda3\include -IC:\Users\Julien\anaconda3\include -c helloworld.c -o build\temp.win-amd64-3.7\Release\helloworld.o
In file included from C:\Users\Julien\anaconda3\include/Python.h:87:0,
from helloworld.c:4:
C:\Users\Julien\anaconda3\include/pytime.h:123:59: warning: 'struct timeval' declared inside parameter list
C:\Users\Julien\anaconda3\include/pytime.h:123:59: warning: its scope is only this definition or declaration, which is probably not what you want
C:\Users\Julien\anaconda3\include/pytime.h:131:5: warning: 'struct timeval' declared inside parameter list
C:\Users\Julien\anaconda3\include/pytime.h:136:5: warning: 'struct timeval' declared inside parameter list
helloworld.c:201:41: warning: division by zero
helloworld.c:201:12: error: enumerator value for '__pyx_check_sizeof_voidp' is not an integer constant
error: command 'C:\\MinGW\\bin\\gcc.exe' failed with exit status 1
I followed tutorials to install mingw (it works for coding in C in codeblocks so I should have installed it properly) and I verified that Cython was correctly installed in Python libraries. What did I do wrong ??

Ok so the problem was effectively in the compilers.
the problem was because my mingw compiler was not correct : i suggest following
these instructions which you will find at https://wiki.python.org/moin/WindowsCompilers.
/!\ do not forget to install setuptools on your python environment (using the command given works for me)
this should at least allow you to make the basic tutorial for cython

Related

How to install HTML package for python3.7

I want to install HTML package for python3.7 but It's is giving error while installing
I tried command pip install html but getting errors in console
ModuleNotFoundError: No module named 'html.parser'; 'html' is not a package
Command "python setup.py egg_info" failed with error code 1 in C:\Users\username\AppData\Local\Temp\pip-install-apo0cgnw\html\
I am getting the same error: archlinux running a virtualenv. I'm looking around it appears to be a problem with a file in there called 'six.py'. Not sure what the problem is but it appears the project has been orphaned because it was consistently updated until 2011. (Also not sure what all of this code is doing in there, similar libraries like 'vapory' are much smaller. - less bloat, less stuff to go wrong) I would suggest either trying it on Python2.x (since it appears that's where it was developed), contacting the developer, or using a different package.
1) download the .tar.gz file OR .zip file according to your OS from this
link .
2) After downloading , install that downloaded package by the following code : pip install ./downloads/SomeProject-1.0.4.tar.gz
And then again follow the below step
You can import the html package as shown below. pip install is not required, as html comes with the Standard library, post Python v3.x,
>>> from html import HTML
>>> h = HTML()
>>> h.p('Hello, world!')
>>> print h # or print(h) in python 3+
<p>Hello, world!</p>
See the html 1.16 project description for more detail .

can't find any solution for running f2py correctly on my windows 7 machine

Can someone pinpoint where I'm doing wrong, PLEASE? I'm so exhausted. I installed MinGW 4.7, python2.7.8, numpy 1.7.1 and scipy0.13.2 to an Anaconda (32bit) environment in Windows7.
Also, for user enviroment variables, I set
C_INCLUDE_PATH:
D:\Anaconda2\envs\arc103\MinGW\i686-w64-mingw32\include
Path (User variable):
C:\Program Files (x86)\Microsoft VS code\bin;D:\Anaconda2\Library\bin;D:\Anaconda2\envs\arc103\MinGW\bin
Tying the following commands in Anaconda Prompt
"f2py -c --help-fcompiler" outputs "... Fortran compilers found:
--fcompiler=gnu95 GNU Fortran 95 compiler (4.7.0) ...."
"f2py -c --help-compiler" outputs
"List of available compilers: ...", not specifically compilers found though.
Running "f2py -c fib1.f -m fib1" according to "NumPy v1.12.dev0 Manual" gives me lots of error as below:
D:\Anaconda2\envs\arc103\Scripts\gfortran.bat -Wall -Wall -shared c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-.7\fib1module.oc:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fortranobject.o c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\fib1.o -Ld:\anaconda2\envs\arc103\mingw\lib\gcc\i686-w64-mingw32\4.7.0 -LD:\Anaconda2\envs\arc103\libs -LD:\Anaconda2\envs\arc103\PCbuild -lpython27 -lgfortran -o .\fib1.pyd
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x35): undefined reference to `__imp__PyNumber_Int'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x68): undefined reference to `__imp__PyComplex_Type'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x79): undefined reference to `__imp__PyType_IsSubtype'
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o:fib1module.c:(.text+0x93): undefined reference to `__imp__PyErr_Occurred'
... (Thousands of "undefined reference to" errors I didn't put it here) ...
collect2.exe: error: ld returned 1 exit statuserror: Command "D:\Anaconda2\envs\arc103\Scripts\gfortran.bat -Wall -Wall -shared c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fib1module.o
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\users\dkim1\appdata\local\temp\tmpvyedhg\src.win32-2.7\fortranobject.o
c:\users\dkim1\appdata\local\temp\tmpvyedhg\Release\fib1.o -Ld:\anaconda2\envs\arc103\mingw\lib\gcc\i686-w64-mingw32\4.7.0 -LD:\Anaconda2\envs\arc103\libs
-LD:\Anaconda2\envs\arc103\PCbuild -lpython27 -lgfortran -o .\fib1.pyd" failed with exit status 1
Sorry for the mess. I have spent almost a few months finding out the fix, but it's too hard for me and all gone to no avail. It would be hugely appreciated if you can help me out. Thanks.
Since this is a couple month old, I am not sure if these tips will still help, but I found when building a Fortran to Python module on Win 10, that only compiling for 32bit worked, and you need to use a signature file, i.e. something along the lines of:
f2py.py -c cuncsd.pyf cuncsd.f
Instead of using the i686-w64-mingw32 toolchain I used a straight mingw32 one (to reduce the risk that I accidentally end up with anything 64bit).
I also found that you need to install a special Visual Studio for Python instance as described here:
Microsoft Visual C++ Compiler for Python 3.4
If you are using Python 2.7 this VSC version should do the trick for you, only newer version (3.5, 3.6) are left out at this time.
For reference here is my complete f2py invocation on the console that I ended up using (neither python nor f2py were on the execution PATH):
python C:\Python34\Scripts\f2py.py -c cuncsd.pyf --opt="-frecursive -fmax-stack-var-size=66560" cuncsd.f -llapack -lrefblas -ltmglib
This particular module depends on 32 bit LAPCK shared libraries that I compiled previously, and we found it even works on XP systems.
I later went back and tried to compile this for 64 bit, but eventually gave up, when I always encountered ld errors. I think going forward for Windows 10 it will be much easier to use the embedded Ubuntu to execute and extend Python.
(See How to enable Bash in Windows 10 developer preview? and Getting PyCharm to recognize python on the windows linux subsystem (bash on windows))

Kivy 1.8 and Cython 0.21.2

Using Buildozer I get 12 times:
#error Do not use this file, it is the result of a failed Cython compilation.
And eventually:
Command failed: ./distribute.sh -m "kivy" -d "myapp"
According to the Kivy docs, I use Cython 0.21.2.
See the full log.
Any help would be very much appreciated!
Looks like you have Kivy 1.8.0 installed, and you're building Kivy 1.9.0 with buildozer. You will need to uninstall or upgrade your system Kivy. This is a bug in Cython, because it is using the system-installed pxds before the local directory pxds.

Error during the installation of Cython

I have installed SimpleCV 1.3 powerpack in my Windows 8.1. Then i set up the required path. And then i installed pyreadline, PIL, pip, ipython via cmd. But when i tried to run easy_install cython, i'm getting the following error,
C:\Users\Ankit>easy_install Cython
Searching for Cython
Reading http://pypi.python.org/simple/Cython/
Best match: Cython 0.22
Downloading https://pypi.python.org/packages/source/C/Cython/Cython-0.22.tar.gz#
md5=1ae25add4ef7b63ee9b4af697300d6b6
Processing Cython-0.22.tar.gz
Running Cython-0.22\setup.py -q bdist_egg --dist-dir c:\users\ankit\appdata\local
\temp\easy_install-lvjvzj\Cython-0.22\egg-dist-tmp-aeuxtq
Unable to find pgen, not compiling formal grammar.
Compiling module Cython.Plex.Scanners ...
Compiling module Cython.Plex.Actions ...
Compiling module Cython.Compiler.Lexicon ...
Compiling module Cython.Compiler.Scanning ...
Compiling module Cython.Compiler.Parsing ...
Compiling module Cython.Compiler.Visitor ...
Compiling module Cython.Compiler.FlowControl ...
Compiling module Cython.Compiler.Code ...
Compiling module Cython.Tempita._tempita ...
warning: no files found matching '*.pyx' under directory 'Cython\Debugger\Test'
warning: no files found matching '*.pxd' under directory 'Cython\Debugger\Test
warning: no files found matching '*.pxd' under directory 'Cython\Utility'
Scanners.c
C:\Python27\include\pyconfig.h(227) : fatal error C1083: Cannot open include file: 'basetsd.h': No such fil
e or directory
error: Setup script exited with error: command '"C:\Program Files (x86)\Microsof
t Visual Studio 9.0\VC\BIN\cl.exe"' failed with exit status 2
Please help me out.
I'm using a double partition system Windows8/Xubuntu14.04LTS.
I had the same issue when attempting to install Cython onto Xubuntu via pip.
So I installed Cython with below command and and everything went ok.
bashsh $ sudo apt-get install cython
This is not the best fix. But, may worth a trial if you are really
looking to port an almost complete project to Windows8.
You compile your Python main (without main):
bash $ cython --embed -o prog.c prog.py
You may decide to install Mxe (MingW) gcc on linux and do
cross compiling or, as me, to compile directly in the windows8:
bash $ gcc -Os -IC:\Python27\include -LC:\Python27\libs -o prog.exe prog.c -lpython27 -DMS_WIN64
Hope this might be of any help.

Octave imread function

I installed latest Octave on Ubuntu 14.04 machine. However, when I tried to run imread command, it showed the following error message:
octave:12> imread('newfile.png')
error: imread: invalid image file: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: failed to load: /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/__magick_read__.oct: undefined symbol: _ZN6Magick5ColorC1Ehhh
error: called from:
error: /usr/share/octave/3.8.1/m/image/private/__imread__.m at line 181, column 7
error: /usr/share/octave/3.8.1/m/image/private/imageIO.m at line 66, column 26
error: /usr/share/octave/3.8.1/m/image/imread.m at line 107, column 30
Can someone please suggest how to solve it?
Thanks!
Following these steps worked for me [Author: Christoffer Cronström (hymyly)]:
Install the dev packages needed to build octave.
sudo apt-get build-dep octave
Get the official source package. Do this in a clean directory, because it will get polluted.
cd ~/some/suitable/directory
apt-get source octave
Build it. This took roughly an hour for me.
cd octave-3.8.2
dpkg-buildpackage
Either run it from the build directory:
./run-octave
...or most preferably install it over the official octave:
cd ..
sudo dpkg --install octave_3.8.2-4_amd64.deb
From: https://bugs.launchpad.net/ubuntu/+source/octave/+bug/1372202
How did you instal Octave? The error suggests that you're missing GraphicsMagick C++ interface (package libgraphicsmagick++3) but
if you installed Octave from Ubuntu's package manager you should not have had this problem; * if you compiled it yourself, Octave should have disabled imread completely and you'd have a very different error message.
So my guess is that you build it yourself, either with:
your own build of GraphicsMagick++ which are not being loaded anymore, you may need to add their path to the dynamic linker load path (either on /etc/ld.so.conf.d./graphicsmagick or define LD_LIBRARY_PATH);
the libraries from the package manager which you have since accidentally removed (since you did not install Octave from the repositories, your package manager will not know that libgraphicsmagick++ is installed for a reason).
Either way, the solution is easy. Install Octave from Ubuntu's package manager. One of the main reasons package managers exist is to avoid this type of problems, i.e., missing dependencies.