jodal / pyspotify

Python bindings for libspotify (no longer working as of May 2022)
https://pyspotify.readthedocs.io
Apache License 2.0
519 stars 95 forks source link

Compiling pyspotify 1 on Windows #63

Closed DrFunk closed 9 years ago

DrFunk commented 12 years ago

Hi!

I tried compiling on WinXP and ran into several problems I thought you'd like to know. First, compilation does not work for me with the latest version of gcc (the option '-mno-cygwin' is no longer supported). Then I tried to downgrade to gcc 3.4.5 but I got compilation errors (log below). Apparently PyObject_HEAD is not recognized, although we do have #include at the beginning of module.c Do you have any idea on how to fix this or is there something stupid I'm missing?

Thanks in advance!

Compilation log:

~\mopidy-pyspotify-3d62577>python setup.py build
running build
running build_py
creating build
creating build\lib.win32-2.7
creating build\lib.win32-2.7\spotify
copying spotify\__init__.py -> build\lib.win32-2.7\spotify
creating build\lib.win32-2.7\spotify\audiosink
copying spotify\audiosink\alsa.py -> build\lib.win32-2.7\spotify\audiosink
copying spotify\audiosink\gstreamer.py -> build\lib.win32-2.7\spotify\audiosink
copying spotify\audiosink\oss.py -> build\lib.win32-2.7\spotify\audiosink
copying spotify\audiosink\portaudio.py -> build\lib.win32-2.7\spotify\audiosink
copying spotify\audiosink\__init__.py -> build\lib.win32-2.7\spotify\audiosink
creating build\lib.win32-2.7\spotify\manager
copying spotify\manager\container.py -> build\lib.win32-2.7\spotify\manager
copying spotify\manager\playlist.py -> build\lib.win32-2.7\spotify\manager
copying spotify\manager\session.py -> build\lib.win32-2.7\spotify\manager
copying spotify\manager\__init__.py -> build\lib.win32-2.7\spotify\manager
running build_ext
building 'spotify._spotify' extension
creating build\temp.win32-2.7
creating build\temp.win32-2.7\Release
creating build\temp.win32-2.7\Release\src
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Isrc -IC:\Python27\include -IC:\Python27\PC -c src/module.c -o build\temp.win32-2.7\Release\src\module.o
src/module.c:3:28: libspotify/api.h: No such file or directory
In file included from src/module.c:5:
src/artist.h:2: error: syntax error before "sp_artist"
src/artist.h:2: warning: no semicolon at end of struct or union
src/artist.h:3: warning: type defaults to `int' in declaration of `Artist'
src/artist.h:3: warning: data definition has no type or storage class
src/artist.h:9: error: syntax error before '*' token
In file included from src/module.c:6:
src/artistbrowser.h:5: error: syntax error before "sp_artistbrowse"
src/artistbrowser.h:5: warning: no semicolon at end of struct or union
src/artistbrowser.h:6: warning: type defaults to `int' in declaration of `ArtistBrowser'
src/artistbrowser.h:6: warning: data definition has no type or storage class
src/artistbrowser.h:13: error: syntax error before '*' token
In file included from src/module.c:7:
src/album.h:2: error: syntax error before "sp_album"
src/album.h:2: warning: no semicolon at end of struct or union
src/album.h:3: warning: type defaults to `int' in declaration of `Album'
src/album.h:3: warning: data definition has no type or storage class
src/album.h:9: error: syntax error before '*' token
In file included from src/module.c:8:
src/albumbrowser.h:4: error: syntax error before "sp_albumbrowse"
src/albumbrowser.h:4: warning: no semicolon at end of struct or union
src/albumbrowser.h:6: error: syntax error before '}' token
src/albumbrowser.h:6: warning: type defaults to `int' in declaration of `AlbumBrowser'
src/albumbrowser.h:6: warning: data definition has no type or storage class
src/albumbrowser.h:13: error: syntax error before '*' token
In file included from src/module.c:9:
src/link.h:2: error: syntax error before "sp_link"
src/link.h:2: warning: no semicolon at end of struct or union
src/link.h:3: warning: type defaults to `int' in declaration of `Link'
src/link.h:3: warning: data definition has no type or storage class
In file included from src/module.c:10:
src/playlist.h:5: error: syntax error before "sp_playlist"
src/playlist.h:5: warning: no semicolon at end of struct or union
src/playlist.h:6: warning: type defaults to `int' in declaration of `Playlist'
src/playlist.h:6: warning: data definition has no type or storage class
src/playlist.h:14: error: syntax error before "sp_playlist_callbacks"
src/playlist.h:14: warning: no semicolon at end of struct or union
src/playlist.h:17: error: syntax error before '}' token
src/playlist.h:17: warning: type defaults to `int' in declaration of `playlist_callback'
src/playlist.h:17: warning: data definition has no type or storage class
src/playlist.h:21: error: syntax error before "sp_playlist"
src/playlist.h:21: warning: no semicolon at end of struct or union
src/playlist.h:22: warning: type defaults to `int' in declaration of `callbacks'
src/playlist.h:22: warning: data definition has no type or storage class
src/playlist.h:23: error: conflicting types for 'next'
src/playlist.h:16: error: previous declaration of 'next' was here
src/playlist.h:24: error: syntax error before '}' token
src/playlist.h:24: warning: type defaults to `int' in declaration of `pl_cb_entry'
src/playlist.h:24: warning: data definition has no type or storage class
src/playlist.h:26: error: syntax error before '*' token
In file included from src/module.c:11:
src/playlistcontainer.h:5: error: syntax error before "sp_playlistcontainer"
src/playlistcontainer.h:5: warning: no semicolon at end of struct or union
src/playlistcontainer.h:6: warning: type defaults to `int' in declaration of `PlaylistContainer'
src/playlistcontainer.h:6: warning: data definition has no type or storage class
src/playlistcontainer.h:12: error: syntax error before '*' token
src/playlistcontainer.h:16: error: syntax error before "sp_playlistcontainer_callbacks"
src/playlistcontainer.h:16: warning: no semicolon at end of struct or union
src/playlistcontainer.h:18: error: conflicting types for 'next'
src/playlist.h:23: error: previous declaration of 'next' was here
src/playlistcontainer.h:18: error: conflicting types for 'next'
src/playlist.h:23: error: previous declaration of 'next' was here
src/playlistcontainer.h:19: error: syntax error before '}' token
src/playlistcontainer.h:19: warning: type defaults to `int' in declaration of `playlistcontainer_callback'
src/playlistcontainer.h:19: warning: data definition has no type or storage class
src/playlistcontainer.h:23: error: syntax error before "sp_playlistcontainer"
src/playlistcontainer.h:23: warning: no semicolon at end of struct or union
src/playlistcontainer.h:24: warning: type defaults to `int' in declaration of `callbacks'
src/playlistcontainer.h:24: warning: data definition has no type or storage class
src/playlistcontainer.h:25: error: conflicting types for 'next'
src/playlistcontainer.h:18: error: previous declaration of 'next' was here
src/playlistcontainer.h:25: error: conflicting types for 'next'
src/playlist.h:23: error: previous declaration of 'next' was here
src/playlistcontainer.h:26: error: syntax error before '}' token
src/playlistcontainer.h:26: warning: type defaults to `int' in declaration of `plc_cb_entry'
src/playlistcontainer.h:26: warning: data definition has no type or storage class
In file included from src/module.c:12:
src/playlistfolder.h:7: error: syntax error before "sp_uint64"
src/playlistfolder.h:7: warning: no semicolon at end of struct or union
src/playlistfolder.h:8: warning: type defaults to `int' in declaration of `_type'
src/playlistfolder.h:8: warning: data definition has no type or storage class
src/playlistfolder.h:9: warning: type defaults to `int' in declaration of `PlaylistFolder'
src/playlistfolder.h:9: warning: data definition has no type or storage class
src/playlistfolder.h:15: error: syntax error before '*' token
In file included from src/module.c:13:
src/search.h:2: error: syntax error before "sp_search"
src/search.h:2: warning: no semicolon at end of struct or union
src/search.h:3: warning: type defaults to `int' in declaration of `Results'
src/search.h:3: warning: data definition has no type or storage class
src/search.h:9: error: syntax error before '*' token
In file included from src/module.c:14:
src/session.h:3: error: syntax error before "sp_session"
src/session.h:3: warning: no semicolon at end of struct or union
src/session.h:5: error: syntax error before '}' token
src/session.h:5: warning: type defaults to `int' in declaration of `Session'
src/session.h:5: warning: data definition has no type or storage class
src/session.h:7: error: syntax error before '*' token
src/session.h:7: warning: type defaults to `int' in declaration of `g_session'
src/session.h:7: warning: data definition has no type or storage class
src/session.h:16: error: syntax error before '*' token
In file included from src/module.c:15:
src/toplistbrowser.h:3: error: syntax error before "sp_toplistbrowse"
src/toplistbrowser.h:3: warning: no semicolon at end of struct or union
src/toplistbrowser.h:4: warning: type defaults to `int' in declaration of `ToplistBrowser'
src/toplistbrowser.h:4: warning: data definition has no type or storage class
src/toplistbrowser.h:10: error: syntax error before '*' token
In file included from src/module.c:16:
src/track.h:2: error: syntax error before "sp_track"
src/track.h:2: warning: no semicolon at end of struct or union
src/track.h:3: warning: type defaults to `int' in declaration of `Track'
src/track.h:3: warning: data definition has no type or storage class
src/track.h:9: error: syntax error before '*' token
In file included from src/module.c:17:
src/image.h:2: error: syntax error before "sp_image"
src/image.h:2: warning: no semicolon at end of struct or union
src/image.h:3: warning: type defaults to `int' in declaration of `Image'
src/image.h:3: warning: data definition has no type or storage class
src/image.h:9: error: syntax error before '*' token
In file included from src/module.c:18:
src/user.h:3: error: syntax error before "sp_user"
src/user.h:3: warning: no semicolon at end of struct or union
src/user.h:4: warning: type defaults to `int' in declaration of `User'
src/user.h:4: warning: data definition has no type or storage class
src/user.h:10: error: syntax error before '*' token
src/module.c: In function `init_spotify':
src/module.c:70: error: `SPOTIFY_API_VERSION' undeclared (first use in this function)
src/module.c:70: error: (Each undeclared identifier is reported only once
src/module.c:70: error: for each function it appears in.)
error: command 'gcc' failed with exit status 1
ghost commented 12 years ago

