"Module not found error" when trying to run pytube on PyCharm - python

I am trying to use pytube to download videos but it isn't working. I don't know much about python (or any other programming language) so it is likely that my problem is easy to solve. I have tried reading multiple websites and watching several YouTube videos, but I haven't been able to make it work yet.
I use a MacOS High Sierra 10.13.6;
I have both Python 2.7.16 and Python 3.8.3 versions installed;
I used the terminal to install pytube using "pip install pytube3";
When I try to install again using the same command as above, I think that it is correctly installed, because the terminal shows the following messages:
Requirement already satisfied: pytube3 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (9.6.4)
Requirement already satisfied: typing-extensions in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pytube3) (3.7.4.3)
I am trying to use PyCharm 2020.2.1 (Community Edition)
I think that pytube is also OK in PyCharm, because it appears in "External libraries" under "site-packages"
My problem:
When I open PyCharm, it opens on "main.py". There, I try to write:
import pytube.
But I get the following message:
/Users/applemacosx/PycharmProjects/pythonProject5/venv/bin/python /Users/applemacosx/PycharmProjects/pythonProject5/main.py
Traceback (most recent call last):
File "/Users/applemacosx/PycharmProjects/pythonProject5/main.py", line 1, in <module>
import pytube
ModuleNotFoundError: No module named 'pytube'
Process finished with exit code 1
I have tried searching about this error, but I wasn't able to find anything that I could make work. I would be very grateful if someone could help me understand what I am doing wrong.

What's happening is that you've indeed installed pytube on the python installation on your machine, but Pycharm creates a virtual environment for each new project you create.
So while pytube is installed in the python environment on your machine, it's not installed in this newly created python environment. The solution is to install pytube in the project's virtual environment. There a couple of ways to do that. Probably the easiest would be to go to the terminal window in Pycharm, and execute the pip install command.

It's happening due to virtual environment, which PyCharm creates separately for each and every project. There are many ways to add a library to current project but the easiest way could be to add directly from PyCharm.
Steps:
Go to Top left, click on PyCharm
Then click on Preferences
Now, In the preferences search for Project Interpreter
After this click on + sign to add pytube
Once you click on +, you would see another pop up window, you need to put putube there and select the exact match or the one you are looking for(You can mention the version too).
At last click on Install package. pytube will be install in few seconds and you can start importing in your module.
The below screenshots could help you more:

Related

Installed selenium with pip, folder is in site-packages, using correct interpreter, but still cannot import (Win10, Python 3.10.9)

I'm trying to use selenium, but can't get python to recognize it.
I installed it first using "pip install selenium" and "pip install webdriver-manager". It is in the folder "C:\Users\{username}\AppData\Local\Programs\Python\Python310\Lib\site-packages\selenium", but I get the error "ModuleNotFoundError: No module named 'selenium'" when I try to import it.(https://i.stack.imgur.com/dVplU.png)
(https://i.stack.imgur.com/wiREJ.png)
Here it is shown as installed with the command "pip list"
(https://i.stack.imgur.com/QhOu7.png)
I also tried uninstalling it and reinstalling with flags that I saw some people say worked, but it didn't make a difference.
(https://i.stack.imgur.com/VTTMU.png)
I only have one python interpreter version installed, 3.10 (so only one python folder, "Python310"). I have pandas in the same site-packages folder which I can import and use no problem.
If anyone knows what the issue might be, please let me know. I can't figure it out for the life of me.
Okay, I solved the issue by completely uninstalling the interpreter which I got from the Microsoft Store and reinstalling it from the official Python website. Now "from selenium import webdriver" works.
Somehow selenium installed in the global scope is not getting recognized within the Virtual Environment of VS Code / PyCharm.
Solution
You need to install Selenium within the Virtual Environment.
Within the Terminal execute the command:
pip install -U selenium

Packages installed via Pip do not get imported in Python VSCode [Windows 10]

Trying to install new packages via pip on Windows, but after it installs - Python cannot resolve the import. For Example, I have just installed the Python package similaritymeasures and pip correctly installed it, but when I import it into my Python program, it cannot find the import. Has anyone know a way around this?
Make sure that you restart VSCode after downloading your package. Sometimes, when you download a package while VSCode is still running, it doesn't recognize the package when using import similaritymeasures.
If that didn't work, then make sure that VSCode is using your preferred version of python. It is possible that you have more than one python version and it's using a non-compatible one to run your code. This can be done at the bottom right corner of the window by clicking the box that says: (for example) 3.9.5 64-bit. Then select a different (preferably older) version from the pop up widnow.
These are the solutions that came to my mind, I hope this helped.

pycharm cannot see the module "openpyxl" even though i installed

I am trying to write a python-script to work with dataframes imported from excel table and another one from another source. In order to read excel file into a pandas dataframe i selected "openpyxl" as a preferred engine, however PyCharm claims there is no such module - even though I have earlier installed it.
I am working on conda and i tried to install it both using pycharm terminal and my macbook terminal: when i retype "conda install openpyxl" it returns me
"# All requested packages already installed."
So please help me because it confuses me that PyCharm keeps screaming
"ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl."
while terminal says i already have that module installed
This may happen because your pycharm is using a different interpreter than your command line.
To solve it:
In Pycharm, go to File, settings, project Interpreter, in the right top corner click the + button. Search for openpyxl and click Install package to install the latest version of the package.

Installing and using npTDMS with Spyder - anaconda3

I have successfully installed npTDMS as seen here:
https://pypi.org/project/npTDMS/
If I try to install with command line using either pip or conda I get a message confirming it is already installed, and I see the package at D:\Users\username\anaconda3\pkgs.
On Spyder I have tried using the PYTHON path manager (in the tools menu) to add both:
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0
D:\Users\username\anaconda3\pkgs\nptdms-1.2.0-pyhd8ed1ab_0\site-packages\nptdms
As far as I understand this should be enough to use the npTDMS package, however when I try to import I get a ModuleNotFoundError: No module named 'nptdms'.
I'm fairly new to python overall so maybe there is a simple thing I am missing.
This issue comes when there are multiple versions of python or any package you are running at current time. The same issue was with me too when the IDLE was not able to detect the position of where the package is installed.
My suggestion is that uninstall all the versions of python and the module you are using and install them again. Otherwise shift to any other IDLE, in my recommendation - Visual Studio Code.

Python 3.4 - Installing Kivy Error

I'm trying to install Kivy on Python 3.4 using the instructions here: https://kivy.org/docs/installation/installation-windows.html
I'm on the installing dependencies step, where it gives me this error: http://prntscr.com/a5rk5k
Initially I tried just going ahead to the last step (python -m pip install kivy) and it looked like it worked fine, but then I tried import kivy in a Visual Studio project and it said "Unable to resolve "kivy""
Any ideas anyone? Keep in mind, I had Python 3.5 installed (which kivy does not work with) before now and set to default, but I changed the path in the command prompt.
Something is not right with your kivy installation, use python -m pip list to check what packages are missing and (re)install them, one-by-one would be the best for debugging. And also you've pasted it wrong, so the kivy.deps.gstreamer was read as a separate comand and not a package for pip
For simple installing of kivy just follow the install docs or if you don't mind having another folder or reinstalling python for new kivy&python try KivyInstaller which hopefully makes the whole process beginnerproof. You enter what you need in the beginning and then wait.

Categories

Resources