Failed to start python after installing speech_recognition package - python

I've already installed this package (SpeechRecognition) on my laptop, now I'm trying to make it work on my Imac (sierra aswell).
I followed the installation the same as on the macbook.
But when trying to run the test I get following error.
python -m speech_recognition
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "/usr/local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 5, in <module>
import io
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

Try going to terminal and typing in that:
python -m speech_recognition
or
python3 -m speech_recognition
If that's what your running.
it depends what version of python your using, Sierra comes with python IDLE 2.7.10 already installed.
if you download those modules for python it will download them to work with 2.7.10 not the 3.0 + you might be using.
so if you downloaded python3 and are trying to run it with python3 it won't work, only from 2.7.10 so try typing in.
python -m speech_recognition
Like i suggested and see if it works in the terminal, if it does then it means i was right and python 2.7.10 will work with it.

Related

Trouble downloading Python modules

I was making a Tetris game and at the top of the Python code, I put in import pygame, since that was the thing I was thinking of doing and the thing I thought I could only do. My game was complete, the terminal was open, and I ran the code. The terminal gives an error:
Traceback (most recent call last):
File "[removed for safety]", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
So I tried pip installing it with the command pip install pygame, but it just returns a similar error:
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in <module>
File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
I was using
VSCode, with Python version 3.10.5, 64-bit.
First of all you can uninstall python 3.4 from your system, with this link then you can reinstall python from from the python.org website. Then hopefully pip install pygame would work. Or, if pygame is installed run pip uninstall pygame then pip install pygame
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
Python34 is mentioned in the error code, which indicates that the terminal runtime retrieves python3.4 instead of 3.10 you mentioned.
This indicates that there are multiple versions of Python in your environment.
You can manually select the Python interpreter by using shortcut "ctrl+shift+P" and typing "python: select interpreter" or click this icon to change the interpreter:
After choosing the correct interpreter, you can use command pip install pygame to install python package at the correct python-lib.

Errors when running s3cmd installed from brew

A few weeks ago I had brew update various casks and now I can't run s3cmd. I get the following errors:
Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
File "/usr/local/Cellar/s3cmd/2.0.2_3/libexec/bin/../lib/python3.8/site.py", line 703, in <module>
main()
File "/usr/local/Cellar/s3cmd/2.0.2_3/libexec/bin/../lib/python3.8/site.py", line 694, in main
execsitecustomize()
File "/usr/local/Cellar/s3cmd/2.0.2_3/libexec/bin/../lib/python3.8/site.py", line 548, in execsitecustomize
import sitecustomize
File "/usr/local/lib/python2.7/site-packages/sitecustomize.py", line 4, in <module>
import re
File "/usr/local/Cellar/s3cmd/2.0.2_3/libexec/lib/python3.8/re.py", line 143, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
Based on the errors, I assumed this is python 3 issue. The Mac comes with python 2.7 and I use a lot of 2.7 python scripts so I don't want to make a system wide change.
Based on some research, it doesn't seem that s3cmd requires python3.
I could be very wrong about it needing python3 and it's some other issue. The rest of my python code runs just fine so it's not a fundamental issues with python and seems to only be s3cmd.
Everything in brew seems to be up to date and I've uninstalled and installed s3cmd miltiple times trying to fix this.
I am running OS X 10.14.6
Did you try that?
Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?
the two top answers were to:
pip uninstall -y enum34
OR
unset PYTHONPATH

Jupyter cannot start, "ImportError: This package should not be accessible"

