'Mac doesn't read pytube package

I've a problem while making a YouTube downloader with pytube. I installed the package with

pip3 install pytube
python3 -m pip install pytube

And I have python3 installed on my machine but when I check which Python version I'm using in the terminal within VS Code, it says Python 2.7

This is my code

from pytube import YouTube

link = ('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
#link = input("please enter the video url: ")

link = YouTube(link)

print("the video title is:{}".fomrat(link.title))

And this is the error

Traceback (most recent call last):
  File "youtube-downloader.py", line 8, in <module>
    kick = YouTube(link)
  File "/opt/miniconda3/lib/python3.7/site-packages/pytube/__main__.py", line 91, in __init__
    self.prefetch()
  File "/opt/miniconda3/lib/python3.7/site-packages/pytube/__main__.py", line 183, in prefetch
    self.js_url = extract.js_url(self.watch_html)
  File "/opt/miniconda3/lib/python3.7/site-packages/pytube/extract.py", line 143, in js_url
    base_js = get_ytplayer_config(html)["assets"]["js"]
  File "/opt/miniconda3/lib/python3.7/site-packages/pytube/extract.py", line 202, in get_ytplayer_config
    raise RegexMatchError(caller="get_ytplayer_config", pattern="config_patterns")
pytube.exceptions.RegexMatchError: get_ytplayer_config: could not find match for config_patterns


Solution 1:[1]

I have the same problem. I have accidentally downloaded python 3.11 alpha release. (The version is incomplete, it can't be used like stable releases.)

But I can't get Mac to run the most recent stable release 3.10, since a newer version is already in the system.

I don't wanna delete the library folders. So everytime I download a package or anything, I download it with the specific python version, and I make sure to run my preferred version in the IDE. That way you can work with a specific version.

ex ; I downloaded pytube with the command, $ pip3.10 install pytube

instead of, $ pip install pytube

'pip' command downloads the pytube package to the default version that runs on your computer. 'pip3.10' downloads the package to the specified version.

Usually, the most recent version is the one that's gonna run in on your computer if it's a Mac. In windows, I guess you can change it from the paths manually or something. (I'm not sure about windows, I use Mac)

Solution 2:[2]

1--> do you have python extension installed on your vs code ? check this by tabbing the extension icon on the left of your screen 2--> make sure that there is no multiple python versions installed on your machine

Solution 3:[3]

Please close the currently used terminal (click the "Kill Terminal" icon), then use the shortcut key Ctrl+Shift+` (or click "Terminal", "New Terminal") to open a new VS Code terminal, and then use the command "python --version" (or "pip --version") Check the source of the currently used python or pip, and the module is installed in this python environment.

enter image description here

If the python3 environment has been selected in the lower left corner of VS Code, but the newly created terminal is still in python3, please make sure that the first python environment variable is this python3. The VS Code terminal uses the first python environment by default.

enter image description here

In addition, after setting the python environment variable, please reopen VS Code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ahmed Yasser
Solution 3