How to run a executable with command line in Python? - python

I´ve installed this package: https://github.com/retostauffer/PyGFSV2, with pip. This package comes with two executables (GFSV2_get and GFSV2_bulk). But, i don´t know how to open executables in Python.
So, after instlation, the package author recomend try the installation by calling:
GFSV2_get --step 12 24 --level 700 850 --param tmp_pres --date 2005-01-01
So, i put in Anaconda Prompt the next:
(base) C:\Users\vrida>CD C:\Users\vrida\anaconda3\Scripts
(base) C:\Users\vrida\anaconda3\Scripts>python GFSV2_get --step 12 24 --level 700 850 --param tmp_pres --date 2005-01-01
But, it didn´t work. Appear this:
# DEBUG Loading default config file from package source.
# INFO Config file read, return.
# INFO Processing date 2005-01-01 00Z
# INFO Downloading inventory information data
# DEBUG Reading ftp://ftp.cdc.noaa.gov/Projects/Reforecast2/2005/200501/2005010100/mean/latlon\tmp_pres_2005010100_mean.grib2.inv
# ERROR Problems reading file, reason: "ftp error: URLError("ftp error: error_perm('550 Failed to change directory.')")".
# ERROR Could not download inventory file! Skip this.
# INFO Inventory empty, skip this file
# INFO Downloading inventory information data
# DEBUG Reading ftp://ftp.cdc.noaa.gov/Projects/Reforecast2/2005/200501/2005010100/sprd/latlon\tmp_pres_2005010100_sprd.grib2.inv
# ERROR Problems reading file, reason: "ftp error: URLError("ftp error: error_perm('550 Failed to change directory.')")".
# ERROR Could not download inventory file! Skip this.
# INFO Inventory empty, skip this file
I´m beginner in Python. So i have two questions:
1 - How to run these executables, for example with Anaconda Prompt?
2 - Could anyone make the download of the package, after try the instalation and, if sucessfull, tell me how can i make the same?

I think you should contact the maintainer of the package. apparently the library tries to download some file via ftp, using the system file separator, \ in your case (since you are using windows), instead of /:
ftp://ftp.cdc.noaa.gov/Projects/Reforecast2/2005/200501/2005010100/mean/latlon\tmp_pres_2005010100_mean.grib2.inv
the file is accessible via anonymous ftp access using a standard ftp client. so it should be an issue with the python library.

Related

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 :)

Python package, "Updating the INI File"

I am working with a python package that I installed called bacpypes for communicating with building automation equipment, right in the very beginning going thru the pip install & git clone of the repository; the readthedocs calls out to:
Updating the INI File
Now that you know what these values are going to be, you can configure the BACnet portion of your workstation. Change into the samples directory that you checked out earlier, make a copy of the sample configuration file, and edit it for your site:
$ cd bacpypes/samples
$ cp BACpypes~.ini BACpypes.ini
The problem that I have (is not enough knowledge) is there isn't a sample configuration file that I can see in bacpypes/samples directory. Its only a .py files nothing with an .ini extension or name of BACpypes.ini
If I open up the samples directory in terminal and run cp BACpypes~.ini BACpypes.ini I get an error cp: cannot stat 'BACpypes~.ini': No such file or directory
Any tips help thank you...
There's a sample .ini in the documentation, a couple of paragraphs after the commands you copied. It looks like this
[BACpypes]
objectName: Betelgeuse
address: 192.168.1.2/24
objectIdentifier: 599
maxApduLengthAccepted: 1024
segmentationSupported: segmentedBoth
maxSegmentsAccepted: 1024
vendorIdentifier: 15
foreignPort: 0
foreignBBMD: 128.253.109.254
foreignTTL: 30
I'm not sure why you couldn't copy BACpypes~.ini. I know tilda could be expanded by your shell so you could try to escape it with
cp BACpypes\~.ini BACpypes.ini
Though I assume it isn't needed now that you have a default configuration file.

Flask app on Cloud Foundry - Command "python setup.py egg_info" failed with error code 1

