Python Pydub Permission denied? - python-2.7

When i run this code :
from pydub import AudioSegment
sound = AudioSegment.from_mp3("i.mp3")
sound.export("F:\\bh", format="wav")
A ffmpeg window pops up and i get this error:
Even if i run it with admin privilleges:
Note :
The error occurs on every location that I try to export

If you are on Windows, face this problem, and also have issues installing simpleaudio, you can try installing pyaudio instead.
If you are using Anaconda, you can install pyaudio with
conda install -c anaconda pyaudio
For me, simpleaudio on Anaconda is only available for Linux and MacOS and not Windows.

See this thread here. They suggest installing simpleaudio (pip install simpleaudio) to resolve this issue. It worked for me.

I had the same issue but fixed using the GillHawk solution from this thread (same link as Jondiepdoop gave). I added f.close() in the _play_with_ffplay function of the playback.py file :
def _play_with_ffplay(seg):
with NamedTemporaryFile("w+b", suffix=".wav") as f:
f.close() # close the file stream
seg.export(f.name, "wav")
subprocess.call([PLAYER, "-nodisp", "-autoexit", "-hide_banner", f.name])

Related

how do i fix "No module named 'win32api'" on python2.7

I am trying to import win32api in python 2.7.9. i did the "pip install pypiwin32" and made sure all the files were intalled correctly (i have the win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32). i also tried coping the files from C:\Python27\Lib\site-packages\pywin32_system32 to C:\Python27\Lib\site-packages\win32. I also tried restarting my pc after each of these steps but nothing seems to work! i still get the error 'No module named 'win32api''
Well, turns out the answer is upgrading my python to 3.6.
python 2.7 seems to old to work with outside imports (I'm just guessing here, because its not the first time I'm having an import problem)
hope it helps :)

Python Image Library fails with message “IOError: decoder jpeg not available” - PIL when compile in SageMath Notebook

I'm facing an strange problem with PIL. Whenever I am compiling the following code with python everything is ok:
from PIL import Image
file=Image.open("si.jpg")
file2=file.convert("L")
pix = file2.load()
print pix
colsize,rowsize=file2.size
for i in range(rowsize):
for j in range(colsize):
if pix[j,i]>250:
pix[j,i]=250
file2.save("ci2.pgm")
But when I compile the above code in SageMath Notebook, it gives an error “IOError: decoder jpeg not available”. Here is the scrrenshot :
I have found a similar problem here, but these solution does not work for me. My OS is Ubuntu 16.04 (32bit).
The image link :)
I want to get solution for SageMath. How do I solve this issue?
It seems your version of the Python package "Pillow"
(the Python Image Library) is missing the decoder for jpg.
To install it, quit Sage, and in a terminal, run the following:
$ sudo apt-get install libjpeg-dev
$ sage --pip install --no-cache-dir -I pillow
Then restart Sage and try running your code again.

ImportError: No module named vaderSentiment

I'm trying to run a code in python2.7 on windows os that uses sentiment analysis
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
and I'm getting this error
ImportError: No module named vaderSentiment
Can anyone help me with this?
Assuming you solved this one as it's from 7 months ago, but for anyone else searching for it:
Go into terminal/cmd and paste the following:
pip install vaderSentiment
More info on VADER: https://github.com/cjhutto/vaderSentiment
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
#note: depending on how you installed (e.g., using source code download versus pip install), you may need to import like this:
#from vaderSentiment import SentimentIntensityAnalyzer
read the comment in a code
Try running your file with Python3 instead of just python. Sometimes when you have different pips/pythons installed on your computer you might have vaderSentiment installed in python2 when you need to run it in python3.

ImportError: No module named twisted.internet

