ImportError: cannot import name 'gTTS' on Ubuntu 18.04 - python-3.x

I am trying to write a python script which can speak text. I wrote this simple code using gtts, which works on my macbook, but has import errors when I try to run it on Ubuntu 18.04
st.py
import os
mytext = "Python can speak!"
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("welcome.mp3")
os.system("mpg321 welcome.mp3")
I am using python3 to run it on ubuntu, and I have installed gtts using pip3, but it's not able to find gTTS. This is the error I am getting -
File "connector.py", line 4, in <module>
from gtts import gTTS
ImportError: cannot import name 'gTTS'
I have tried uninstalling and re-installing gtts module and python3, but no luck.

First make sure you are in the appropriate virtual environment if you are using one.
Then try running $ python3 -m pip install gTTS without sudo
If that is the command you already used to install gTTS, try running
pip list to see if gTTS is listed there.
Check to make sure that the gtts folder exists in lib/python3.X/site-packages/

Related

cannot import module imageio in python3

Using python3, I am unable to import the imageio module into my python program, which I need, as I try to animate a list of PNG images I have. Thus far I have tried:
"pip3 install imageio" both running as myself and as root. The install succeeded, but it still errors out as in the subject line. I suppose I could try "apt-get install (package name)", but need to determine the package_name.
Any ideas more than welcome - TIA.
Try importing the last version.
import imageio.v3 as iio
im = iio.imread('imageio:chelsea.png')
print(im.shape) # (300, 451, 3)
ref https://imageio.readthedocs.io/en/stable/examples.html

ModuleNotFoundError: No module named 'win32api

I am using embedded python 3.7.4
Getting the folliwng error when trying to create new file in jupyter notebook
File "D:\Users\sgangop7\python3.7.4\Lib\site-packages\jupyter_core\paths.py", line 387, in win32_restrict_file_to_user
import win32api
ModuleNotFoundError: No module named 'win32api'
Solutions Tried:
fresh install of jupyter notebook
pip install pypiwin32
pip install pywin32
Running the pywin32_postinstall.py
Added 'D:\Users\sgangop7\python3.7.4\Lib\site-packages' in the PATH variable of environment variable
Copied 'win32api.pyd' to 'D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib'
I cannot find any other solution for how to fix this issue.
On your jupyter notebook, you can try these commands :
import sys
sys.path
You will see a list of paths which Python is using to find packages. If your path "D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib" isn't in the list, you may need to add it. You can do it like this :
sys.path.insert("D:\Users\sgangop7\python3.7.4\Lib\site-packages\win32\lib")
Good luck !

issue plotting .cap files ScaPy Python3

After reading .cap file using rdpcap successfully, I've been trying to use the function pdfdump but it keeps giving me an error:
"AttributeError: 'SingleTexRunner' object has no attribute 'texoutput' "
here's my code:
from scapy.all import *
import pyx
a = rdpcap("the file path..")
a.pdfdump("output filename")
anyone got an idea how to solve this issue?
Use sudo apt-get install python3-pyx on Linux(Debian, Ubuntu...) to install pyx and its dependencies; installing pyx with pip install pyx is not enough.
I'm using Python 3.6.0
I've installed scapy with:
pip3 install scapy-python3
Using wireshark 2.2.3, I saved a dump using the default file format which is .pcapng
I've used the same code as you :
from scapy.all import *
import pyx
a = rdpcap("test.pcapng")
a.pdfdump("test.pdf")
and I obtain a valid pdf.
Don't run scapy (if you use the command line) or your script as root. This fixed it for me.

SSHTunnel not installed correctly?

I'm using anaconda python 3.5.2 in PyCharm using windows 10.
I'm pretty new to python and a complete noob to PyCharm!
I just want to use SSHtunnel.
I have intalled the package and it shown in the project interpreter page:
However when I try to run the code which I cut and pasted from example 1 here https://github.com/pahaz/sshtunnel:
from sshtunnel import SSHTunnelForwarder
server = SSHTunnelForwarder(
'pahaz.urfuclub.ru',
ssh_username="pahaz",
ssh_password="secret",
remote_bind_address=('127.0.0.1', 8080)
)
server.start()
print(server.local_bind_port) # show assigned local port
# work with `SECRET SERVICE` through `server.local_bind_port`.
server.stop()
I get the following error:
C:\Users\HP\Anaconda3\python.exe C:/Users/HP/PycharmProjects/SSH_Downloader/SSH_Downloader
Traceback (most recent call last):
File "C:/Users/HP/PycharmProjects/SSH_Downloader/SSH_Downloader", line 1, in <module>
from sshtunnel import SSHTunnelForwarder
ImportError: cannot import name 'SSHTunnelForwarder'
Process finished with exit code 1
How can I sort this out?
Just run the command below:
pip install sshtunnel
sshtunnel for python and sshtunnel Anaconda-python are different modules.
To install sshtunnel for Anaconda; you need to use the Anaconda repository. use below pip command; Hope this helps:
pip install -i https://pypi.anaconda.org/pypi/simple sshtunnel
More Description Here
I think your name of file is sshtunnel.py
i face this problem on window 10 and fix it buy this line
easy_install sshtunnel

Pip in python34 does not work properly (OS Windows)

I'm writing a data extraction from xls python script using xlrd. I'm having trouble however with pip, I just managed to get a positive reply from the cmd when i requested (I had some trouble with it at first, but a few posts helped out)
py -m install requests
The response I now get is: "Requirement already satisfied." (with some mention of update since my pip version is 6.0.8 and there's a 7.0.1 available)
However, when I run my code part of which can be seen below I get a syntax error.
import xlrd
from xlrd import open_workbook
import xlwt
workbook = xlrd.open_workbook('editable.xls')
The error:
File "C:\Python34\lib\site-packages\xlrd__init__.py", line 1187
print "EXTERNSHEET(b7-):"
^ SyntaxError: invalid syntax
I run your program on Ubuntu/Linux and it runs fine.
I will recommend to follow my instructions for installing the xlrd on your Windows machine.
From here download the latest version of the xlrd.
Then extract the file, and using the command prompt in the new xlrd directory type:
python3 setup.py install
Unfortunately I don't own a Windows machine so I can't guaranteed to you that this is the right way to install it.
The trick was that you should run the setup.py using the python3 and not the python
(note that on my machine, I run the above command using sudo, which means in Linux administration permissions, so if you have any problems try to run your command prompt with administration permissions.)
I test this code on my Ubuntu machine:
import xlrd
from xlrd import open_workbook
workbook = xlrd.open_workbook('Untitled.xls')
I remove the import xlwt as I don't have this module, please try and let me know.
Edit: Also you will need the setuptools installed on your computer.

Resources