Categories
Python Answers

How to fix installation issues for PyAudio, PortAudio: “fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory” with Python?

Sometimes, we want to fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory" with Python.

In this article, we’ll look at how to fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory" with Python.

How to fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory" with Python?

To fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory" with Python, we install pipwin and use it to install pyaudio.

To fix this, we run

pip install pipwin
python -m pipwin install pyaudio

to install pipwin.

And then we use pipwin to install pyaudio with

python -m pipwin install pyaudio

on Windows.

On Ubuntu distributions, we run

sudo apt install portaudio19-dev

to install the portaudio19-dev package before installing pyaudio.

Conclusion

To fix installation issues for PyAudio, PortAudio: "fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory" with Python, we install pipwin and use it to install pyaudio.

Categories
Python Answers

How to download NLTK data with Python?

Sometimes, we want to download NLTK data with Python.

In this article, we’ll look at how to download NLTK data with Python.

How to download NLTK data with Python?

To download NLTK data with Python, we use the download method.

For instance, we write

import nltk

nltk.download('punkt')

to call download to download the punkt sentence tokenizer.

We can also download a basic list of data with

nltk.download('popular')

Conclusion

To download NLTK data with Python, we use the download method.

Categories
Python Answers

How to extract the n-th elements from a list of tuples with Python?

Sometimes, we want to extract the n-th elements from a list of tuples with Python.

In this article, we’ll look at how to extract the n-th elements from a list of tuples with Python.

How to extract the n-th elements from a list of tuples with Python?

To extract the n-th elements from a list of tuples with Python, we can use list comprehension.

For instance, we write

elements = [(1,1,1),(2,3,7),(3,5,10)]
n = 1
l = [x[n] for x in elements]

to get the 2nd element from each tuple x in the elements list and assign the list to l.

Conclusion

To extract the n-th elements from a list of tuples with Python, we can use list comprehension.

Categories
Python Answers

How to fix Can not click on a Element: ElementClickInterceptedException in Python Selenium?

Sometimes, we want to fix Can not click on a Element: ElementClickInterceptedException in Python Selenium.

In this article, we’ll look at how to fix Can not click on a Element: ElementClickInterceptedException in Python Selenium.

How to fix Can not click on a Element: ElementClickInterceptedException in Python Selenium?

To fix Can not click on a Element: ElementClickInterceptedException in Python Selenium, we can use move_to_element to move to the element we want to click on before we call click.

For instance, we write

element = driver.find_element_by_css('div[class*="loadingWhiteBox"]')
webdriver.ActionChains(driver).move_to_element(element).click(element ).perform()

to get the div with class loadingWhiteBox with find_element_by_css.

Then we use

webdriver.ActionChains(driver).move_to_element(element)

to move to the returned element.

Next, we call click with element and then perform to do the click on the element.

Conclusion

To fix Can not click on a Element: ElementClickInterceptedException in Python Selenium, we can use move_to_element to move to the element we want to click on before we call click.

Categories
Python Answers

How to get item frequency count in Python?

Sometimes, we want to get item frequency count in Python.

In this article, we’ll look at how to get item frequency count in Python.

How to get item frequency count in Python?

To get item frequency count in Python, we can use the Counter class.

For instance, we write

from collections import Counter

words = "apple banana apple strawberry banana lemon"
c = Counter(words.split())

to split the words in words with split.

Then create a Counter object with the list of strings split from words to get an object with the count of each word.

Conclusion

To get item frequency count in Python, we can use the Counter class.