question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ImportError: cannot import name 'YoutubeSearch'

See original GitHub issue

Hey, I’m pretty sure this issue is my own fault, but whenever running the example code given I get the error:

"ImportError: cannot import name 'YoutubeSearch'"

I’ve tried installing the library on both windows and linux (I use the windows terminal), both through:

pip (or pip3) install youtube_search

and through github via

pip (or pip3) install git+https://github.com/joetats/youtube_search.git

This is the example code:

from youtube_search import YoutubeSearch

results = YoutubeSearch(‘search terms’, max_results=10).to_json()

print(results)

returns a json string

########################################

results = YoutubeSearch(‘search terms’, max_results=10).to_dict()

print(results)

returns a dictionary

I also have pytube installed if that affects anything?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cstuart1310commented, Jul 21, 2020

I’d guess that this is an environment error based on what you’re seeing - pip is probably using python2 but when you use pip3 it’s installing to a different python path

Can you try making a virtual environment so everything is consistent? This way the regular pip command will work correctly. For example, on my Mac I need to do the following to keep everything in python3:

python3.8 -m venv venv
source venv/bin/activate

pip install youtube-search

Windows would be similar:

python3.8 -m venv venv
venv\Scripts\activate

pip install youtube-search

Super sorry, whole thing was my own stupid mistake. I made a file called youtube_search.py and later abandoned it to test using a different filename, meaning that all the files in the test folder were trying to read my youtube_search file instead of the library. Deleting the youtube_search.py that I made fixed all my issues, thanks.

1reaction
cstuart1310commented, Jul 10, 2020

Didn’t mean to close, I have fat fingers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot import name "Youtube"? - python - Stack Overflow
I need help, I got stuck with a problem inside of my python code. I have installed pytube module from ...
Read more >
ImportError: cannot import name 'YouTube' from 'pytube' #564
Depends on the issue. It could mean those scripts don't exist anymore. It could mean your IDE doesn't know they exist.
Read more >
youtube-search - PyPI
Perform YouTube video searches without the API.
Read more >
cannot import name 'youtube' from partially initialized module ...
Python3.8 pytube ImportError: cannot import name 'YouTube' from 'pytube' ... from pytube import YouTube, Search screen = Tk() title = screen.title('Baixe ...
Read more >
Python Code Samples | YouTube Data API - Google Developers
from oauth2client.tools import argparser, run_flow # The CLIENT_SECRETS_FILE variable specifies the name of a file that contains
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found