Visual Studio 2019 Python Publish to File System Fails - python

I have been unable to "Publish" a Python application to a local filepath with Visual Studio 2019. The intent is to host the application under IIS on a Windows 2016 Server. PC is running Windows 10 build 1909.
I have updated VS 2019 to version 16.9.2, with the Python product being version 16.9.21026.1.
The test application is an unmodified "Flask Web Project" template, which runs as expected in the Visual Studio environment.
I have attempted publishing to the default ".\app.publish" file path, i.e.
"C:\Apps_VS2019\FlaskDemoApp\FlaskDemoApp\app.publish", and to "C:\Apps_VS2019\Pub"
In both cases all users have been granted Full Control permissions.
The Publish command reports success publishing to e.g. "C:\Apps_VS2019\Pub" but no files are written to that path. I do see some files copied to "C:\Apps_VS2019\FlaskDemoApp\FlaskDemoApp\obj\Any CPU\Debug\Package\PackageTmp"
but nothing makes it to the final publish folder. The .\PackageTmp folder contains: Folder "FlaskDemoApp", and files "requirements.txt" and "runserver.py". The "FlaskDemoApp folder contains: "static", "templates", "init.py", and "views.py", with the static and template folders containing expected files / subfolders.
What I do not see in the .\PackageTmp folder are any of the required packages "click", "Flask", "itsdangerous", "Jinja2", "MarkupSafe", Werkzeug" etc. (Should they be there?)
FolderProfile1.pubxml in "C:\Apps_VS2019\FlaskDemoApp\FlaskDemoApp\PublishProfiles"
Content:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>C:\Apps_VS2019\Pub</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
</PropertyGroup>
</Project>
The VS project has always been in Debug / Any CPU configuration, so it is not at all clear why is set to "Release". However there is no Release folder or Debug folder.
Bottom line: Any ideas why the publish is "successful" but there are no files in the target path? And does the "PackageTmp" folder described above have everything it should? Where are the external packages supposed to be, such as "Flask" and "Jinja2"?

I have at least a partial answer to my own question. The build configuration in VS is "Debug" "Any CPU". In the publish profile the "Configuration" parameter was set to "Release". I had to manually change that setting to "Debug". Now, upon publishing I am getting a file set in the publish path. That file set contains folders "static" and "templates", and files "_ init _.py" and "views.py".
I am still uncertain about the external packages, e.g. "Flask" and "Jinja2", but I suspect that those need to be dealt with separately, in setting up the Python environment on the server. I will begin researching that. At least I now get files in my publish target path.

Related

Django, Webpack and Heroku: Error reading /app/webpack-stats.json

I'm trying to use Django with Webpack on Heroku via django-webpack-loader. After pushing the files from the repository to Heroku, I run webpack to generate the static files in /dist as well as webpack-stats.json:
npx webpack --config webpack.config.js
This works fine: both the /dist files and the webpack-stats.json file are correctly created (both are placed within /app/). However, when I try to load the page I get an error:
OSError at /
Error reading /app/webpack-stats.json. Are you sure webpack has generated the file and the path is correct?
The error doensn't say much other than the file /app/webpack-stats.json is missing; however, the file exists, its content is well-formatted and it's in the right location.

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.

How do I use Python file in Nagios?

I'm trying to get a response from Nagios by using the following Python code and instructions:
http://skipperkongen.dk/2011/12/06/hello-world-plugin-for-nagios-in-python/
From some reason I never get to have OK from Nagios and it's always comes back with the message: Return code 126 is out of bounds - plugin may be missing
I installed nagiosplugin 1.0.0, and still nothing seems to be working
In parallel I have some other services (not python files) that work e.g. http check, current users, and SSH
What am I doing wrong? I'm trying to solve that for few days already
Getting Nagios to utilize your new plug-in is quite easy. You should make changes to three files and restart Nagios — that’s all it takes.
The first file is /etc/nagios/command-plugins.cfg (leave comment please if you know path to this file or analog in ubuntu). Assumed that plugin file is placed in /usr/lib/nagios/plugins/ directory:
command[check_hello_world]=/usr/lib/nagios/plugins/check_helloworld.py -m 'some message'
Drop down one directory to /etc/nagios/objects/commands.cfg (for ubuntu user should create cfg file in that dir /etc/nagios-plugins/config/):
define command {
command_name check_hello_world
command_line $USER1$/check_hello_world.py -m 'some message'
}
Save the file and open up /etc/nagios/objects/localhost.cfg (in ubuntu path to service definition files located in /etc/nagios3/nagios.cfg and by default cfg_dir=/etc/nagios3/conf.d. So, to define new service in ubuntu user should create cfg file in that dir, for example hello.cfg). Locate this section:
#
# SERVICE DEFINITIONS
#
and add new entry:
define service {
use local-service ; Name of service template to use
host_name localhost
service_description Check using the hello world plugin (always returns OK)
check_command check_hello_world
}
All that remains is to restart Nagios and to verify that plug-in is working. Restart Nagios by issuing the following command:
/etc/init.d/nagios restart
http://www.linux-mag.com/id/7706/
ubuntuforums.org - Thread: My Notes for Installing Nagios on Ubuntu Server 12.04 LTS
I had to prepend the path to python2.7 even though the shebang in the file specified it.
In the command definition I had this:
command_line /usr/local/bin/python2.7 $USER1$/check_rabbit_queues.py --host $HOSTADDRESS$ --password $ARG1$
Even though the top of the actual python file had:
#!/usr/bin/env python2.7
Even though the script executed and returned just fine from the command line without specifying the interpreter.
Nothing else I tried seemed to work.

How do I ignore PyCharm configuration files in a git repository?

I don't want to commit my PyCharm config files (e.g. .idea/codeStyleSettings.xml) to my git repository, so I added the following to my .gitignore file:
.idea/
mydjangosite/.idea/
However, every time I try to make a commit within PyCharm (command k), it still wants to commit these files. How do I get PyCharm to recognize my .gitignore file and not commit these files?
If PyCharm offers you to commit the files, it means that you have already added them to Git. You need to remove them using 'git rm --cached' and commit the change. After that, they will be ignored by the integration according to your .gitignore settings.
You can configure ignored files.
Under the Version Control node, of the Settings dialog box, click Ignored Files. The Ignored Files dialog box opens.
More easily:
Tip
You can also add files to ignore list on-the-fly. A new file under the Unversioned Files change list, has Ignore command on its context menu.
Remove the .idea folder (keep a copy)
Commit the changes
Add the following to the gitignore
(JetBrains recommended exclusions for PyCharm that also covers JetBrains plugins etc):
### JetBrains ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff: .idea/workspace.xml .idea/tasks.xml .idea/dictionaries .idea/vcs.xml .idea/jsLibraryMappings.xml
# Sensitive or high-churn files: .idea/dataSources.ids .idea/dataSources.xml .idea/dataSources.local.xml .idea/sqlDataSources.xml .idea/dynamic.xml .idea/uiDesigner.xml
# Gradle: .idea/gradle.xml .idea/libraries
# Mongo Explorer plugin: .idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ /out/
# mpeltonen/sbt-idea plugin .idea_modules/
# JIRA plugin atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties
### JetBrains Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr
Now you can add your .idea folder back into your project directory and the changes won't be tracked any more.
You should not ignore all of the files under .idea directory. Some of them are local and tied to your personal preferences and some other are global settings of the PyCharm project that most likely should be stored in git.
Here is the link to an updated .gitignore snippet for PyCharm and other JetBrains IDEs.

Categories