I am unable to start a Jupyter notebook server on a linux machine. When I type jupyter notebook, I get the following errors:
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
During handling of the above exception, another exception occurred:
ModuleNotFoundError: No module named 'urlparse'
Here is some system info, let me know if anything else might be helpful:
$ jupyter --version
4.4.0
$ which jupyter
/usr/bin/jupyter
$ which python
/usr/bin/python
$ which python3
/usr/bin/python3
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"
$ cat /proc/version
Linux version 4.15.0-38-generic (buildd#lcy01-amd64-023) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018
$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)
When I try python2 -m pip install urlparse --user, I get an error: Collecting urlparse Could not find a version that satisfies the requirement
The reported error resembles the one shown here, but the stated solution of creating and using a python3 virtual environment doesn't seem to immediately fix the jupyter notebook command, although it does replace python and python3 executable with links to the virtual environment:
(env) $ which jupyter
/usr/bin/jupyter
(env) $ which python
/home/.../env/bin/python
(env) $ which python3
/home/.../env/bin/python3
In case there is some question about the python path, here is the path for python 2:
$ ipython
...
In [2]: sys.path
Out[2]:
['/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/home/$USER/.local/lib/python2.7/site-packages',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/home/$USER/.local/lib/python2.7/site-packages/IPython/extensions',
'/home/$USER/.ipython']
And for python3
$ ipython3
...
In [2]: sys.path
Out[2]:
['/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/$USER/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/$USER/.local/lib/python3.6/site-packages/IPython/extensions',
'/home/$USER/.ipython']
The full stack trace of the first error when starting Jupyter is:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/notebook/nbextensions.py", line 18, in <module>
from urllib.request import urlretrieve
File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
import http.client
File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
The contents of /usr/bin/jupyter are as follows:
$ cat `which jupyter`
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'jupyter-core==4.4.0','console_scripts','jupyter'
__requires__ = 'jupyter-core==4.4.0'
import re
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(
load_entry_point('jupyter-core==4.4.0', 'console_scripts', 'jupyter')()
)
One suggested answer is that there is a spurious http library, "it happens to be overridden by some 3rd-party module "http" at /home/$USER/.local/lib/python3.6/site-packages/http". When I remove this library manually, I now get an error importing the site module, as follows:
$ cd /home/$USER/.local/lib/python3.6/site-packages
$ mv ./http ~/Desktop/python_disabled/python3/
$ jupyter notebook
Error processing line 1 of /home/$USER/.local/lib/python3.6/site-packages/lazr.restfulclient-0.14.0-py3.6-nspkg.pth:
Failed to import the site module
Traceback (most recent call last):
File "/usr/lib/python3.6/site.py", line 174, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "/usr/lib/python3.6/types.py", line 171, in <module>
import functools as _functools
File "/usr/lib/python3.6/functools.py", line 21, in <module>
from collections import namedtuple
File "/usr/lib/python3.6/collections/__init__.py", line 32, in <module>
from reprlib import recursive_repr as _recursive_repr
File "/home/$USER/.local/lib/python3.6/site-packages/reprlib/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
This part is wrong:
File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
import http.client
File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
A standard module tries to import http.client, also a standard module. And in your installation, it happens to be overridden by some 3rd-party module "http" at /home/$USER/.local/lib/python3.6/site-packages/http.
Remove that 3rd-party module.
Judging by the same problem with reprlib package after uninstalling http in your updated question, you seem to have the micropython-lib set of packages installed in /home/$USER/.local/lib/python3.6. Since there are lots of them, it's easier to just delete the entire directory. I've no idea how they ended up there since they are not only incompatible with a regular CPython installation but with Python 3 in general.
Finally, note that depending on your needs, using virtualenv may be a more manageable solution than pip --user.

Anaconda Installation error on MAc OS

I am tyying to install anaconda on my mac but at the last step of installtion it gives me following error:
installing: conda-env-2.4.5-py27_0 ...
Python 2.7.11 :: Continuum Analytics, Inc.
creating default environment...
Traceback (most recent call last):
File "/Users/sdb99/anaconda2/pkgs/conda-4.0.5-py27_0/lib/python2.7/site-packages/conda/install.py", line 37, in <module>
import subprocess
File "/Users/sdb99/anaconda2/pkgs/python-2.7.11-0/lib/python2.7/subprocess.py", line 430, in <module>
import pickle
File "/Users/sdb99/anaconda2/pkgs/python-2.7.11-0/lib/python2.7/pickle.py", line 1272, in <module>
import binascii as _binascii
ImportError: dlopen(/Users/sdb99/anaconda2/pkgs/python-2.7.11-0/lib/python2.7/lib-dynload/binascii.so, 2): Library not loaded: #loader_path/../../libz.1.dylib
Referenced from: /Users/sdb99/anaconda2/pkgs/python-2.7.11-0/lib/python2.7/lib-dynload/binascii.so
Reason: image not found
Any idea how i can get ahead from here?
Thanks!
Just update python to the next version and try installing Anaconda again.
I had python 2.7 and then I updated it to python 3 and I was able to install Anaconda graphical installer successfully.

Pushbullet on python throws import error due to python-magic unable to find libmagic?

