Mac doesn't read pytube package - python

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

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

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)

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.
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.
In addition, after setting the python environment variable, please reopen VS Code.

Related

I keep getting an error on python path when I open terminal

I recently updated python on my mac and since then, whenever I open terminal there's the following error shown:
File "/opt/homebrew/share/man/man1/python3.1", line 1
.TH PYTHON "1"
^
SyntaxError: invalid syntax
Any idea how to resolve this issue?
Try reinstalling:
visit https://www.python.org/downloads/ on your Mac; It detects your operating system automatically and shows a big button for downloading the latest version of Python installer on your Mac.
Install (I recomend the latest python3.10, not python3.1) python, pip is included and useful for managing packages on the command line.
Open terminal and type:
$python3
into terminal, NOT:
$python
Hope this helps.

Python 3.4 and 2.7 installation no Script folder and no pip installed

I was doing a fresh installation for Python 2.7.9 and 3.4.3 on Win7 X64 today, and I found that there is no Script folder in Python27 and Python34 folder as first child level folder, but there is one in Tools. However, I couldn't find pip within that Script folder, although pip should be installed with Python by default. The other I was doing the same installation for my other PC and laptop, there was Script folder (as first level child folder in Python27 and Python34) containing pip. So what is going on? how to install pip and maybe other useful scripts this way?
[EDIT] I tried python -m ensurepip in Python34. I got the following errors:
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Exception:
Traceback (most recent call last):
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\basecommand.py", line 232, in main
status = self.run(options, args)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\commands\install.py", line 339, in run
requirement_set.prepare_files(finder)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\req\req_set.py", line 333, in prepare_files
upgrade=self.upgrade,
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 326, in find_requirement
file_locations, url_locations = self._sort_locations(locations)
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 158, in _sort_locations
sort_path(os.path.join(path, item))
File "C:\Users\daiyue\AppData\Local\Temp\tmppvmc8dv1\pip-6.0.8-py2.py3-none-
any.whl\pip\index.py", line 139, in sort_path
if mimetypes.guess_type(url, strict=False)[0] == 'text/html':
File "C:\Python34\lib\mimetypes.py", line 287, in guess_type
init()
File "C:\Python34\lib\mimetypes.py", line 348, in init
db.read_windows_registry()
File "C:\Python34\lib\mimetypes.py", line 255, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: OpenKey() argument 2 must be str without null characters or None, not str
[EDIT] The problem is due to multiple null Registry keys in HKEY_LOCAL_MACHINE that make read_windows_registry() in mimetypes.py searches failed. Here is the post that leads to the solution:
Python ‘pip’ and Windows registry corruption
thanks
If you used the PSF (python.org) .msi Windows installers, pip (and dependencies) should be installed in pythonxy/Lib/site-packages for 3.4.0+ and 2.7.9+. There should also be pythonxy/Scripts containing about 5 .exes. This is the last part of the install process. A command prompt window should briefly appear. Perhaps you did not have [ ] install pip checked when doing the installs (although this should have been checked by default). Perhaps there was an error that you missed.
In any case, you should have pythonxy/Lib/ensurepip/* present for both 2.7 and 3.4 and you should be able to run this module now. In Command Prompt, try python -m ensurepip in both .../python27 and .../python34.
Had the same issue, reinstalling didn't help.
Finally fixed it by running python -m ensurepip as administrator.
This problem is a official bug: Issue23604 .
I had encountered the same problem, and fixed it successfully using the method in
Swarley's Blog.
I ran into the same issue today while trying to install Python 2.7.13 in my computer; after some investigation I realized that v.3.60 ("Anaconda") was already present (it came along with Microsoft Visual Studio 2017, which I've installed a couple weeks ago).
I suspected of some path mismatch in the registry, so I tried removing both Python v. 3.60 and 2.17, and cleaning up the Registry by deleting the HKCU\Software\Python key (which, due to some reason, was still present).
After this, I was able to correctly install version 2.7.13, and this time the \scripts folder is present, with all the expected contents.
I don't know if installing v. 3.6 again would cause any problem: I'm not going to try this for the time since I'm currently developing for v.2.7.
Hope this can be of some help, anyway.
Max - Italy
EDIT:
I've made some further investigation and think I've discovered the reason why (in my case), the \Scripts folder was missing: the path where I was going to install Python is in virtual drive.
In my computer I only have one partition (C:), and i've mapped a folder (C:\Development) as D:, then I tried to install Python on D:\Python27; apparently this is not "good" and causes some problem in the installer.
After discovering that, I tried installing to the real path, and now everything seems to be OK.
Max.
Resolved by installing Python 2.7.13
https://www.python.org/downloads/release/python-2713/
Windows 10. I had this issue while installing Python 2.7 into C:/Program Files/Python27 .. I think in this case it was a path issue. Fix was to do an install into C:/Python27, copy the Scripts folder from that installation to the installation in C:/Program Files/Python27. Everything else (including the paths to Python and Scripts) was fine.
Based on a combination of whats here, and what I found elsewhere, here is how I fixed it:
Uninstall whatever is installed already.
Go to regedit and HKLM/SOFTWARE/Python and delete the whole python section.
Reinstall Python
This installed with the scripts folder this time.
Hope this helps someone.
Guess what? In case you have NetBeans (or probably GlassFish) installed, then it could break installation for pip!
Details: there's a bug in NetBeans installer that could sometimes break the Windows registry in a way that's not expected by other installers.
#J3soon's answer was close, but Swarley's blog post haven't fixed the problem in my environment, because it wasn't a null character but was another kind of registry corruption.
And here's how I got rid of the issue. Run the following PowerShell script:
$local_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*'
$machine_key6432 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
$items = Get-ChildItem #($local_key, $machine_key, $machine_key6432)
$ErrorActionPreference = 'Stop'
foreach ($item in $items) {
Write-Output $item.PSPath
$null = Get-ItemProperty $item.PSPath
}
It will write the registry key names to the output. In case it prints an error, take the one last key it printed and remove that from the registry (using PowerShell or regedit or whatever tool you prefer).
After that, reinstall Python, and it should install pip as intended.
I am using python 3.6.2 and faced a similar issue of missing scripts folder(also pip script) in python folder. I have done following things to add scripts folder again to python.
Goto - Control Panel\All Control Panel Items\Programs and Features
then look for python program and try to uninstall it. A pop window
will appear which shows the following image.
Image Python
Try to REPAIR the installed program that should fix the issue.
Otherwise click on MODIFY and tick on pip check box and Add Python to environment variables checkbox, then install it. This should fix the issue.
Even I was facing this issue. I solved it by doing the following steps:
Uninstall python. (you can use the installer(python-2.7.xx.msi) to perform the uninstall. Select the option 'Remove Python'on double clicking the installer.)
Edit the environment variable 'Path', and remove the python directory path. ( To change the environment variable, right click on 'This PC', click properties, click 'Advanced System Properties' ->Environment Variables)
Remove the environment variable 'Python Path' if present.
Now reinstall python.
It will work !!!
Actually Scipts folder will not create after installing python, you have to manually create this folder and then install pip, then you can find the required files in this directory.
I had also faced the same problem which i managed to solve. The problem is when you install the python in default configuration then it installs the python folder in the "c:\user\Appdata......" which is lengthy and hard to find . To avoid it first uninstall the python 3.7 completely from the system from the control panel ->uninstall program. Then install it again with the option " customize installation". On the next page change the default location to C:/Python/Python37-32 and select the required check boxes and click install. This should solve your problem.
It is permission issue. I have both python 2 and 3 installed under
C:\Program Files\python\2.7.16
C:\Program Files\python\3.7.2
Python 2 installer is msi, so there is no run as admin option when install it
Python 3 installer is exe, there is run as admin option.
As the results, python 2 installed without scripts and pip.exe and python 3 installed successfully.
To fix this, simply give the full permission to everyone on
C:\Program Files\python\ and install python 2 again. then change the permission back.
That's it.
This Command works fine for me:
python -m ensurepip
Looking in links: C:\Users\kjangala\AppData\Local\Temp\tmpvd4_442i
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
I had this issue after getting a new computer and restoring my appdata folder (an enterprise system did this automatically for me). Somehow some old metadata in my %userprofile%\AppData\Local\Programs\Python folder made the Scripts folder inside end up empty when I reinstalled Python.
I deleted this folder and uninstalled/reinstalled Python, and everything is working again.
Edit: I also had to delete %userprofile%\AppData\Roaming\Python to resolve another similar error. Interestingly, this one didn't get recreated on the reinstall.
It is simple,
Download this file Get Pip. Save it in your local with the extension .py
To run in windows:
1.) Open cmd
2.) type "python" and check if python is been installed
3.) type "python filePath.py" (example if you saved your file in C drive go the particular folder and run the command - Here "filePath.py" is the filename you saved)
command looks like this
4.) Cheers now it should work
5.) To check if pip installed properly type "pip --version"
I had the same issue (win 10, py 3.8.5, executable installer). The solution i've found is to install python to non-standard catalog (D:/ instead of windows user folder which is under access protection). In this case, the file "easy_install.exe" will be created in the Scripts folder. Then open console inside the folder and call "easy_install pip", this will install pip. After that just copy everything to the standard catalog and don't forget to change the environment variables.

"ImportError no module named gnuradio" when trying to execute ./uhd_fft

I have followed instructions out lined here:
http://forums.nuand.com/forums/viewtopic.php?f=9&t=2804
and installed GNU Radio from GIT repo (scroll down to the section that says "Building GNURADIO from GIT". I used the ./build-gnuradio.sh script to do this and it took a while, but it appeared to build successfully, as per the instructions.
I am running on Ubuntu 12.04 LTS.
When I attempt to run the "./uhd_fft" function I get the following error message:
Traceback (most recent call last):
File "./uhd_fft", line 23, in <module>
from gnuradio import gr, gru
ImportError: No module named gnuradio
I have Googled this error message and most of the forums claim there is a problem with the PYTHONPATH.
When I do
echo $PYTHONPATH
/usr/bin/python2.7
But when I check the python2.7 directory I do not see gnuradio. So I guess it makes sense I'm getting an import error when it tries to import gnuradio. But the bigger question is why?
I installed GNU Radio (per instructions from nuand forum) using ./build-gnuradio.sh script. So I should have it installed.
I would appreciate if it python / GNU Radio experts from the community could weigh in.
There is a section later in the instructions with this boldface label:
Now for some voodoo to get the new program installed into system libraries and python paths and executable path.
Those instructions lead you through modifying your PYTHONPATH to pick up the gnuradio module, among other things. If you have followed those instructions, you will have to start a new shell to see any effect, or execute the .sh file by hand, since profile scripts only run when a new shell starts up or when they're run manually.
One of the reason for this error is, when the default python is selected incorrectly. To see which python is selected type the following command in the Terminal:
"sudo port select python"
it will display all the python available on your mac.
like:
python26
python27-apple(Active)
python27
For Gnuradio you need python27,if other python is active like in the example above you can change it by the following command:
"sudo port select python python27"
Now RUN your python code,it should work.If python27 is already active you may consider changing the path manually as suggested by others
Try this once the PATH variables have been set.
ln -sf /usr/lib/x86_64-linux-gnu/libvolk.so.1.3.1 /usr/lib/x86_64-linux-gnu/libvolk.so.1.3
On OSX 10.12.3 (16D32) this worked for me:
export PATH=/opt/local/bin:$PATH
python
> import gnuradio
For me python at the prompt was using Mac's python instead of the one in
/opt/local/bin/python
The link you have provided also mentioned that you might need to add dist-packages and site-packages.
The following command solved the issue for me:
export export PYTHONPATH=/usr/local/lib/python3/dist-packages:/usr/local/lib/python3.6/dist-packages:\
/usr/local/lib/python3/site-packages:/usr/local/lib/python3.6/site-packages:$PYTHONPATH

Python Spyder reset

I was using python(x,y), which came with Spyder. Yesterday, Spyder crashed I can't figure it out how to fix it. I uninstalled python(x,y) and reinstalled, still the same problem.
If I try to open Spyder I get this message:
Spyder crashed during last session
If Spyder does not start at all and before submitting a bug report, please try to reset setting to defaults by running Spyder with the command line option '--reset:
python spyder --reset
Of course, I tried to do the above, but it doesn't seem like I have Spyder in my path. When I try to put
python spyder --reset
in my command prompt window, I get this error message:
python: can't open file 'spyder': [Errno 2] No such file or directory
I made some attempts of trying to add spyder to path, but they all failed. How should I go about adding Spyder to path?
I am using Windows Vista on a 32 bit system.
My Spyder Crash report looks like this:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 1547, in main
mainwindow = run_spyder(app, options)
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 1472, in run_spyder
main.setup()
File "C:\Python27\lib\site-packages\spyderlib\spyder.py", line 555, in setup
multithreaded=self.multithreaded)
File "C:\Python27\lib\site-packages\spyderlib\plugins\console.py", line 54, in __init__
light_background=light_background)
File "C:\Python27\lib\site-packages\spyderlib\widgets\internalshell.py", line 101, in __init__
debug, profile)
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 698, in __init__
ShellBaseWidget.__init__(self, parent, history_filename, debug, profile)
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 61, in __init__
self.history = self.load_history()
File "C:\Python27\lib\site-packages\spyderlib\widgets\shell.py", line 500, in load_history
if rawhistory[1] != self.INITHISTORY[1]:
IndexError: list index out of range
I am terrible with this stuff, so I might be missing something completely obvious or doing something really stupid.
I am wondering if anyone else ran into a similar problem, or can just give suggestions on what to do, and how to do this "reset" thing, or maybe other advice.
Thank You in Advance
python doesn't search spyder in the PATH e.g.:
c:\some\dir> python some_file
Here python tries to read c:\some\dir\some_file file i.e., it looks in the current directory for some_file file.
c:\some\dir> python another_dir\some_file
Here python tries to read c:\some\dir\another_dir\some_file file i.e., it looks in the another_dir directory for some_file file.
c:\some\dir> python C:\path\to\some_file
Here python tries to read C:\path\to\some_file file i.e., it looks in the C:\path\to directory.
If documentation says run: python spyder --reset it assumes that you're in the directory where spyder script lives. It works both from the source checkout scripts directory (if you'd like to run it without installation) and from whatever directory the installation puts scripts in.
Installation process should create spyder or spyder.bat files. If spyder.bat in your PATH then you could run it as:
c:\any\dir> spyder
So instead of python spyder --reset you could try:
c:\any\dir> spyder --reset
The traceback shows that the first executed function is spyderlib.spyder.main(),
source code for the spyder script confirms it, so you can run:
python -c "from spyderlib.spyder import main; main()" --reset
don't worry, it is very easy to reset the spyder. for windows 10 users, you all need to type 'spyder' in 'Cortana' then you can see in apps category something like 'reset spyder setting' just click on that and some black screen will open and your problem will be solved. now you can open your spyder.
I have this problem in windows and it resolved by updating the spyder
pip install -U spyder
I am working with conda virtual environments and if you run
python spyder --reset it it will output the same error message. However, unlike stated above, no need to uninstall anaconda or look for any files.
Just activate your virtual environment as you usually do and write (no need for 'python' in there):
conda activate [name of your virtual env]
spyder --reset
This works for me.
Most of the users' spyder settings are in the user folder .Spyder file name.By deleting it.You will be able to restart the IDE and a new .Spyder directory would be created
For starters in winpython, I too faced this problem of spyder/spyder-reset not starting . And finally this is how it started :
opened command line went to :
D:\manas\mak\crap\WinPython-64bit-3.4.4.2\scripts
typed in spyder.bat
And that opened spyder .
Perhaps the environment variable is stuck at .exe when clicking on the spyder icon and preventing it to load.
Best solution as per my experience: uninstall spyder first, delete all the spyder files under conda > lib > site-packages > ..
1. pip install ipython
2. pip install spyder
3. spyder --reset
I had a similar problem. I had both two installations of Python27---the Ananaconda distribution and the other. Python27 folders appeared before the Anaconda ones in my search path, although Spyder was executed through the Anaconda executable.
It turned out that making the Anaconda distribution folders first in the PYTHONPATH solved the problem.
An easier solution--avoid multiple installations of Python27 if possible.
I tried the method about "python -c "from spyderlib.spyder import main; main()" --reset",but it seems that I don't have the spyderlib.spyder.Then,I solve this problem through install another version of spyder(you can find from anaconda if you use it),you can run:
conda install -c anaconda spyder-app=2.3.8
and it works.
Searched for spyder.bat, per prev answer, and after changing to that directoy - ran the python spyder --reset command.
C:\WinPython-32bit-2.7.3.3\python-2.7.3>cd scripts
C:\WinPython-32bit-2.7.3.3\python-2.7.3\Scripts>python spyder --reset

ezyang / git-ftp on Windows

I have been trying to install git-ftp from https://github.com/ezyang/git-ftp on my windows. I know most of git-ftp need cygwin or just cant be install on windows but, since its coded in Python and you can install a Python interpreter on windows, i tough i could install it.
I installed Python 3.2, added it to my path. Then i pulled the lastest version of git-ftp and followed the install instructions which are pretty clear :
Requirements: [git-python 3.x] ( http://gitorious.org/git-python )
it can be installed with `easy_install gitpython`
Usage: `python git-ftp.py`
Then i run 'python git-ftp.py' and i get the following error :
python git-ftp.py install
File "git-ftp.py", line 322
print complaint
^
SynthaxError: invalid synthax
My question is : why dosent it work? is it a python error, git-ftp script error, windows compatibility issues?
Note : I didint installed 'easy_install gitpython', do i absolutly need it?
Edit :
I also tried to install python-2.7.2.amd64-pdb and runned the same command and i get an other error :
python git-ftp.py install
Traceback (most recent call last):
File "git-ftp.py", line 48, in <module>
from git import Tree, Blob, Repo, Git, Submodule
ImportError : No module named git
I Belive it is beacause the script cant find my git or something like that, I then tried to put the correct 'ftpdata' file in a .git folder and runned the script from the root folder of the .git and even tried to run it from the .git folder itself. That didint work either.
I dont know if it matters but i have a Windows 7 - 64 bit (Intel Core2 Duo CPU T9600)
My question is : how to tell the python script where's the git module?
git-ftp is written Python 2, and is not, as it stands, compatible with Python 3. Install an earlier version of the interpreter.
Edit. You need to install the git-python library. Since the easiest way to install libraries is easy_install, you should set it up with the instructions here: http://pypi.python.org/pypi/setuptools and then run easy_install git-python.

Categories

Resources