hobuinc / mgrs

Python MGRS library
https://pypi.python.org/pypi/mgrs
MIT License
111 stars 36 forks source link

Install on Windows 7 x64 with Python 2.7 x64 #4

Closed aarismendi closed 4 years ago

aarismendi commented 11 years ago

I'm trying to build and install this module on Windows 7 x64 with Python 2.7 x64.

I installed setuptools (https://pypi.python.org/pypi/setuptools)

From the visual studio 2008 command prompt I ran:

C:\Users\andy\Downloads\mgrs-master>C:\Python27\python.exe setup.py install

Which did this:

running install
running bdist_egg
running egg_info
writing requirements to mgrs.egg-info\requires.txt
writing mgrs.egg-info\PKG-INFO
writing top-level names to mgrs.egg-info\top_level.txt
writing dependency_links to mgrs.egg-info\dependency_links.txt
reading manifest file 'mgrs.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'mgrs.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
copying mgrs\core.py -> build\lib.win-amd64-2.7\mgrs
copying mgrs\__init__.py -> build\lib.win-amd64-2.7\mgrs
running build_ext
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
copying build\lib.win-amd64-2.7\libmgrs.dll -> build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\mgrs
copying build\lib.win-amd64-2.7\mgrs\core.py -> build\bdist.win-amd64\egg\mgrs
copying build\lib.win-amd64-2.7\mgrs\__init__.py -> build\bdist.win-amd64\egg\mgrs
byte-compiling build\bdist.win-amd64\egg\mgrs\core.py to core.pyc
byte-compiling build\bdist.win-amd64\egg\mgrs\__init__.py to __init__.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying mgrs.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying mgrs.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mgrs.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying mgrs.egg-info\not-zip-safe -> build\bdist.win-amd64\egg\EGG-INFO
copying mgrs.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mgrs.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
creating dist
creating 'dist\mgrs-1.1.0-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing mgrs-1.1.0-py2.7-win-amd64.egg
creating c:\python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg
Extracting mgrs-1.1.0-py2.7-win-amd64.egg to c:\python27\lib\site-packages
Adding mgrs 1.1.0 to easy-install.pth file

Installed c:\python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg
Processing dependencies for mgrs==1.1.0
Searching for setuptools==0.6c11
Best match: setuptools 0.6c11
Processing setuptools-0.6c11-py2.7.egg
setuptools 0.6c11 is already the active version in easy-install.pth
Installing easy_install-script.py script to C:\Python27\Scripts
Installing easy_install.exe script to C:\Python27\Scripts
Installing easy_install.exe.manifest script to C:\Python27\Scripts
Installing easy_install-2.7-script.py script to C:\Python27\Scripts
Installing easy_install-2.7.exe script to C:\Python27\Scripts
Installing easy_install-2.7.exe.manifest script to C:\Python27\Scripts

Using c:\python27\lib\site-packages\setuptools-0.6c11-py2.7.egg
Finished processing dependencies for mgrs==1.1.0

But from IDLE when I try to import MGRS I get:

Traceback (most recent call last):
  File "", line 1, in 
    import mgrs
  File "C:\Python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg\mgrs\__init__.py", line 1, in 
    from core import rt
  File "C:\Python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg\mgrs\core.py", line 18, in 
    rt = ctypes.PyDLL(lib_name)
  File "C:\Python27\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
hobu commented 11 years ago

IIRC, MSVC 2008 requires special stuff to actually build x86_64 binaries. Doesn't it make 32bit by default? I don't know if setuptools/pip is smart enough to turn those switches on. The error you are getting certainly implies the dll it is trying to open is not the same format as the python binary you're running.

On Apr 10, 2013, at 1:45 PM, Andy Arismendi notifications@github.com wrote:

I'm trying to build and install this module on Windows 7 x64 with Python 2.7 x64.

From the visual studio 2008 command prompt I ran:

C:\Users\andy\Downloads\mgrs-master>C:\Python27\python.exe setup.py install

Which did this:

running install running bdist_egg running egg_info writing requirements to mgrs.egg-info\requires.txt writing mgrs.egg-info\PKG-INFO writing top-level names to mgrs.egg-info\top_level.txt writing dependency_links to mgrs.egg-info\dependency_links.txt reading manifest file 'mgrs.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'mgrs.egg-info\SOURCES.txt' installing library code to build\bdist.win-amd64\egg running install_lib running build_py copying mgrs\core.py -> build\lib.win-amd64-2.7\mgrs copying mgrsinit.py -> build\lib.win-amd64-2.7\mgrs running build_ext creating build\bdist.win-amd64 creating build\bdist.win-amd64\egg copying build\lib.win-amd64-2.7\libmgrs.dll -> build\bdist.win-amd64\egg creating build\bdist.win-amd64\egg\mgrs copying build\lib.win-amd64-2.7\mgrs\core.py -> build\bdist.win-amd64\egg\mgrs copying build\lib.win-amd64-2.7\mgrsinit.py -> build\bdist.win-amd64\egg\mgrs byte-compiling build\bdist.win-amd64\egg\mgrs\core.py to core.pyc byte-compiling build\bdist.win-amd64\egg\mgrsinit.py to init.pyc creating build\bdist.win-amd64\egg\EGG-INFO copying mgrs.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO copying mgrs.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO copying mgrs.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying mgrs.egg-info\not-zip-safe -> build\bdist.win-amd64\egg\EGG-INFO copying mgrs.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO copying mgrs.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt creating dist creating 'dist\mgrs-1.1.0-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it removing 'build\bdist.win-amd64\egg' (and everything under it) Processing mgrs-1.1.0-py2.7-win-amd64.egg creating c:\python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg Extracting mgrs-1.1.0-py2.7-win-amd64.egg to c:\python27\lib\site-packages Adding mgrs 1.1.0 to easy-install.pth file

Installed c:\python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg Processing dependencies for mgrs==1.1.0 Searching for setuptools==0.6c11 Best match: setuptools 0.6c11 Processing setuptools-0.6c11-py2.7.egg setuptools 0.6c11 is already the active version in easy-install.pth Installing easy_install-script.py script to C:\Python27\Scripts Installing easy_install.exe script to C:\Python27\Scripts Installing easy_install.exe.manifest script to C:\Python27\Scripts Installing easy_install-2.7-script.py script to C:\Python27\Scripts Installing easy_install-2.7.exe script to C:\Python27\Scripts Installing easy_install-2.7.exe.manifest script to C:\Python27\Scripts

Using c:\python27\lib\site-packages\setuptools-0.6c11-py2.7.egg Finished processing dependencies for mgrs==1.1.0

But from IDLE when I try to import MGRS I get:

Traceback (most recent call last): File "", line 1, in import mgrs File "C:\Python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg\mgrsinit.py", line 1, in from core import rt File "C:\Python27\lib\site-packages\mgrs-1.1.0-py2.7-win-amd64.egg\mgrs\core.py", line 18, in rt = ctypes.PyDLL(lib_name) File "C:\Python27\lib\ctypesinit.py", line 353, in init self._handle = _dlopen(self._name, mode) WindowsError: [Error 126] The specified module could not be found

— Reply to this email directly or view it on GitHub.

aarismendi commented 11 years ago

I was hoping it was smart enough to do python bitness detection and compile the DLL as necessary. I'll research how to make setup.py do this.

aarismendi commented 11 years ago

Progress...

So this error:

WindowsError: [Error 126] The specified module could not be found

Was caused by setup.py not putting libmgrs.dll in the place core.py was attempting to load it from. Setup.py setup the module like this:

C:\Python27\Lib\site-packages
|   
+---mgrs-1.1.0-py2.7-win32.egg
    |   libmgrs.dll
    |   
    +---EGG-INFO
    |       dependency_links.txt
    |       native_libs.txt
    |       not-zip-safe
    |       PKG-INFO
    |       requires.txt
    |       SOURCES.txt
    |       top_level.txt
    |       
    \---mgrs
           core.py
           core.pyc
           __init__.py
           __init__.pyc

But core.py is trying to load libmgrs.dll from C:\Python27\DLLs:

local_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
original_path = os.environ['PATH']
os.environ['PATH'] = "%s;%s" % (local_dlls, original_path)
rt = ctypes.PyDLL(lib_name)

I found these two blog posts that attempt to get disutils to use the 64 bit C compiler:

http://blog.victorjabur.com/2011/06/05/compiling-python-2-7-modules-on-windows-32-and-64-using-msvc-2008-express/ http://mattptr.net/2010/07/28/building-python-extensions-in-a-modern-windows-environment/

They involve a complicated process that involves editing disutils files. So I just let setup.py compile libmgrs.dll as 32 bit and replace it with a 64 bit version I made with Visual Studio 2010.

So after compiling libmgrs.dll as 64 bit and putting it in the DLL folder the module worked.

I modified core.py to load libmgrs.dll from the current folder so I can store the module in an outside directory:

if os.name == 'nt':
    lib_name = 'libmgrs.dll'
    try:
        lib_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), lib_name)
        rt = ctypes.PyDLL(lib_path)

btw - It would be nice to have some setup documentation added to the readme... like where the DLL needs to go... especially since setup.py doesn't put it in the right place.

hobu commented 11 years ago

This code was stolen from Shapely, and it is the same issue as Toblerity/Shapely#37.

endeav0r commented 11 years ago

I don't know if this issue was fixed, but the current release 1.1.0 still has this issue.