I'm trying to use PushBullet.py which uses python-magic which in turn uses libmagic.
I have followed the dependencies instructions and installed Cygwin and copied the three files to Windows\system32 directory but still getting the following error:
Traceback (most recent call last):
File "C:\New Python ActiveX Scripting Engine.py", line 1, in <module>
from pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\__init__.py", line 2, in <module>
from .pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\pushbullet.py", line 4, in <module>
import magic
File "C:\Python27\lib\site-packages\magic.py", line 161, in <module>
raise ImportError('failed to find libmagic. Check your installation')
ImportError: failed to find libmagic. Check your installation
EDIT
If I put cygmagic-1.dll OR cygz.dll into C:\Python27\ and rename it to magic.dll I get the following error:
Traceback (most recent call last):
File "C:\New Python ActiveX Scripting Engine.py", line 1, in <module>
from pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\__init__.py", line 2, in <module>
from .pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\pushbullet.py", line 4, in <module>
import magic
File "C:\Python27\lib\site-packages\magic.py", line 143, in <module>
libmagic = ctypes.CDLL(dll)
File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
If I put cygwin1.dll into C:\Python27\ and rename it to magic.dll I get the following error:
Traceback (most recent call last):
File "C:\New Python ActiveX Scripting Engine.py", line 1, in <module>
from pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\__init__.py", line 2, in <module>
from .pushbullet import PushBullet
File "C:\Python27\lib\site-packages\pushbullet\pushbullet.py", line 4, in <module>
import magic
File "C:\Python27\lib\site-packages\magic.py", line 185, in <module>
magic_open = libmagic.magic_open
File "C:\Python27\lib\ctypes\__init__.py", line 378, in __getattr__
func = self.__getitem__(name)
File "C:\Python27\lib\ctypes\__init__.py", line 383, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'magic_open' not found
I'm doing this on Windows 7 64bit running Python 32bit 2.7.8 (fresh install today to try and resolve this problem).
Does anyone know how to resolve the problem?
EDIT: Tried on a further 5 different windows computers and all 5 have the same problem(s).
I had the same problem with python-magic and solved it by fixing the following line in the magic.py file (C:\Python27\lib\site-packages\magic.py in my PC):
dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1')
Since I've installed libmagic from Cygwin, the DLL was named cygmagic-1.dll. So I simply added another choice in the previous line:
dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1') \
or ctypes.util.find_library('cygmagic-1')
Don't forget to add cygwin\bin to your PATH.
EDIT:
It seems that this issue has been addressed on the GitHub repository.
EDIT2:
These are the steps I followed to make PushBullet.py work on my machine:
Install PushBullet.py via pip (pip install PushBullet.py);
Install libmagic from Cygwin;
Add C:\cygwin\bin\ to the PATH environment variable;
Change the magic.py file as I've explained above. (In my case the error was on line 139)
From the Windows paths in your traceback listings I guess that you are trying to execute PushBullet script from Windows version of Python. Why did you install Cygwin if you are not using it? Python for Windows really won't use Cygwin's DLLs.
You have to execute PushBullet.py from Cygwin using a Python for Cygwin, not from Windows Console using a Python for Windows. That means execute for example bash (something like C:\cygwin64\bin\bash.exe --login -i) and from bash execute PushBullet script: python PushBullet.py.
It expects, that you have Python and python-magic for Cygwin (for Cygwin! not Windows version) already installed.
Copying DLLs to your system directories is nonsense, don't do it. Renaming them is uber-nonsense. How did you expect it could work? Each library is specific, you can't just rename it to change how it works internally.
I'm already using PushBullet for some time, so I was interested in this particular Python script. I'm also using the Cygwin for years. So I have installed PushBullet library:
pip install pushbullet.py
Then I have created very simple script test.py:
#!/usr/bin/python
from pushbullet import PushBullet
pb = PushBullet('my_access_token')
success, push = pb.push_note("Testing title", "Hello world!")
When I executed it using ./test.py I got an error message, that I'm missing magic library, so I installed python-magic library using Cygwin's setup utility.
I executed it again and voila - I have "Hello world!" message on my phone. Done.
Just a note again: I have executed it from the Cygwin's shell (zsh, but you'll have bash I guess), not from Windows Console. I also didn't use Python for Windows but Cygwin's version. Don't mix Windows and Cygwin executables!
So dumb-proof steps would be:
download and execute setup.exe from Cygwin.com
install python and python-magic
execute Cygwin's shell (you can execute "Cygwin Terminal" from your Start menu or just execute C:\cygwin64\bin\bash.exe --login -i for example from "Run" dialog or Windows Console)
install pip (see for example Pip install not functioning on windows 7 Cygwin install)
install PushBullet library: pip install pushbullet.py
prepare your testing script
execute it: python testing_script.py or just testing_script.py if it contains the shebang line and is executable
it should work, if not, post your errors, please
Thank you for a tip to useful library :)
You cannot mix Cygwin and MSVCRT binaries. Therefore, in order to use python-magic with the Windows Python, you must get a Windows-compiled libmagic and fix magic.py to find the libmagic DLL.
Otherwise, if you want to use Cygwin's python-magic as-is, you need to use Cygwin's python packages.

Categories