I'm trying to compile and use the PyGRIB module. There is no binary distribution of the module, so I have compiled using Cygwin. I would really like to be able to use the module in my windows python installation -- I already have numpy, matplotlib, and a development environment setup for my windows installation. How do I do this?
It looks like the Cygwin install creates the following two files:
pygrib-1.9.3-py2.6.egg-info
pygrib.dll
in my c:\cygwin\lib\python2.6\site-packages directory.
I have tried copying these to: C:\Python27\Lib\site-packages but that doesn't seem to do the trick.
If I can't do this, can I get IPython in Cygwin? I haven't seen it in the setup utility.
Honestly, the easiest way to compile on windows when using python is to just use the free visual studios distribution. I've installed many different packages that way and never had an issue. Normally, the installation will place the path variable on your path, but you will need to verify that.
You need to make sure to use 2008 though, and not 2010.
You can retrieve it from here:
http://msdn.microsoft.com/en-us/express/future/bb421473
Do note, if you go this way, it will mean you will have to reinstall any other compiled python binary packages (numpy, scipy, etc)
That said, I notice you are downloading a 2.6egg to a 2.7 distro. Off the top of my head, I'm not certain that 2.6 and 2.7 were compiled using the same compiler, but I believe they were. In any event, that could be your problem, either the package doesn't support 2.7, or 2.6 doesn't compile with the same compiler as 2.7.
Related
To preface: my code works as I expect when compiling and running on Linux. However, this library needs to be compiled for use on a Windows machine. I looked in to a couple different options, and decided that using Cygwin to compile for Windows seemed to be the correct choice. I'm using a setup.py file with the distutils.core library and compiling using python setup.py install. When compiling on Windows in Cygwin, it fails to find pthread.h, arpa/inet.h, netinet/in.h, and sys/socket.h. I was under the impression that Cygwin came prepackaged with these headers, which is why I chose to use it. The alternative to Cygwin is putting preprocessor commands everywhere and using Windows specific libraries such as winsock2.h, which I want to avoid if at all possible. Is it possible to compile for Windows using Cygwin? If so, what have I done wrong to cause Cygwin to not recognize these headers?
You need to install the proper headers
$ cygcheck -p usr/include/pthread.h
Found 9 matches for usr/include/pthread.h
cygwin-devel-3.0.7-1 - cygwin-devel: Core development files
..
cygwin-devel-3.1.6-1 - cygwin-devel: Core development files
...
so install the cygwin-devel package
To check all the shared libraries needed by the built dll, you can use cygcheck
$ cygcheck /usr/lib/python3.8/site-packages/Cython/Compiler/FlowControl.cpython-38-x86_64-cygwin.dll
D:\cygwin64\lib\python3.8\site-packages\Cython\Compiler\FlowControl.cpython-38-x86_64-cygwin.
dll
D:\cygwin64\bin\cygwin1.dll
C:\WINDOWS\system32\KERNEL32.dll
C:\WINDOWS\system32\ntdll.dll
C:\WINDOWS\system32\KERNELBASE.dll
D:\cygwin64\bin\libpython3.8.dll
D:\cygwin64\bin\cygintl-8.dll
D:\cygwin64\bin\cygiconv-2.dll
D:\cygwin64\bin\cyggcc_s-seh-1.dll
As was built with Cygwin Python, you need also to transfer the cygwin python...
Most important, I think, is to follow the instructions in the Python help or on the Python doc web site for "Extending and Embedding the Python Interpreter" for the version you are building the extension for. For windows, the build instructions identify the build environment used to create the binary package that you download from python.org, usually something like VS2013 or VS2017. (As an aside, I think the Community editions have everything you need, and I don't think you actually have to use the Visual Studio GUI when you build using nmake from the CMD.EXE terminal.)
To build in Cygwin for use in a Windows version of Python, you may need to install and then use the x86_64-w64-mingw32-gcc, etc., cygwin packages to cross-compile non-cygwin (i.e. pure windows) executables and DLLs from Cygwin.
Binary extensions must be built using the source tree for a specific Python major.minor version, and bitness. For windows, you will need to build multiple versions of the extension, one for each major.minor, bitness version of Python that will import it, e.g. 3.6, 3.7, 3.8, 3.9, 32-bit, 64-bit. The extension code may not require changes between versions, but it still needs to be compiled with the right compiler and linked against exactly the same shared libraries (in this case .DLL files) as used by the Python executable. For instance, it must use exactly the same version of Microsoft's C run time library DLL as the Python executable does. This is a bit more sensitive and restrictive than on Linux, where you can rebuild the python executable and your extension with the same toolchain from your distro more easily.
I'm trying to get the HDBSCAN package to run on a Windows 7 machine with no C++ compiler. Installing a compiler is not an option, unfortunately.
I read that some packages have precompiled wheel files that require no compiler to install. The installation notes state "Binary wheels for a number of platforms are available thanks to the work of Ryan Helinski". However, there is no mention of where those can be found. My questions are then:
How do I obtain the .whl file for the HDBSCAN package?
Is it possible to simply compile+install on another machine and copy it? If so, what should the machine on which I compile have in common with the one on which the code must run? Can I do it on a Windows 10 machine, or does it have to be Win7 as well, do the same Windows updates need to have been run on both, etc?
Looks like there is no pre-built wheel distribution published by the maintainers of the project themselves on PyPI.
As already mentioned by other contributors, one could get such wheel distributions from a third party such as Christoph Gohlke's "Unofficial Windows Binaries for Python Extension Packages".
It is also of course possible to build such wheels yourself on one machine and then reuse it on another. As far as I know in the case of Windows, both machines need to have the same Python interpreter (minor) version as well as the same bitness (both 32 bits or both 64 bits). The exact version of the operating system should not matter (from Windows 10 to Windows 7 or the other way around should work).
I ended up getting this to work by compiling on another machine and copying the package from it. It was critical that the required packages were of the same version on both machines, so I simply set up a new conda environment which had the same package versions as the target machine, then intalled hdbscan with pip there, and copied.
I was worried about Windows version compatibility, but this worked even though I installed on Windows 10 and moved to a machine running Win7.
here is the site you can download the wheel file :https://www.lfd.uci.edu/~gohlke/pythonlibs/
for python 3.5>
or PyPi for older versions
run python -m pip install thefiledownloadedforyourpythonversion.whl
For the second question , yes you can but is rather complicated and you should avoid it when you can :)
I just checked. Python 3.8 is coded in C. You need a C compiler, not a C++ one. MINGW is one, and TinyCC Win32 is another one (a small one, producing quickly slow executables). Look also into this list of free C or C++ compilers.
A possibility (which could take several days of work) might be to use some WSL or some Linux emulator such as JSLinux (it runs in a web browser). Then you could (painfully) build a cross compiler (starting first with a tinycc-win32, then compiling an old cross GCC 3 compiler, then compiling with that a newer C++ GCC, etc....)
But the reality is that you should not be allowed to do this. Your real issue is non technical: why are you not allowed to install then use a C++ compiler, such as MinGW? Get permission (and resources) to install some....
Alternatively, consider installing some Linux distribution (ensure you are allowed to do so). Most of them have a recent Python and GCC...
Is it possible to simply compile+install on another machine and copy it?
This is called cross-compilation and is possible in general. The point is to be permitted to do that. You should find relevant cross-compilers for your situation.
If you are allowed to, you could even use a live Linux USB stick....
Some C compilers written in Python do exist.... You could use them to cross-compile tinycc for Win32. Then you should have a C compiler for Win32. You could then compile an old GCC, etc.... Qemu exist for windows. You could run a Linux with a cross-GCC compiler in Qemu.
I'm quit new in using python. The current version I'm using is 2.7. I need to employ function mncontour in minuit which requires the installation of natgrid as additional toolkit for matplotlib. I downloaded natgrid 0.2.1 with a file named setup.py in it. I ran this setup.py through python shell without reaching any error. But it seems that the installation was not succeed. Anyone has any idea how the installation can be done? Many thanks.
Liang
Could you please provide some more information on this topic.
what operating system you are working with ( some offer more support than others for python)
have you installed python headers, and a C/C++ compiler in your environment? ( numerical libraries might require native code to speed up the computation)
Have you tried a package manager for python ( such as easy or pip)? Both work on both windows and unixes, and usually download and install all the needed packages to make your module working.
A piece of the setup's output before setup.py finished would help us help you greatly.
Python for Windows [Nt - 7] is compiled with either cygwin or mingw, thus you not only need the python environment, but also said compiler, and python headers. If you want a more point and click install, then there's this professor at this university who maintains a good and up to date repository of scientific python modules, that depend on native extensions ( among which numpy, scipy, matplotlib).
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Manuals to setup mingw and python :
https://docs.python.org/2/using/windows.html
MingW can be downloaded from here:
http://www.mingw.org/
Best option for installing natgrid is from conda
conda install -c jochym natgrid=0.2
I normally use python 2.7.3 traditionally installed in /usr/local/bin, but I needed to rebuild python 2.6.6 (which I did without using virtualenv) in another directory ~/usr/local/ and rebuild numpy, scipy, all libraries I needed different versions from what I had for python 2.7.3 there...
But all the other packages that I want exactly as they were (meaning same version) in my default installation, I don't know how to just use them in the python 2.6.6 without having to download tarballs, build and installing them using --prefix=/home/myself/usr/local/bin.
Is there a fast or simpler way of "re-using" those packages in my "local" python 2.6.6?
Reinstall them. It may seem like a no-brainer to reuse modules (in a lot of cases, you can), but in the case of modules that have compiled code - for long term systems administration this can be an utter nightmare.
Consider supporting multiple versions of Python for multiple versions / architectures of Linux. Some modules will reference libraries in /usr/local/lib, but those libraries can be the wrong arch or wrong version.
You're better off making a requirements.txt file and using pip to install them from source.
I need to support some software that is using an old Python version (2.4). So I have downloaded and compiled Python 2.4 and installed it in a virtualenv. So far, all OK and normal procedure.
But the software is trying to import an rpm module. And I cannot find a source for that module (it is not part of the standard Python library, afaict).
Typically, once the virtualenv is enabled (source env/bin/activate) I can install required software using easy_install. But easy_install rpm is failing to find anything. There is a pyrpm module, but it is not the same thing (it installs a module called "pyrpm"). And google searches are useless, as they all link to articles on how to build rpms...
If I were using the system python (on Ubuntu) I could install the python-rpm package. But that is for Python 2.7. How do I install the equivalent for Python 2.4?
[My impression is that the rpm libraries, used by many Linux systems, include a Python library, which is packaged as python-dev by the distro. But I can't see how to access that for an arbitrary python version.]
I AM NOT LOOKING FOR AN RPM THAT CONTAINS PYTHON 2.4. I AM LOOKING FOR A MODULE NAMED rpm THAT IS USED BY SOFTWARE WRITTEN FOR PYTHON 2.4.
It's right there, in the python-rpm RPM package:
http://rpmfind.net/linux/rpm2html/search.php?query=python-rpm
You will probably want to download the package contents, extract them, and then use
python setup.py install
From your active environment.
Of course, as it's pre compiled, you might have trouble getting the C extension to run.
I'm not familiar enough with RPM's to know whether you can get the source from there.
No guarantees the package will work with your python version though.
there's no simple way to do this; the python library is part of the system rpm package and interfaces to C code, so is closely tied to the rpm package installed on your machine.
instead, it's much simpler to install an old OS in a VM (eg CentOS 5) that uses Python 2.4. then everything is consistent and works.
the sources for the rpm module can be found here: http://www.rpm.org/wiki/Download
After you download the wanted version read and follow the INSTALL instructions in order to compile it on your target OS. Afterwards make sure you add the correct path to the 'site-packages' folder the installation chose into your PYTHONPATH environment variable.
To test start your python interpreter and run 'import rpm'
HTH,
Ran