the packages pydub.AudioSegment in python doesn't work on window7? - python-3.x

I am using python on the window7, python3 ver, jupyter(or pycharm both).
I installed the pydub package for some reasons,
that converting *.mp3 to *.wav file at the same time
and split to mp3 file to per 40sec files,
and I checked it installed successfully.
"Requirement already satisfied: pydub in c:\programdata\anaconda3\lib\site-packages (0.22.1)"
but when I typed like bellows,
from pydub import AudioSegment
song = AudioSegment.from_mp3('D:\a'+'.mp3' )
it caused the error like:
C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py:165: RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work
pydub ffmpeg
so I try to installed ffmpeg but it's impossible with this message:
Could not find a version that satisfies the requirement subprocess (from ffmpeg) (from versions: )
No matching distribution found for subprocess (from ffmpeg)
so I found another way to solve it in here:
import pydub
pydub.AudioSegment.converter = "C:\path\to\ffmpeg.exe"
but another error shows up like this:
C:\ProgramData\Anaconda3\lib\site-packages\pydub\utils.py:193: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
as like many guys stuck in the same error.
I read many solutions about these, but nothing to make it better.
Anybody help me with this problem with a code in detail.

I have w8.
If i use this, i have а error.
AudioSegment.converter = ffmpeg_catalog+'ffmpeg.exe'
AudioSegment.ffmpeg = ffmpeg_catalog+'ffmpeg.exe'
AudioSegment.ffprobe = ffmpeg_catalog+'ffprobe.exe'
But when i add "C:\ffmpeg\bin" to PATH and restart os, it works.
And you must to remove lines above.

Related

Hydrogen package in Atom IDE returns import error for all python packages e.g. numpy, nltk etc