have you installed libspotify, the log clearly says that the spotify header files were not found.

...
src/module.c28: libspotify/api.h: No such file or directory
...
bok commented 12 years ago

@aish9r is right; most of the errors I see in the log are cause by the missing declaration of libspotify API structs.

Anyway, I do not have tried to compile on Windows yet. The code is mostly written with portability in mind, but there will be surely a few quirks to resolve before it works flawlessly.

DrFunk commented 12 years ago

Hey!

Thanks for your answers =)

I tried adding ~\libspotify\include to my path, as well as ~\libspotify\lib and I still have the error.

I also tried to copy the ~\libspotify\include\libspotify directory in the ~\mopidy-pyspotify-3d62577\src, so libspotify/api.h is found when compiling. But I then get another error when linking. Here's a snippet of the log below. I guess it's because the lib cannot be found but it's strange because it's in the path now... Maybe a path separator problem ("\" vs "/") ?

C:\MinGW\bin\dllwrap.exe -mno-cygwin -mdll -static --output-lib build\temp.win32-2.7\Release\src\lib_spotify.a --def build\temp.win32-2.7\Release\src\_spotify.def -s build\temp.win32-2.7\Release\src\module.o build\temp.win32-2.7\Release\src\session.o build\temp.win32-2.7\Release\src\link.o build\temp.win32-2.7\Release\src\track.o build\temp.win32-2.7\Release\src\album.o build\temp.win32-2.7\Release\src\albumbrowser.o build\temp.win32-2.7\Release\src\artist.o build\temp.win32-2.7\Release\src\artistbrowser.o build\temp.win32-2.7\Release\src\search.o build\temp.win32-2.7\Release\src\playlist.o build\temp.win32-2.7\Release\src\playlistcontainer.o build\temp.win32-2.7\Release\src\playlistfolder.o build\temp.win32-2.7\Release\src\image.o build\temp.win32-2.7\Release\src\user.o build\temp.win32-2.7\Release\src\pyspotify.o build\temp.win32-2.7\Release\src\toplistbrowser.o -LC:\Python27\libs -LC:\Python27\PCbuild -lspotify -lpython27 -lmsvcr90 -o build\lib.win32-2.7\spotify\_spotify.pyd
C:\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lspotify
collect2: ld returned 1 exit status
dllwrap: gcc exited with status 1
error: command 'dllwrap' failed with exit status 1
bok commented 12 years ago

You need to add the API headers in the include path (add something like -I~\libspotify\include to your compiler options) and the shared library in the library path (add -L~\libspotify\lib to your linker options). This will allow the compiler to find the necessary include files, and your linker to find the necessary binary objects.

metalshark commented 11 years ago

I have started a bounty for this on StackOverflow: http://stackoverflow.com/q/13867498/179454

girlpunk commented 11 years ago

Was this issue ever resolved? I am having the same problem.

krixian commented 11 years ago

I've just tried to compile in Win8. I've gotten pretty far, but now I'm stuck on the missing libgen.h and unistd.h files. These do not exists in Windows, and haven't been ported either.

A couple of other Open Source projects I found in my search of these files, actively tells their developers to refrain from using them, because of cross-platform issues.

JeppeTh commented 10 years ago

Would be awesome if this was fixed - even for my old XP system ;-)

