简体   繁体   English

在windows 10安装python shout模块(python版本3.9)

[英]Install python shout module in windows 10 (python version 3.9)

I am trying to install python-shout module in windows 10 but it fails.我正在尝试在 windows 10 中安装 python-shout 模块,但它失败了。 In the ubuntu works well.在ubuntu上运行良好。

Edit (06/10/2022): Here is what i have tried to build python-shout in native windows编辑(06/10/2022):这是我尝试在本机 windows 中构建 python-shout 的内容

  1. Only download libshout module files from here : Note that i download all the 14 dependencies + this package: winpthreads仅从此处下载 libshout 模块文件:请注意,我下载了所有 14 个依赖项 + 这个 package: winpthreads
  2. I renamed the 15 zst files to have names like 1.zst, 2.zst,..., 15.zst我将 15 个 zst 文件重命名为 1.zst、2.zst、...、15.zst
  3. I decompress the zst files using this command: tar --use-compress-program=unzstd -xvf 1.zst我使用以下命令解压缩 zst 文件: tar --use-compress-program=unzstd -xvf 1.zst
  4. From the output files and directories i copied the opt/x86_64-w64-mingw32/* folders and files in mingw64 folder.从 output 文件和目录中,我复制了 opt/x86_64-w64-mingw32/* 文件夹和 mingw64 文件夹中的文件。
  5. After that i uninstall msys2 platform.之后我卸载了 msys2 平台。
  6. I open a cmd and i run the file mingw64/bin/shout.exe The files run correctly.我打开 cmd 并运行文件 mingw64/bin/shout.exe 这些文件运行正常。
  7. I download and extract the python-shout module from here我从这里下载并提取 python-shout 模块
  8. I modified the setup.py of the extracted folder in step 7 to be like我在第 7 步中将提取的文件夹的 setup.py 修改为
# distutils build script
# To install shout-python, run 'python setup.py install'

from setuptools import setup, Extension
import os
import sys
import setuptools

ver = '0.2.7'

with open("README.md", "r") as fh:
    long_description = fh.read()

cflags = "-IC:/Users/cpapp/OneDrive/Υπολογιστής/mingw64/include"
libs = "-LC:/Users/cpapp/OneDrive/Υπολογιστής/mingw64/lib -lshout"

# there must be an easier way to set up these flags!
iflags = [x[2:] for x in cflags.split() if x[0:2] == '-I']
extra_cflags = [x for x in cflags.split() if x[0:2] != '-I']
libdirs = [x[2:] for x in libs.split() if x[0:2] == '-L']
libsonly = [x[2:] for x in libs.split() if x[0:2] == '-l']

# include_dirs=[]
# libraries=[]
# runtime_library_dirs=[]
# extra_objects, extra_compile_args, extra_link_args
shout = Extension('shout', sources = ['shout.c'],
                  include_dirs = iflags,
                  extra_compile_args = extra_cflags,
                  library_dirs = libdirs,
                  libraries = libsonly)

# data_files = []
setup (name = 'python-shout',
       version = ver,
       description = 'Bindings for libshout 2',
       long_description=long_description,
       long_description_content_type="text/markdown",
       url = 'http://icecast.org/download.php',
       author = 'Brendan Cully',
       author_email = 'brendan@xiph.org',
       ext_modules = [shout],
       packages=setuptools.find_packages(),
       classifiers=[
                   "Programming Language :: Python :: 3",
                   "Programming Language :: Python :: 2",
                   "License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
                   "Operating System :: OS Independent",
               ],

       )

Important note: Check the path values of cflags and libs variables.重要说明:检查 cflags 和 libs 变量的路径值。

  1. I run python setup.py build with this output:我用这个 output 运行python setup.py build
running build
running build_ext
building 'shout' extension
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:/Users/cpapp/OneDrive/Υπολογιστής/mingw64/include -IC:\python\include -IC:\python\Include "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\include" "-IC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\um" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\shared" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\winrt" "-IC:\Program Files (x86)\Windows Kits\10\\include\10.0.19041.0\\cppwinrt" /Tcshout.c /Fobuild\temp.win32-cpython-310\Release\shout.obj
shout.c
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\bin\HostX86\x86\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:/Users/cpapp/OneDrive/Υπολογιστής/mingw64/lib /LIBPATH:C:\python\libs /LIBPATH:C:\python /LIBPATH:C:\python\PCbuild\win32 "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\lib\x86" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\lib\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x86" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\ATLMFC\lib\x86" "/LIBPATH:C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\lib\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.19041.0\\um\x86" shout.lib /EXPORT:PyInit_shout build\temp.win32-cpython-310\Release\shout.obj /OUT:build\lib.win32-cpython-310\shout.cp310-win_amd64.pyd /IMPLIB:build\temp.win32-cpython-310\Release\shout.cp310-win_amd64.lib
LINK : fatal error LNK1181: cannot open input file 'shout.lib'
error: command 'C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX86\\x86\\link.exe' failed with exit code 1181

The error is that shout.lib file can't be found, but there is no shout.lib file only libshout-3.dll.错误是找不到shout.lib文件,但是没有shout.lib文件只有libshout-3.dll。 I tried to convert libshout-3.dll to shout.lib using dumpbin.我尝试使用 dumpbin 将 libshout-3.dll 转换为 shout.lib。 The python module installation works well but when i am trying to import the module not well formatted dll error oquered. python 模块安装工作正常,但是当我尝试导入格式不正确的模块时,出现 dll 错误。

Any help would be usefull!!任何帮助都会很有用!!

Here is a simple but good solution.这是一个简单但很好的解决方案。

  1. First install msys2, python for msys2, libshout for msys2, pip for msys2, pyinstaller for python for msys2, setuptools for python for msys2 and everything else to build python-shout module in msys2 platform.首先安装msys2, python for msys2, libshout for msys2, pip for msys2, pyinstaller for python for msys2, setuptools for python for msys2 和其他一切来构建ms python-shout2 平台模块。
  2. After installation of python-shout in msys2 platform i create an exe (using pyinstaller).在 msys2 平台上安装 python-shout 后,我创建了一个 exe(使用 pyinstaller)。 The code of this file is:这个文件的代码是:
import shout
import ast

x = ""
while(x is not "stop"):
    try:
        x = input()
        if x == "stop":
            break
        else:
            if "s.get_connected()" in x:
                connected_status = int(s.get_connected())
                print(connected_status)
            elif "list_bytes=" not in x:
                exec(x)
            else:
                x = x.replace("list_bytes=","")
                original_list = ast.literal_eval(x)
                s.send(bytes(original_list))
                s.sync()
    except Exception as e:
        print(str(e))

The above code uses libshout and python-shout that have been installed in msys2 for use in native windows.上述代码使用了msys2中已经安装好的libshout和python-shout,用于原生windows。

  1. After creating the.exe (msys_shout.exe) of the up file, i wrote the following file that uses the msys_shout.exe:创建 up 文件的 .exe (msys_shout.exe) 后,我编写了以下使用 msys_shout.exe 的文件:
import os
import sys
from subprocess import Popen, PIPE
from pydub import AudioSegment
from pydub.utils import which
AudioSegment.converter = which("ffmpeg.exe")

from threading  import Thread
from queue import Queue, Empty
ON_POSIX = 'posix' in sys.builtin_module_names

import time
import io

def enqueue_output(out, queue):
    for line in iter(out.readline, b''):
        queue.put(line)
    out.close()

p1 = Popen(["msys_shout.exe"], stdin=PIPE, stdout=PIPE,shell=False, universal_newlines=True, bufsize=1, close_fds=ON_POSIX)
q = Queue()
t = Thread(target=enqueue_output, args=(p1.stdout, q))
t.daemon = True # thread dies with the program
t.start()
time.sleep(2)

#create icecast connection
p1.stdin.write('s = shout.Shout()\n')
p1.stdin.flush()

p1.stdin.write('s.audio_info = {shout.SHOUT_AI_BITRATE:\'128\', shout.SHOUT_AI_SAMPLERATE:\'44800\', shout.SHOUT_AI_CHANNELS:\'2\'}\n')
p1.stdin.flush()

p1.stdin.write('s.name = \'Test radio connection\'\n')
p1.stdin.flush()

p1.stdin.write('s.url = \'http://localhost/test.ogg\'\n')
p1.stdin.flush()

p1.stdin.write('s.mount = \'test.ogg\'\n')
p1.stdin.flush()

p1.stdin.write('s.port = 8000\n')
p1.stdin.flush()

p1.stdin.write('s.user = \'username\'\n')
p1.stdin.flush()

p1.stdin.write('s.password = \'password\'\n')
p1.stdin.flush()

p1.stdin.write('s.genre = \'Other\'\n')
p1.stdin.flush()

p1.stdin.write('s.description = \'Test description\'\n')
p1.stdin.flush()

p1.stdin.write('s.host = \'localhost\'\n')
p1.stdin.flush()

p1.stdin.write('s.format = \'ogg\'\n')
p1.stdin.flush()

p1.stdin.write('s.open()\n')
p1.stdin.flush()

time.sleep(2)

p1.stdin.write('s.get_connected()\n')
p1.stdin.flush()

#connected_status = int(p1.stdout.readline())
time.sleep(2)
try:
    connected_status = int(q.get_nowait())
except Empty:
    connected_status = -2
    
if(connected_status==0):
    connected = True
    connected_message = "No error"
elif(connected_status==-1):
    connected = False
    connected_message = "Nonsensical arguments e.g. self being NULL"
elif(connected_status==-2):
    connected = False
    connected_message = "Couldn't connect"
elif(connected_status==-3):
    connected = False
    connected_message = "Login failed"
elif(connected_status==-4):
    connected = False
    connected_message = "Socket error"
elif(connected_status==-5):
    connected = False
    connected_message = "Out of memory"
elif(connected_status==-6):
    connected = False
    connected_message = "-"
elif(connected_status==-7):
    connected = True
    connected_message = "Connected in progress...Send data"
elif(connected_status==-8):
    connected = False
    connected_message = "Not connected"
elif(connected_status==-9):
    connected = False
    connected_message = "This libshout doesn't support the requested option"
elif(connected_status==-10):
    connected = False
    connected_message = "Socket is busy"
elif(connected_status==-11):
    connected = False
    connected_message = "TLS requested but not supported by peer"
elif(connected_status==-12):
    connected = False
    connected_message = "TLS connection can not be established because of bad certificate"
elif(connected_status==-13):
    connected = False
    connected_message = "Retry last operation"

print(connected_message)

audio_segment = AudioSegment.from_file("1.mp3", format="mp3").set_frame_rate(44800)
total_duration_milliseconds = len(audio_segment)
chunk_number = 0
packet_time = 744

while(True):
    try:
        try:
            error_msg = q.get_nowait()
            print(error_msg)
            p1.stdin.write('stop\n')
            p1.stdin.flush()
            break
        except Empty:
            pass

        t1 = time.time()
        if((chunk_number+1)*(packet_time)<=total_duration_milliseconds):
            slice = audio_segment[chunk_number*(packet_time):(chunk_number+1)*(packet_time)]
            chunk_number+=1
            send_data = io.BytesIO()
            slice.export(send_data,format="ogg",bitrate="128k")
            send_data_final = send_data.getvalue()
            send_data_list = list(send_data_final)
            
            p1.stdin.write('list_bytes='+str(send_data_list)+'\n')
            p1.stdin.flush()
            
        else:
            if((chunk_number)*(packet_time)<total_duration_milliseconds):
                slice = audio_segment[chunk_number*(packet_time):]
                send_data = io.BytesIO()
                slice.export(send_data,format="ogg",bitrate="128k")
                send_data_final = send_data.getvalue()
                send_data_list = list(send_data_final)
                
                p1.stdin.write('list_bytes='+str(send_data_list)+'\n')
                p1.stdin.flush()
                
                chunk_number = 0
                continue
            else:
                chunk_number = 0
                continue
        t2 = time.time()
        diff = (t2 - t1)
        if diff<packet_time/1000-0.1:
            time.sleep(packet_time/1000-diff-0.1)
    except Exception as e:
        print(e)
#s.close() command

This file was run under windows cmd. It uses pydub (AudioSegment), subprocess.Popen, ffmpeg and of course the compiled msys_shout.exe script!这个文件是在windows cmd下运行的。它使用了pydub(AudioSegment),subprocess.Popen,ffmpeg,当然还有编译好的msys_shout.exe脚本!

Why I don't use msys2 python-shout module directly: The reason is that in my project I want to use PyQtWebEngine python module that msys2 can't provide me (only QtWebView, but I want more functionalities).为什么我不直接使用msys2 python-shout模块:原因是在我的项目中我想使用msys2不能提供给我的PyQtWebEngine python模块(只有QtWebView,但我想要更多的功能)。

Looking at the setup.py , it looks like the package just doesn't support Windows.查看setup.py ,看起来 package 只是不支持 Windows。 All those os.system() calls are POSIX-only.所有这些os.system()调用都是 POSIX-only。

I have succesfully install python-shout module with MingGW and MSYS 2.我已经成功安装了带有 MingGW 和 MSYS 2 的 python-shout 模块。

Instructions:指示:

  1. Download msys2 fromhttps://repo.msys2.org/distrib/x86_64/msys2-x86_64-20210228.exehttps://repo.msys2.org/distrib/x86_64/msys2-x86_64-20210228.exe 下载 msys2

  2. Run the installer (instructions: https://www.msys2.org/ )运行安装程序(说明: https://www.msys2.org/

  3. Update packages using pacman -Syu and pacman -Su使用pacman -Syupacman -Su更新软件包

  4. Install basic programs for msys2 pacman -S --needed base-devel mingw-w64-x86_64-toolchain安装 msys2 pacman -S --needed base-devel mingw-w64-x86_64-toolchain基本程序

  5. Install python pacman -S mingw-w64-x86_64-python安装 python pacman -S mingw-w64-x86_64-python

  6. Install libshout pacman -S mingw-w64-x86_64-libshout安装 libshout pacman -S mingw-w64-x86_64-libshout

  7. Download and extract python-shout from: https://github.com/yomguy/python-shout从: https://github.com/yomguy/python-shout下载并提取 python-shout

  8. Edit setup.py to be like this:编辑 setup.py 如下:

from setuptools import setup, Extension
import os
import sys
import setuptools

ver = '0.2.7'

with open("README.md", "r") as fh:
    long_description = fh.read()

cflags = "-IC:/msys64/mingw64/include"
libs = "-LC:/msys64/mingw64/lib -lshout"

# there must be an easier way to set up these flags!
iflags = [x[2:] for x in cflags.split() if x[0:2] == '-I']
extra_cflags = [x for x in cflags.split() if x[0:2] != '-I']
libdirs = [x[2:] for x in libs.split() if x[0:2] == '-L']
libsonly = [x[2:] for x in libs.split() if x[0:2] == '-l']

# include_dirs=[]
# libraries=[]
# runtime_library_dirs=[]
# extra_objects, extra_compile_args, extra_link_args
shout = Extension('shout', sources = ['shout.c'],
                  include_dirs = iflags,
                  extra_compile_args = extra_cflags,
                  library_dirs = libdirs,
                  libraries = libsonly)

# data_files = []
setup (name = 'python-shout',
       version = ver,
       description = 'Bindings for libshout 2',
       long_description=long_description,
       long_description_content_type="text/markdown",
       url = 'http://icecast.org/download.php',
       author = 'Brendan Cully',
       author_email = 'brendan@xiph.org',
       ext_modules = [shout],
       packages=setuptools.find_packages(),
       classifiers=[
                   "Programming Language :: Python :: 3",
                   "Programming Language :: Python :: 2",
                   "License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
                   "Operating System :: OS Independent",
               ],

       )
  1. Install setuptools pacman -S python-setuptools安装 setuptools pacman -S python-setuptools

  2. Install python-shout running: 10.a cd c/Users/Χρήστος/Desktop/python-shout-master Note that you must put your Windows username instead of mine (Χρήστος) and 10.b python setup.py install安装 python-shout 运行: 10.a cd c/Users/Χρήστος/Desktop/python-shout-master请注意,您必须输入您的 Windows 用户名而不是我的用户名(Χρήστος)和 10.b python setup.py install

and that's it.就是这样。 Python-shout module has successfully installed in your Windows machine. Python-shout 模块已成功安装在您的 Windows 机器中。 To test it just run:要测试它,只需运行:

python 
>>import shout
>>s = shout.Shout()
>>print("Using libshout version %s" % shout.version())

After that you can install pyinstaller from source in MSYS2 console ( https://github.com/pyinstaller/pyinstaller ) download and extract, then run python setup.py install之后,您可以在 MSYS2 控制台 ( https://github.com/pyinstaller/pyinstaller ) 中从源代码安装 pyinstaller 并解压,然后运行 python setup.py install

and finally run pyinstaller --onefile icecast_program.py最后运行 pyinstaller --onefile icecast_program.py

and then you will have an exe that can be run in every Windows system.然后您将拥有一个可以在每个 Windows 系统中运行的 exe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM