pythonAnywhere AttributeError : module 'pytube' has no attribute 'YouTube' - pip

I am making a project with Django and pytube in python 3.6, but when I run the code below in my python anywhere project, I get this error:
AttributeError : module 'pytube' has no attribute 'YouTube'.
import pytube
url = input()
yt = pytube.YouTube(url)
This probably is because there are multiple packages named pytube, and I think that I installed the wrong one. Which one do I have to install? And should I than use pip or pip3?
I already tried uninstalling pytube and reinstalling (also via the GitHub link which you can find from other people who are having issues with this: git+https://github.com/nficano/pytube.git)

Related

cx_Freeze throws an error when building if packages are involved

cx_Freeze successfully converts a .py file to an .exe if no other packages are involved.
But when pandas is included, the setup fails with this message:
File "C:\Anaconda\lib\site-packages\cx_Freeze\hooks.py", line 1324, in load_zmq
libzmq = __import__("zmq", fromlist=["libzmq"]).libzmq
AttributeError: module 'zmq' has no attribute 'libzmq'
This is the contents of the setup.py:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"packages": ["pandas"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup( name = "test",
version = "0.1",
options = {"build_exe": build_exe_options},
executables = [Executable("test.py", base=base)])
So far I've tried creating a different environment in anaconda to run cx_freeze to see if the problem resolves itself that way.
Appreciate any help.
I've spent a long time trying to find an answer to this question, but luckily it can be found here. It seems it was a bug inherent to cx_freeze.
Although the link provided to download the wheels no longer works, the patch has been added to the latest development version (6.6.0 if I recall correctly). You can install it directly from github, as such:
python -m pip install git+https://github.com/marcelotduarte/cx_Freeze.git
Doing this fixed the error for me (and enabled me to discover other errors that I had to deal with!).

Azure functions (cloud): Install cython dependent module

I'm trying to install/import a cython dependent module [ZigZag] into my python function on Azure functions (Linux platfrom), I'm working via Windows 8.1 (VSCode), Running Python 3.6 on both local machine and azure functions.
I tried including Cython in the requirements.txt file, this errors out during deployment (seems installation of external modules happens somewhat in parallel)
I tried creating a '.toml' file, no luck.
I also tried the idea found here Python google cloud function deployment failure - Madmom pip package still didn't work.
Finally I decided to deploy the function first (with cython included in the 'requirements.txt' file) without the zigzag module, and then in my python script use subprocess.Popen() to do a pip install zigzag and import it before the rest of the function runs.
This is where I get stuck. In my python file I have these lines included to do the above:
#function to be called in azure __init__.py file
def f....:
# check for zigzag
try:
import zigzag
except ImportError:
subprocess.Popen(["pip", "install", "ZigZag"], shell=True)
finally:
import zigzag
.
.
.
rest of the function...
This deploys successfully to azure functions, however it fails during execution with the error:
Microsoft.Azure.WebJobs.Script.Workers.Rpc.RpcException :
Result: Failure Exception: ModuleNotFoundError: No module named 'zigzag
Any idea's how to do this correctly?
NB: This issue occurs on google cloud functions as well.
I see this is related to https://learn.microsoft.com/en-us/answers/questions/152557/index.html
As per the thread, the latest version for ZigZag is 0.2.2 and the supported python version is 3.5: https://pypi.org/project/ZigZag/
The azure function supports 3.6 and above python version which will make it incompatible. You can try installing the latest cython using requirements.txt and it will work as expected. But when you try to install ZigZaG it tries to find the dependency of cython package (Cython==0.26.1) that is compatible with it therefor it throws the error that cython package not found.

Python3.7: No module named

I've been trying to install matplotlib and textblob on my system using
pip3 install matplotlib
or
pip3 install textblob
It says it's installed successfully. However, when I try to import in in Sublime Text it says
ModuleNotFoundError: No module named 'matplotlib'
or
ModuleNotFoundError: No module named 'textblob'
I've set up the build system in sublime text for python 3. A lot of modules that I've installed and are using the same way works fine (BeautifulSoup, requests and tweepy for example). I do not understand why some modules work and others do not. I've been trying to find the solution to this problem but after hours of research without results, I see this question as my last resort. Very thankful for all help.
shell_cmd: /usr/bin/env python3

ImportError: No module named googlemaps

I've installed this package via pip27 on macports. My OS is OSX El Capitan 10.11.6. My python install is 2.7.10.
I'm trying to run an example script that imports googlemaps module, but I keep getting that ImportError. I have a feeling that it's how pip installed it and the reason why python can't find it, but I'm relatively new to pip so I don't know where to start investigating.
I also tried googling for a fix but no dice. Any idea what's happening here?
Here's my code:
import googlemaps # can't import
import argparse
from datetime import datetime
# collect args for lat, long, # of addresses, radius of search
parser = argparse.ArgumentParser(description='Randomize addresses on Google Maps')
parser.add_argument('-lt', '--latitude')
parser.add_argument('-lng', '--longitude')
parser.add_argument('-n', '--count')
parser.add_argument('-r', '--radius')
args = parser.parse_args()
print('Results: ', vars(args))
Error message:
Traceback (most recent call last):
File "randomize_addresses.py", line 1, in <module>
import googlemaps
ImportError: No module named googlemaps
Found a fix. I uninstalled googlemaps via pip and then reinstalled using easy_install. Apparently OSX doesn't like pip.
Looks like you used pre-installed python since you mentioned version 2.7.10 (default version shipped with macOS) which is located at /usr/bin/.
MacPorts installs binaries and libraries under /opt/local. Try to install python via MacPorts and run the program again. Python and pip should both be linked so that packages installed via pip is available to python.
In this case packages installed using pip27 would be available to python27 installed via MacPorts and not /usr/bin/python.
Another way would be to download get-pip.py and install it against /usr/bin/python (pip installation guide).
Note: Make sure you are using python installed via MacPorts. To check this run which python, it should show something like /opt/local/bin/python2.7

kmpfit module not in Kapteyn v2.2 module list

I am using Python 2.7 through Anaconda 2.7.8 and need Kapteyn 2.2 to perform Non-linear Least Squares fitting easily (it is probably an alternative to Scipy.optimize.leastsq() for dummies like me!).
After copy-pasting this from a previous post here on Stack Overflow:
conda install -c https://conda.binstar.org/dhirschfeld pyodbc
and then running on my cmd (as I did not have pyodbc installed I think, because of which maybe the command prompt on my Windows 7 64-bit system was not responding well to python setup.py install inside the Anaconda directory where I unzipped the Kapteyn .zip file downloaded from University of Groningen website.
But, after the installing pyodbc properly and running python setup.py install, the cmd gave me an error saying error: command 'C:\Users\windows 7\Anaconda\Scripts\gcc.bat' failed with exit status 1. Later, when I tried to import kmpfit module (needed for Non-linear least square fitting with Kapteyn), here is the problem:
import kapteyn
help(kapteyn)
Help on package kapteyn:
NAME
kapteyn - Kapteyn package.
FILE
c:\users\windows 7\anaconda\kapteyn\__init__.py
PACKAGE CONTENTS
_ni_support
celestial
doccer
filters
interpolation
maputils
mplutil
positions
rulers
shapes
tabarray
wcsgrat
DATA
__all__ = ['celestial', 'wcs', 'wcsgrat', 'tabarray', 'maputils', 'mpl...
__version__ = '2.2'
VERSION
2.2
As you can see, there is no module named kmpfit (or even wcs) here. But according to http://www.astro.rug.nl/software/kapteyn/intro.html, these two should be there.
Kindly help. I have never imported any module before.
Thanks in advance...:-)
I just managed to get this working (on Mac OSX, so you may have to adjust this). My steps were:
$ conda install pyodbc (didn't need to go through binstar)
Download & unarchive the kapteyn package, then navigate to its directory
$ python setup.py install, which used my OS's C compiler and Anaconda's python, and installed kapteyn to my anaconda distro's site-packages, as it should.
Check that kmpfit.so is in the kapteyn folder in site-packages, showing that kmpfit installed correctly.
>> from kapteyn import kmpfit failed, ImportError: cannot import name kmpfit. I did some digging and discovered that it was still importing kapteyn from the folder that I downloaded, not from site-packages.
Delete the downloaded kapteyn folder, then try again. It worked!

Resources