JDurman commented 10 years ago

Here are some Instructions on how to install pyspotify on Windows 8, I've done this on two different computers and its worked both times without issue.

Install Python 2.7 32bit

Install setuptools for Python 2.7 32bit http://www.lfd.uci.edu/~gohlke/pythonlibs/#setuptools

Install pip for Python 2.7 32bit http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip

Install PyAudio for Python 2.7 32bit http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

Install MinGW http://sourceforge.net/projects/mingw/ (Select the base package when asked)

Add the Scripts folder for your python install and the bin folder for you MinGW install and add both of their locations to the path variable. For me this was C:\Python27\Scripts\ and C:\MinGW\bin\

Then Edit or Create the file in your python install at C:\Python27\Lib\distutils\distutils.cfg distutils.cfg should have the 2 lines below as its content

[build]
compiler=mingw32

Now we need to take out -mno-cygwin flag from C:\Python27\Lib\distutils\cygwincompiler.py It should start around line 326 after you edit the snippet it should look like

self.set_executables(compiler='gcc -O -Wall',
                         compiler_so='gcc -mdll -O -Wall',
                         compiler_cxx='g++ -O -Wall',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

Take libspotify.lib that you got from spotify.com and rename it to spotify.lib then move it to C:\Python27\libs Then take the libspotify folder under include in the libspotify package and move it to C:\MinGW\include\

then type in cmd pip install -U pyspotify

If you have any questions just shoot me an email at Jacob.Durman@gmail.com

JeppeTh commented 10 years ago

Awesome!

I guess I got it working: Successfully installed pyspotify Cleaning up...

I was hoping to get Spotify going on Plex on my Windows XP - but it seems I need to do some more... At least this is a good start ;-)

