So, Im trying to do a conversor, and I had a successful work at it, but, when I was trying to execute the python script by the localhost, it simply didn't work.(btw, Im using XAMPP as the local server)
Here is a code that functions until before the "import pytube":
print("Content-type: text/html\n")
import sys
import os
print("<html><head><title>HelloCGI</title></head")
print("<body><h1><i>Hello</h1></body></html>")
import pytube
url = "https://www.youtube.com/watch?v=eH4F1Tdb040"
yt = pytube.YouTube(url)
yt.streams.last().download(r'C:\xampp\htdocs\converter_My\songs')
os.chdir(r'C:\xampp\htdocs\converter_My\songs')
os.system('ren *.webm *.mp3')
Ok, for some stupid reason, I put the import pytube after the print's, and then, it went...
#!C:\xampp\htdocs\converter_My\Python\Python37-32\python.exe
print("Content-type: text/html\n")
import sys
import os
print("<html><head><title>HelloCGI</title></head")
print("<body><h1><i>Hello</h1></body></html>")
import pytube
url = "https://www.youtube.com/watch?v=44Mz-kwonWk"
yt = pytube.YouTube(url)
yt.streams.last().download(r'C:\xampp\htdocs\converter_My\songs')
os.chdir(r'C:\xampp\htdocs\converter_My\songs')
os.system('ren *.webm *.mp3')
Maybe I made you waste a little bit of your time, but thank you...:)
I always need to do it:
from pytube import*
import pytube
I hope it works :)
PS: You don't add error message so it is litle hard to repair
EDIT: Make sure then using pip you have console with ADMIN privilages
I also got the same problem but make sure while you are installing them use
1.pip for python2
2.pip3 for python3
so with python3 use
pip3 install PyTube
make sure to take care of t
Related
I have pip installed edi-835-parser and then trying to import like below
from edi_835_parser import parse
but getting module not found error.
as per edi-835-parser documentation package name is edi-835-parser but while importing it is edi_835_parser
Also tried using below code.
import importlib
module_name = importlib.import_module('edi-835-parser')
This also did not help much.
Could someone help on this
I am trying to use the google API client to download something every day for something but I have deduced that for some reason it won't let me import googleapiclient when I run it in crontab.
For example, if I run this in crontab
crontab: * * * * * python3 test.py >> cron.log
test.py:
print("Hello")
cron.log outputs:
Hello
But if I then once I import it so the file look like this
from googleapiclient import discovery
print("Hello")
then the cron.log looks like this:
Its just empty. I can not figure out why this is true. The google API client I believe is installed correctly because when I run it manually then it works perfectly with no issues.
The operating system I am using is macos.
The way I fixed it is first by changing the crontab to python3 test.py > cron.log 2>&1. This showed that the errors where. Then I realized that it was not able to import googleapiclient into python. I still did not understand why it does not, but a workaround I found was to first install the libraries into a folder and then accessing the libraries from there.
To install the libraries into a folder the command I used in terminal is below:
pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib -t ./lib
Then inside the python I added whats below to the beginning of the file so it would know where to import the libraries from.
import os
import sys
file_path = os.path.dirname(__file__)
module_path = os.path.join(file_path, "lib")
sys.path.append(module_path)
This does work.
I'm trying to run CairoSVG but I don't have permission on the server to run it. No problem I think, I've used other libraries in Python before without installing them by pointing sys.path.append to their directory path:
import sys
sys.path.append("/full/path/to/SomeOtherLibrary")
import SomeOtherLibrary
I thought I could create something like loader.py, import the path inside there to CairoSVG with a sys.path.append, then instead of calling: cairosvg image.svg -o image.png I could call /full/path/to/loader.py image.svg -o image.png.
Then I started to create loader.py and thought I have no idea what to do or if this is even possible. I figured I start with:
import sys
sys.path.append("/full/path/to/CairoSVG")
And then I don't know what. If I was able to install the script I'd need to pass parameters to it. How can I create a loader to run this library?
Simply call cairosvg.main() from your script. Pretty much like it is done here: https://github.com/Kozea/CairoSVG/blob/master/cairosvg.py
I have created I python program which makes 100 screenshots, and saves them on a folder called img inside the OS folder Documents. It worked perfectly fine in my Linux Ubuntu, it did the 100 screenshots and saved them in the directory I wanted. Now, I created a new Linux user in the same Virtual Machine, and I ran the same python script.
It gives me this error: ImportError: No module named pyscreenshot
I have tried many times. It works in my other user, although in the new one it keeps giving me error. Is there any reason for this?
Thanks. The code is below:
import os
import pyscreenshot as ImageGrab
def photos(num):
for n in range(num):
s = str(n)
a = "../Documents/img/s" + s + ".png"
# grab fullscreen
im = ImageGrab.grab()
# save image file
im.save(a)
return True
Quick note: I am calling the function photos() from another file using import screenshot (the file is called 'screenshot.py')
try to install pyscreenshot for your user
pip install pyscreenshot
Just in case the answers provided above don't work, try using
sudo -H pip install pyscreenshot
First the setup: Windows 8.1 64bit, Python 3.4 32bit.
I wanted to run the code here. So I installed comtypes
pip install comtypes
I then tried to run the code, i got
ImportError: cannot import name 'SpeechLib'
Then tried this code here to try and generate the needed SpeechLib module.
I am however still getting the same error, what should I try next?
Running these lines made it work:
from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
stream = CreateObject("SAPI.SpFileStream")
Output was:
# Generating comtypes.gen._C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4
# Generating comtypes.gen.SpeechLib
After this I got no import error anymore, as expected.