I am trying to push a Python (3.6.5) app via Flask to Cloud Foundry (cf version 6.36.1+e3799ad7e.2018-04-04). The application takes a POST request (text file), does some text transformation, saves the new file, and returns a confirmation message. It works locally (tested via Postman). However, when attempting to push it to CF, it gives the following error -
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ygzuah5g/logging/
Could you please let me know how I can go about solving this issue? Thanks in advance. The entire files together are ~ 350 MB. I am using a manifest.yml
---
applications:
- name: textsum
memory: 512M
command: python server.py
buildpack: https://github.com/cloudfoundry/buildpack-python.git
PS - Not sure if this is helpful, I do have import queue in one of my files. If I change it to import Queue (Py 2x compatible) and use Py 2.7.15 runtime, the cf push is successful, but it throws runtime errors
ERROR in app: Exception on / [POST]
File "/home/vcap/deps/0/python/lib/python2.7/subprocess.py", line 1047, in _execute_child
ERR raise child_exception
ERR OSError: [Errno 2] No such file or directory
ERR 10.0.65.11 - - [12/Jun/2018 20:56:16] "POST / HTTP/1.1" 500 -
First. Don't do this in your manifest.yml:
buildpack: https://github.com/cloudfoundry/buildpack-python.git
This is telling Cloud Foundry to use the master branch of the buildpack which can change quite frequently and there are no guarantees of it's fitness (i.e. it could even be broken).
Instead, make sure that you are using a release. Releases are tested and the code won't change out from under you.
You can do this by using the platform supplied Python buildpack, simply remove this line or put python_buildpack as the name, or you can point to buildpack: https://github.com/cloudfoundry/buildpack-python.git#v1.6.17 where v1.6.17 is a release from here.
https://github.com/cloudfoundry/python-buildpack/releases
Second, it seems like you need to tell Cloud Foundry & the buildpack which version of Python you want. If you need Python 3, then you should tell it that. See here for instructions on doing that.
https://stackoverflow.com/a/50837696/1585136
Third, this error:
ERR OSError: [Errno 2] No such file or directory
Seems like you're trying to write to a location that does not exist. Where are you trying to write your file? The paths will be different on your local machine vs running on Cloud Foundry. Typically on Cloud Foundry, you would write temporary files to /home/vcap/tmp or /app/tmp (/app is a symlink to /home/vcap) or $HOME/tmp. They all point to the same place.
I'm specifically mentioning temporary files here because you don't want to write permanent files to the local file system on Cloud Foundry. The local file system is ephemeral and your data will not persist for very long. See here for details.
https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#filesystem
Hope that helps!

VATIC Annotation Tool installation - "turkic setup --database" - unknown action setup

I'm trying to install VATIC Video Annotation Tool on Linux. I followed the instructions in README file twice, always failing to execute command:
$ turkic setup --database
which gives these two error messages:
No handlers could be found for logger "turkic.geolocation"
Error: Unknown action setup
Other turkic commands, e.g. turkic status --verify give the same error messages (for a given action name).
I also noticed that source file ~/vatic/public/index.html contains links to stylesheets and scripts in turkic folder src="/turkic/file_name", which can't be reached. Their true location is in ~/turkic/turkic/public.
Any ideas what can be wrong?
You should go into vatic folder when executing any commands starting with turkic.
Only inside vatic folder "actions" will be recognized.
Make sure that you issue the symbolic link command:
$ turkic setup --public-symlink

pip fails to install PIL or Pillow with mt.exe error

On one of my Windows 7 development machines, I am attempting to install the Python Image Library.
My machines are similar. Both run Windows 7 Professional, x64. Both use Python 2.7.3 (32bit). On one of the machine pip install PIL works fine. On the other it fails with the trace ending with this:
build\temp.win-amd64-2.7\Release\_imaging.pyd.manifest : general error c1010070:
Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31
How can I resolve this error?
Thanks to http://bugs.python.org/issue4431, this error was fixed by modifying:
C:\<Python dir>\Lib\distutils\msvc9compiler.py
and adding:
ld_args.append('/MANIFEST')
after the MANIFESTFILE line so it looks like:
# Embedded manifests are recommended - see MSDN article titled
# "How to: Embed a Manifest Inside a C/C++ Application"
# (currently at http://msdn2.microsoft.com/en-us/library/ms235591(VS.80).aspx)
# Ask the linker to generate the manifest in the temp dir, so
# we can embed it later.
temp_manifest = os.path.join(
build_temp,
os.path.basename(output_filename) + ".manifest")
ld_args.append('/MANIFESTFILE:' + temp_manifest)
ld_args.append('/MANIFEST')
If you still get the error, then change the if arg.startswith("/MANIFESTFILE:") to if arg.startswith("/MANIFEST:") in the manifest_get_embed_info(self, target_desc, ld_args) method.
Download the compressed package from pypi, and try building and installing in your machine. This link could give you some hints. That exactly deals with your problem only but the installation varies.
If you've reached here looking for
general error c1010070:
Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31
Here's a workaround that worked in Windows 8/x64/Python 3.3/VS 11:
# py 3.3 seems to be compiled against VS 2010 compiler, force using VS11 cl.exe for us
$env:VS100COMNTOOLS=$env:VS110COMNTOOLS
# Modify C:\Python33\lib\distutils\msvc9compiler.py
# Comment line 670: ld_args.append('/MANIFESTFILE:' + temp_manifest)
# Basically it will instruct build to not look for manifest file

Categories