Edit: I wonder if the build itself really works... I removed self.dll_libraries = get_msvcr() from cygwincompiler.py (kind of mentioned http://bugs.python.org/issue16472) Then pyspotify is at least possible to load in Plex - but it crashes when calling spotify.Session.create(self, self.settings)

I also tried the Jukebox (to see if it was plex related) - python crashes instead. So suggestion above doesn't seem to work for me at least.

JeppeTh commented 10 years ago

Here's the output from the crash report (Dr Watson) running jukebox - not sure if I can make the information more informative in anyway - I don't know much about Windows development... Any Help would be appreciated.

*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Python27\lib\site-packages\spotify\libspotify.dll - 
function: libspotify!sp_session_create
        01f7d64d ff53e8           call    dword ptr [ebx-0x18]
        01f7d650 21e6             and     esi,esp
        01f7d652 0200             add     al,[eax]
        01f7d654 83c404           add     esp,0x4
        01f7d657 bf02000000       mov     edi,0x2
        01f7d65c 53               push    ebx
        01f7d65d e82ef1ffff       call    libspotify+0xdc790 (01f7c790)
        01f7d662 53               push    ebx
        01f7d663 e80de60200       call    libspotify+0x10bc75 (01fabc75)
        01f7d668 83c404           add     esp,0x4
FAULT ->01f7d66b 8b9bc0010000     mov     ebx,[ebx+0x1c0]   ds:0023:000001c0=????????
        01f7d671 85db             test    ebx,ebx
        01f7d673 7409             jz    libspotify!sp_session_create+0x2ee (01f7d67e)
        01f7d675 53               push    ebx
        01f7d676 e8fae50200       call    libspotify+0x10bc75 (01fabc75)
        01f7d67b 83c404           add     esp,0x4
        01f7d67e 57               push    edi
        01f7d67f e8fc1df8ff       call    libspotify+0x5f480 (01eff480)
        01f7d684 83c404           add     esp,0x4
        01f7d687 8bc7             mov     eax,edi
        01f7d689 5f               pop     edi
jodal commented 10 years ago

Just a note to self: This may be a useful resource for building C exts on Windows: http://www.wireshark.org/docs/wsdg_html_chunked/ChToolsMSChain.html

jodal commented 9 years ago

Due to the imminent release of the 2.0 rewrite of pyspotify, compilation of pyspotify 1.x on Windows will probably never be documented/supported. I'm closing this issue.

Feel free to open a new issue to discuss how to compile pyspotify 2 on Windows.