Python fail install a github script (HLS Server loop) - python

My goal it's to install a HLS server to stream a live video.
So i found https://github.com/jbochi/hls-loop this script.
But my install fail.
I am on Linux Ubuntu 14.04
apt-get install python-dev --> It's OK
pip install flask --> It's OK
python hls-loop.py --> ERROR python: can't open file 'hls-loop.py': [Errno 2] No such file or directory
Also i found this packet https://github.com/dayvson/hls-endless but build fail too :(
If you found a another script to install HLS live stream server, , I'm more than interrested!
Thx

After you clone the repository to your local directory using:
git clone https://github.com/jbochi/hls-loop.git
Your directory structure will look something like:
| - <current_dir> /
| | -- hls-loop /
| | | -- hls-loop.py
| | | -- ...
You have to install Flask using pip as that's a dependency for the hls-loop project. I'd recommend taking a look at virtualenv to isolate the project dependencies for each of your applications.
From your current directory you could run the application using something like python hls-loop/hls-loop.py. This causes and error in read_file_durations() due to how they are reading their static file. Because of that you will have to run the application from the same directory as the script:
cd hls-loop
python hls-loop.py
If you wanted you could create a fix for this so it doesn't matter where you run the application from by doing something like this:
import os
def read_file_durations():
basedir = os.path.abspath(os.path.dirname(__name__))
file_durations = os.path.join(basedir, "static/bipbop_4x3/gear1/prog_index.m3u8")
with open(file_durations) as f:
...
Hopefully that clears some stuff up for you.

You will need to git clone https://github.com/jbochi/hls-loop, then cd hls-loop, then you can run python hls-loop.py.

Related

How to get the location of installed Python package into the shell

I want my users to be able to reference a file in my python package (specifically a docker-compose.yml file) directly from the shell.
I couldnt find a way to get only the location from pip show (and grep-ing out "location" from its output feels ugly), so my current (somewhat verbose) solution is:
docker compose -f $(python3 -c "import locust_plugins; print(locust_plugins.__path__[0])")/timescale/docker-compose.yml up
Is there a better way?
Edit: I solved it by installing a wrapper command I call locust-compose as part of the package. Not perfect, but it gets the job done:
#!/bin/bash
module_location=$(python3 -c "import locust_plugins; print(locust_plugins.__path__[0])")
set -x
docker compose -f $module_location/timescale/docker-compose.yml "$#"
Most of the support you need for this is in the core setuptools suite.
First of all, you need to make sure the data file is included in your package. In a setup.cfg file you can write:
[options.package_data]
timescale = docker-compose.yml
Now if you pip install . or pip wheel, that will include the Compose file as part of the Python package.
Next, you can retrieve this in Python code using the ResourceManager API:
#!/usr/bin/env python3
# timescale/compose_path.py
import pkg_resources
if __name__ == '__main__':
print(pkg_resources.resource_filename('timescale', 'docker-compose.yml'))
And finally, you can take that script and make it a setuptools entry point script (as distinct from the similarly-named Docker concept), so that you can just run it as a single command.
[options.entry_points]
console_scripts=
timescale_compose_path = timescale:compose_path
Again, if you pip install . into a virtual environment, you should be able to run timescale_compose_path and get the path name out.
Having done all of those steps, you can finally run a simpler
docker-compose -f $(timescale_compose_path) up

Can't use .so on Mac (has bad ELF magic)

I'm using buildozer to convert a python program to a phone app on Mac connected to an Android phone with the command line:
buildozer android debug deploy run
The previous command line runs the converted app on the connected phone.But the app crashes as soon as playsound is used. As for the methods before playsound work just fine.
When I run:
adb logcat | grep python
I get the error:
ImportError: dlopen failed: "/data/data/org.test.myapp/files/app/_python_bundle/site-packages/gi/_gi.so" has bad ELF magic
When I looked it up I found that Mac cannot use .so files.
Does anybody know how I can solve this?
Okay, so I ended up fixing this when I got a similar error. (dawg.so has bad ELF magic)
Basically, the reason I got this error was because the library ("gi" in your case) was not been read properly by the android phone when deployed and hence, was "corrupted".
The bottomline reason (for me) was that it was a C/C++ library under the hood and used Cython to be converted to a Python library. Hence, this error usually means that your library needs a custom recipe.
Steps to solve it:
In the root directory (where .buildozer folder is found), I added a folder named dawg (the library name), and then, inside dawg, I git cloned the source files of dawg. To get the source files, you can just go to the PyPi page for that library and go to the Project links -> Homepage of their GitHub site. Once cloned, you can also remove .git, .gitignore, from the source files.
Once that's done, run python3 setup.py install in the dawg directory to install and hence, "cythonize" the source files
In .buildozer/android/platform/python-for android/pythonforandroid/recipes, add a new folder named "dawg" (your library name) and then, inside /dawg, make _init_.py where you will add your custom recipe.
In _init_.py, you can add your recipe and the path to the source files. Here is a template that worked for me, but you can customize it for you as per your requirements.
from pythonforandroid.recipe import IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe
import os
import sys
class DAWGRecipe(IncludedFilesBehaviour, CppCompiledComponentsPythonRecipe):
version = '0.8.0'
src_filename = "../../../../../../../dawg"
name = 'dawg'
# Libraries it depends on
depends = ['setuptools']
call_hostpython_via_targetpython = False
install_in_hostpython = True
def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
env['LDFLAGS'] += ' -lc++_shared'
return env
recipe = DAWGRecipe()
Don't forget to alter the buildozer.spec. To its p4a.local_recipes, add the local path to /.buildozer/android/platform/python-for-android/pythonforandroid/recipes as that's where we add our recipes.
Clean the previous build by running buildozer android clean
Lastly, run buildozer -v android debug deploy run to build the app on android phone again.
Hope this helps :)