I installed python 2.7.5 which is working fine.
I then install scrapy (which, I think, uses twisted internally). My scrapy spider is also working fine.
I installed twisted:
sudo apt-get install python-twisted
Then, I created a sample program using Echo Server code shown here
Here is the code
from twisted.internet import protocol, reactor
class Echo(protocol.Protocol):
def dataReceived(self, data):
self.transport.write(data)
class EchoFactory(protocol.Factory):
def buildProtocol(self, addr):
return Echo()
reactor.listenTCP(1234, EchoFactory())
reactor.run()
I try to run this code using this command:
$ python twistedTester.py
Traceback (most recent call last):
File "twistedTester.py", line 1, in <module>
from twisted.internet import protocol, reactor
ImportError: No module named twisted.internet
Can anyone help me with how I can debug why my twisted package is not being picked up by Python installation?
If you use pip just try:
pip install twisted
The same works with w3lib and lxml.
On some *nix systems this might give you a permission error. If that happens, try:
sudo -H pip install twisted
I figured out why this error was happening. For some reason, using apt-get to install a python package was not installing it right.
So, I had to download a tar ball and install the package from them.
I downloaded Twisted tar from here.
I did a tar xjf Twisted-13.1.0.tar.bz2 - this created a directory called Twisted-13.1.0
next, cd Twisted-13.1.0
Finally, python setup.py install
This gave me an error. Twisted required another package called zope.interface. So, I downloaded tar ball for zope.interface from here. Then, ran this command tar xzf zope.interface-3.6.1.tar.gz That created a folder called zope.interface-3.6.1. So, cd into zope.interface-3.6.1 and run python setup.py install
Note: Depending on your user's rights, you may want to do these commands in sudo mode. Just add the keyword sudo before every command.
please rename the file twisted.py to something else. whenever you import a function from a file the interpreter will search for the file in the current location and then it searches in the library. so if you have any file in the name of "twisted.py" you should probably rename it.
after renaming it. dont fail to remove the twisted.pyc file before running it again.
It happened to me too. Finally I figure out that there is a file named twisted.py my present working directory. I removed twisted.py and twisted.pyc. Problem resolved.
Looks like Twisted may have removed the twisted.internet module from the current release. Pinning on the version required by scrapy (17.9.0) worked for me:
$ pip install twisted==17.9.0
Checking if it's installed:
$ python -c "import twisted.internet; print(twisted.internet)"
<module 'twisted.internet' from '/Users/username/dev/env/redacted-ewmlD2h2/lib/python3.7/site-packages/twisted/internet/__init__.py'>
I figured out why apt-get install python-twisted was not enough or "installing it right", as you said, user1700184.
I use Debian Wheezy and Python 2.7.
I just had to move the folder named "twisted" from /usr/lib/python2.7/dist-packages/ to /usr/lib/python2.7/
The same has to be done with the package "zope" and any other one that you do install but is not retrieved when you try run your code.
However, why this is even necessary in my case is still a mystery since my sys.path does include both /usr/lib/python2.7/ and /usr/lib/python2.7/dist-packages, so whatever was under dist-packages should have been retrieved by the interpreter.
I think it is worth noting that if you use sudo to launch python you are using your original default system python. This is NOT the python that your PATH points to. For example if you are using Anaconda and you have updated your path such that which python points to path/to/anaconda/bin/python, sudo which python will still point to usr/bin/python.
So obviously sudo python twistedTester.py will not find the twisted module. To get around this you should explicitly pass the path to the anaconda python. Like so:
sudo path/to/anaconda/bin/python twistedTester.py

SimpleCV 1.3 is not

I just install SimpleCV 1.3 on Windows 7. During the install I got a message: "this program could not have been correctly installed setuptools-0.6c11.win32-py2.7.exe". When I run the first example
>>> logo = Image("simplecv")
>>> logo.show()
I got an empty python window and I get a warning: "You need the python image library to save by filehandle"
Someone knows how to fix this?
thanks in advance
After the install error message, did you try reinstalling?
SimpleCV is supposed to include all the libraries it needs, so when installation failed it must have missed some libraries.
You could try installing the python image library (PIL) yourself.
I usually use this web site as a source of python libraries: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil (I think you should use Pillow-2.0.0.win32-py2.7.‌exe)