I am new to using stackoverflow, so any advice for asking questions more clearly is welcomed.
I am trying to use hydrogen in atom to run python scripts on a mac M1 chip, which has worked for me in the past. After a clean laptop wipe, it no longer works. I receive the following errors:
For numpy, I get this: "Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed." ...
Original error was: dlopen(/Users/user/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/user/Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/_multiarray_umath.cpython-38-darwin.so' (no such file), '/usr/lib/_multiarray_umath.cpython-38-darwin.so' (no such file)
And then, for nltk:
dlopen(/Users/user/Library/Python/3.8/lib/python/site-packages/regex/_regex.cpython-38-darwin.so, 0x0002): tried: '/Users/user/Library/Python/3.8/lib/python/site-packages/regex/_regex.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/usr/local/lib/_regex.cpython-38-darwin.so' (no such file), '/usr/lib/_regex.cpython-38-darwin.so' (no such file)
I have followed the all tutorials I can find online, but no luck.
If it helps, my paths for jupyter and python are the following, respectively:
/usr/local/share, /usr/bin/python3
Also, my python and numpy versions are up to date and the versions I expect.
The way I made it work was to add at the top of my .py file:
import sys
sys.path.append('/Users/[username]/opt/anaconda3/envs/[your_virtual_env_name]/lib/python3.10/site-packages')
I combined the solution from the answer and a comment from Tell Atom+Hydrogen to look in virtual enviromnment for packages

Exception has occurred: ModuleNotFoundError No module named 'cv2'

I have code that requires: import cv2
but get the error message: Exception has occurred: ModuleNotFoundError
No module named 'cv2'
I have seen exactly the same question before, but all the suggestions fail. The question is 6 years old and hence am repeating it.
various failed suggestions:
conda install --channel https://conda.anaconda.org/menpo opencv3
conda install -c menpo opencv
I am using Windows 10 and have python 3.8.1 running.
I have removed cv2 from the code which works without error and resolves the issue.
The link here (at time of writing, version 4.1.2.3) describes the opencv-python package:
opencv-python link
With the following description of cv2 towards the bottom of the page:
It's easier for users to understand opencv-python than cv2 and it makes it easier to find the package with search engines. cv2 (old interface in old OpenCV versions was named as cv) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet. Changing the import name or behaviour would be also confusing to experienced users who are accustomed to the import cv2.

Python Pillow and Font Conversion

I have just installed python pillow 5 on a raspberry pi. It installed fine, and works ok.
The issue i am having is finding a pilfont.py file.
I have several bdf fonts i need to convert and have been searching the web for how to do this.
All the information i have found points to the pilfont utility, but i cant find it on the pi.
Can anyone point me in the right direction as to where it is, I understand how to use it to convert the fonts, just can not activate it.
cheers
As of at least October 2018, the previous answer doesn't work anymore since the package does not include the pilfont utility. But it turns out you don't need to spend time hunting down an external utility, since pilfont is just a very simple script you recreate in just a couple of minutes.
Here's my own "pilfont utility" which converts all the .bdf and .pcf fonts in the current directory to .pil and .pbm:
#!/usr/bin/env python
# Author: Peter Samuel Anttila
# License: The Unlicense <http://unlicense.org, October 16 2018>
from PIL import BdfFontFile
from PIL import PcfFontFile
import os
import glob
font_file_paths = []
current_dir_path = os.path.dirname(os.path.abspath(__file__))
font_file_paths.extend(glob.glob(current_dir_path+"/*.bdf"))
font_file_paths.extend(glob.glob(current_dir_path+"/*.pcf"))
for font_file_path in font_file_paths:
try:
with open(font_file_path,'rb') as fp:
# despite what the syntax suggests, .save(font_file_path) won't
# overwrite your .bdf files, it just creates new .pil and .pdm
# files in the same folder
if font_file_path.lower().endswith('.bdf'):
p = BdfFontFile.BdfFontFile(fp)
p.save(font_file_path)
elif font_file_path.lower().endswith('.pcf'):
p = PcfFontFile.PcfFontFile(fp)
p.save(font_file_path)
else:
# sanity catch-all
print("Unrecognized extension.")
except (SyntaxError,IOError) as err:
print("File at '"+str(font_file_path)+"' could not be processed.")
print("Error: " +str(err))
For those on a tight deadline:
You don't need the utility. Just use the following code to convert it yourself:
with open(font_file_path,'rb') as fp:
p = BdfFontFile.BdfFontFile(fp) #PcfFontFile if you're reading PCF files
# won't overwrite, creates new .pil and .pdm files in same dir
p.save(font_file_path)
It throws SyntaxError and/or IOError in case the file can't be read as a BDF or PCF file.
Seems you installed pillow 5 via pip3. I did this myself, too and it did not include the pilfont utility. Even did not find the file in the pillow git. Did not find a deprecated info either. Therefore I suggest this workaround:
create an empty dir and change into it.
Now:
apt-get download python3-pil
to download the raspbian package which includes pillow 4 including pilfont. This does not install the package.
Next extract your downloaded deb package. Filename may vary:
ar -x python3-pil_4.0.0-4.deb
After that you have some files one is data.tar.xz which you need to extract:
tar -xvf data.tar.xz
This gives you ./usr/bin/pilfont
Now you may copy it to /usr/bin/
sudo cp ./usr/bin/pilfont /usr/bin/pilfont
After that you can delete the downloaded archive and its extracted contents.

ImportError when using cx_Freeze with scipy

I'm trying to use cx_Freeze to generate a .app from a python project. Generally I have it working, but some of my modules which depend on scipy have an import error when executed:
No module named '_csr'
under the build folder I see a file:
scipy.sparse.sparsetools._csr.so
and watching the output of the build command seems to suggest that it's copying csr:
$ python3 setup.py bdist_mac | grep csr
m scipy.sparse.csr /usr/local/lib/python3.3/site-packages/scipy/sparse/csr.py
m scipy.sparse.sparsetools._csr /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/_csr.so
m scipy.sparse.sparsetools.csr /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/csr.py
? _csr imported from scipy.sparse.sparsetools.csr
? os.path imported from NIF_WRF.util.StopPow, distutils.file_util, matplotlib.backends.backend_tkagg, matplotlib.cbook, numpy.core.memmap, numpy.distutils.command.scons, os, pkg_resources, pkgutil, scipy.lib.blas.scons_support, scipy.lib.blas.setup, scipy.lib.lapack.scons_support, scipy.linalg.setup, scipy.sparse.csgraph.setup, scipy.sparse.linalg.dsolve.setup, scipy.sparse.linalg.eigen.arpack.setup, scipy.sparse.linalg.isolve.setup, scipy.sparse.sparsetools.bsr, scipy.sparse.sparsetools.coo, scipy.sparse.sparsetools.csc, scipy.sparse.sparsetools.csgraph, scipy.sparse.sparsetools.csr, scipy.sparse.sparsetools.dia, scipy.special.setup, shutil, sysconfig
? scipy.lib.six.moves imported from scipy.integrate.quadrature, scipy.interpolate.interpolate, scipy.interpolate.polyint, scipy.linalg.special_matrices, scipy.misc.common, scipy.optimize.anneal, scipy.optimize.linesearch, scipy.optimize.nonlin, scipy.sparse.base, scipy.sparse.compressed, scipy.sparse.coo, scipy.sparse.csc, scipy.sparse.csr, scipy.sparse.dok, scipy.sparse.lil, scipy.sparse.linalg.eigen.lobpcg.lobpcg, scipy.sparse.linalg.isolve.lgmres, scipy.spatial.distance, scipy.special.basic, scipy.stats.stats
copying /usr/local/lib/python3.3/site-packages/scipy/sparse/sparsetools/_csr.so -> build/exe.macosx-10.8-x86_64-3.3/scipy.sparse.sparsetools._csr.so
The problem seems to be related to this other question but that user seemed to solve it by building again, which hasn't helped here. Any ideas?
UPDATE
I mucked around in the .app package contents and found that renaming scipy.sparse.sparsetools._csr.so to _csr.so solves that error (though generates another similar one for another scipy component). It seems like the cx_Freeze script is not properly naming scipy inputs.
Also, here are the versions I'm using:
cx_Freeze: 4.3.2
scipy: 0.13.0
python: 3.3.2

python3 importing pygame results in PyCObject_AsVoidPtr

I have encountered difficulty putting pygame together with python3 on my MacBookPro.
I installed Python 3.3, and my MacOS is running version 10.7.5.
Then I downloaded pygamev1.9.1 source code, and followed instructions in http://programming.itcarlow.ie/PyGameInstall.pdf
Compilation and installation was smooth until I issued "import pygame" inside python3.
Then I encountered the following "PyCobJect_AsVoidPtr" error (further text following error message):
import pygame
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/init.py", line 95, in
from pygame.base import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so, 2): Symbol not found: _PyCObject_AsVoidPtr
Referenced from: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/pygame/base.so
A search on google indicates this symbol has been removed since Python3.2:
http://mail.python.org/pipermail/python-dev/2011-March/108882.html
Can someone please give me some advice on how to get pygame working on Python3.3?
More so, whereas I am aware the pygame/python3 developers are busy with their work, but I would certainly appreciate it if someone can provide precompiled pygame binaries for python3. I have limited computer skills, and I just want to go ahead and learn Python3 and pygame, and this is seriously stunting my interest.
I notice that you were trying to compile from source, but builds on Python 3.3, to my knowledge, are not yet supported (as of January 2013). In fact, the only binaries I'm aware of for PyGame and Python 3.3 are unofficial builds and Windows only.
You should consider instead using a previous version of Python (e.g. Python 2.7.*), PyGame builds/binaries on which are well-supported. Any points on setting up should be directed to the pygame-users mailing list, if they weren't already.

Resources