Can't install gcloud on Amazon Linux : invalid syntax

I'm trying to install gcloud on my EC2 server running Amazon Linux 4.14.47-56.37 64bits, in interactive mode running the following command :
curl https://sdk.cloud.google.com | bash
The files download correctly, but the install then fails with the following Traceback :
File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
import bootstrapping
File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 32, in <module>
import setup # pylint:disable=g-import-not-at-top
File "/home/ec2-user/google-cloud-sdk/bin/bootstrapping/setup.py", line 55, in <module>
from googlecloudsdk.core import properties
File "/home/ec2-user/google-cloud-sdk/lib/googlecloudsdk/core/properties.py", line 291
self.__sections = {section.name: section for section in sections}
^
SyntaxError: invalid syntax
Any idea why this for is causing issues?
I am running python 2.7 (2.7.14) as recommended by Google.
On top of python 2.7 installed on the "python" command, I also had python 2.6 installed on the "python2" command.
Uninstalling python 2.6 solved the issue, Google Cloud install went through without issue on the next try.
You locally update the install.sh file to use python2.7 instead of python2. This worked for me
In case someone meets this problem again, and if you do not want to uninstall python 2.6 or to modify install.sh, here is a procedure that worked for me on an ec2 instance :
open a new terminal and type :
curl https://sdk.cloud.google.com | bash
The install should not work as CLOUDSDK_PYTHON=python2 by default, which leads to Python 2.6. To correct this, enter this command :
export CLOUDSDK_PYTHON=python
this links CLOUDSDK_PYTHON to Python 3.6
then
bash google-cloud-sdk/install.sh
and finally
./google-cloud-sdk/bin/gcloud init
Once this is done, you can use any gcloud or gsutil command by doing this :
./google-cloud-sdk/bin/gcloud <your gcloud command>
./google-cloud-sdk/bin/gsutil <your gsutil command>
For example, in order to copy a folder from a gs bucket to your ec2 instance :
./google-cloud-sdk/bin/gsutil -m cp -r gs://<bucket_name>/path/to/folder /path/on/your/ec2/instance
the -m option allows fast transfer (I could transfer with an average speed of 81 MiB/s with this option)
Hope this helps !
Setup yum repo:
# Update YUM with Cloud SDK repo information:
sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
# The indentation for the 2nd line of gpgkey is important.
Install yum downloader and download the rpm, then install with "--nodeps":
yum install yum-utils
yumdownloader google-cloud-sdk-231.0.0-1.el7.noarch
mv 23873bd6e8459ba6e70e96eb8f03f6ac03cd707ce3c80baa8264c714e030c915-google-cloud-sdk-231.0.0-1.el7.noarch.rpm /usr/local/src/google-cloud-sdk-231.0.0-1.el7.noarch
rpm -ivh --nodeps /usr/local/src/google-cloud-sdk-231.0.0-1.el7.noarch
This solved issue:
export CLOUDSDK_PYTHON=python

How do I install python app?

I want to install the app I found on a github page (https://github.com/googlei18n/fontview), how do I do it? I tried opening the 'build.py' file through mac terminal but it doesn't work, as well as pyton luncher- it freezes.
Kajas-MacBook-Pro:~ Kaja1$ cd fontview-master
Kajas-MacBook-Pro:fontview-master Kaja1$ cd src
Kajas-MacBook-Pro:src Kaja1$ cd fontview
Kajas-MacBook-Pro:fontview
Kaja1$ python2.7 build.py && ./build/FontView.app/Contents/MacOS/fontview
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'build.py': [Errno 2] No such file or directory
You are in the wrong directory. Change back to the folder fontview-master and run the command from there.

Fail to build atom/electron on Windows 7

Try to build atom/electron on Windows 7, but failed.
OS Environment:
Windows 7
VS 2013 Update 5
Python 2.7
Node.js 4.2.3
Git 2.6.4
atom/electron - Latest pull (2015.12.17)
It failed when running the bootstrap script "$ python bootstrap.py -v", the screenshot is here:
Trying to find a way through, any help will be appreciated.
-- dean
Found a way...:
Situation failed one: "can't open file"
According to the official documentation: Build Instructions (Windows)
$ python script\bootstrap.py -v
the result will be:
D:\Program Files\Python27\python.exe: can't open file 'scriptbootstrap.py': [Errno 2] No such file or directory
Situation failed two: "WindowsError: [Error 3]...."
Pay attention to this:
$ cd script
$ python bootstrap.py -v
I cd into the script folder, and run the bootstrap script, and failed.
Situation OK: Use "/" instead of "\"
See the screenshot below:
Explanations are welcome...
--dean

Categories