I have an Android app written in kotlin that needs to call python code. I would like the app to come bundled with the necessary python binaries to execute some python scripts as well as the required python libraries, ideally managed by pip in a virtual environment.
I already have some code that will copy these files from the assets folder that is bundled into the APK when building the app, but I don't know where to find recent python binaries that can run natively on Android. I'm assuming I need something like a arm64 version of python >3.7 .
A second issue I have is that I'm developing the app on Windows, so the virtual environment and some dependencies are not cross platform. I would probably need a way to either automatically convert the windows virtualenv into a valid project structure with correct dependencies, or a way to create and manage a linux virtual environment from Windows (maybe WSL can save me here).
What is the preferred method? Are there open source Android apps that have solved similar issues?
I've been searching around the Internet for a while but I have not been able to find detailed instructions on how to install Polynote (The polyglot notebook
with first-class Scala support.) for Windows with mixing multiple languages, Python and Scala.
Github Link for Polynote.
Official Website.
According to Official Website:
Polynote is currently only tested on Linux and MacOS, using the Chrome browser as a client. We hope to be testing other platforms and browsers soon. Feel free to try it on your platform, and be sure to let us know about any issues you encounter by filing a bug report
I would really appreciate it if anyone here can share his/her method if he/she
had successfully installed Polynote on Windows, either from Virtual Machines
(VMware/Virtualbox) or directly.
You could install Polynote on Windows with Ubuntu's subsystem for Windows. To do that, you have to:
Enable Windows Developer mode: Settings > Update & Security > For Developers > Developer Mode.
On Windows Features turn on Windows Subsystem for Linux.
Search for Bash on Ubuntu on Windows in your local search and you will find it.
Otherwise, you can skip the third step by installing Ubuntu 18.0.4 LTS from Window Store which is free and you can run linux commands there. You can actually install any Linux software and it works just as if it was native.
Having installed Ubuntu for Windows, you can just go through the steps on official documentation through the link which you provided us and you will be fine.
Might be a bit late but still maybe helpfull if you can't on WSL or if you easily want to keep polynote up-to-date.
I used docker to run polynote on Windows. Currently I'm reworking the Dockerfile I wrote to automatically update polynote on new releases. But as of now the script to run Polynote works for polynote version (0.3.11). https://github.com/moritzbaumotte/polynote-windows-inofficial
Here you only need docker-compose and docker installed. You can download the repository and execute the batch script. It will create a working docker image and run it, then you can access polynote on http://localhost:8192
The issue with the official docker images imo is the binding to 127.0.0.1 which needs to be 0.0.0.0, hence the config.yml in my repository.
I've been reading a lot these days, and I'm not sure about the specific use of it. I need ask it, because cannot find someone who explain it to me. Now I'm lost..
The main problem is I need install my app (python + glade) in "/usr/share/name_app" and a ".desktop" file in "/usr/share/applications" in Ubuntu.
The solution that I've find is creating a ".deb" file because the installation is perfect. In ubuntu I can launch it with Unity clicking on the launcher, the ".desktop".
(Probably I'll upload it to "Ubuntu Software Center").
For windows I could use "py2exe" or a similar, and another one for Mac.
But, like the code is in GitHub, it should have a "setup" or a "makefile" to install it.
After reading and reading (and reading), I think that "setup.py" is only for install a module and then import it with python.
However if I have to install and app, how can I distribute it making a "setup.py" or a "makefile"? Which is better for install an app? Which is the diference? What I have to use?
Thanks:)
setup.py is used to deploy Python applications and modules with virtualenv http://www.virtualenv.org/en/latest/index.html setup.py is mostly useful for the application developers - you can run
python setup.py develop
within virtualenv to set-up your development workspace with Python dependencies.
For each platform distribution (Windows, OSX, Linux) use the distribution tools as you are currently using.
You can also use setuptools tools to roll out packages from setup.py for the platform architecture. Eg. creating .deb from setup.py
http://pypi.python.org/pypi/stdeb/
More info about setup.py
http://packages.python.org/distribute/setuptools.html
To grasp general concepts you could read stdlib docs: An Introduction to Distutils.
The first several links for keywords: "python packaging" are to: Python Packaging User Guide that should show what setup.py is and how to use it.
I'm looking to create the following:
A portable version of python that can be run on any system (with any previous version of python or no python installed) and have it pre-configured with various python packages (ie, django, lxml, pysqlite, etc)
The closest I've found to the above is virtualenv, but this only goes so far.
If I package up a nice virtualenv for python on one machine, it contains sym links to a lot of the libraries it needs. I can take those sym links and convert them to their actual files, but if I try to move this entire directory to another machine, I get seg fault after seg fault.
To launch python on a different machine, I'm using:
LD_LIBRARY_PATH=lib/ ./bin/python
and in lib/ I have all of the shared libraries I copied from the original machine. The problem here is these shared libraries might rely on other shared libraries that I'm not including, so executing this on other linux distros does not work. Probably due to it falling back on older shared libaries installed on the system that do not work with what I copied over.
Anyone have an idea on how to get this working? Is this even possible?
EDIT:
To clarify, the desired outcome is to create a tar.gz of a python binary and associated packages (django, lxml, pysqlite, etc) that can be extracted and run on any linux based system, ie (ubuntu 8.04, redhat 5, suse 11, etc), all 32bit distros, where the locally installed version of python doesn't impact what's in the tar.gz.
I just tested this and it works great.
Get the copy of python you want to install and untar it and cd to the untarred folder first.
Also get a copy of setuptools and untar that.
/opt/portapy used below is of course just the name I came up with for this post, it could be any path and the full path should be tarred up and the same path should be used on any systems you put this on due to absolute path linking.
mkdir /opt/portapy
cd <python source dir>
./configure --prefix=/opt/portapy && make && make install
cd <setuptools source dir>
/opt/portapy/bin/python ./setup.py install
Make the virtual env folder inside the portapy folder.
mkdir /opt/portapy/virtenv
/opt/portapy/bin/virtualenv /opt/portapy/virtenv
cd /opt/portapy/virtenv
source bin/activate
Done. You are ready to install all of your libraries here and have the option of creating multiple virtual envs this way.
You can then tar up the whole /opt/portapy folder and transport it to any Linux system of the same arch, within reason I suspect.
I compiled 2.7.5 ond centOS 5.8 64bit and moved the folder to a Cent6.9 system and it runs perfectly.
I don't know how this is even possible. If it were, they woudn't need to distribute binary packages of python for different platforms. You can't simply distribute python that will run on any platform. It has to be built from source for that arch. Virtualenv will expect you to tell it which system python to use (using links).
This pretty much goes for almost any binary package that links against system libs. Again, if it were possible, we wouldn't need any platform specific binary distributions.
You can, however, achieve part of what you want. That is, running python on another machine that doesn't have python installed as long as its the same arch. This is the same concept behind freezing, or py2exe/py2app/pyinstaller. An interpreter is bundled into a standalone environment. So the app can run on any similar platform.
Edit
I just realized that while your question speaks about "system" agnostically, your title contains the reference "linux". There are different flavors of linux, so in order for it to work you would have to build it fat for multiple archs and also completely contain the standalone links. You might try building a package with pyinstaller and using that to include in your project.
You can try just building python from source, in your virtualenv:
$ ./configure --prefix=/path/to/virtualenv && make && make install
If you still have problems with the links to libs, you can also investigate building it statically
I'm not sure that working solely in Python is the way to go here. You might have better luck with Puppet of Chef, which are configuration tools that can be used to create a local environment. There is plenty of code out there to install virtualenv and python on just about any Linux plus OSX (probably not Windows though).
Your workflow would be to install chef or Puppet (your choice), run a script to install the Python you want, then enter a virtualenv and pip install any packages you might need.
Sorry this isn't as easy as virtualenv alone, but it is much more robust.
Well, since I rarely accept "can't be done", there is a way to do it. Warning: it isn't pretty and you should probably look into a different scenario.
What you will need to to is determine a standard location for this top level directory. Second, using that directory as your root you will need to compile Python on each Linux distribution you want to run this on. For this you would use something like "/usr/local/myappname/platform/" to configure and compile Python to live in. In each case substitute "platform" with the name of the platform such as "/usr/local/rhel/". If memory serves the configure option you are looking for here is --prefix.
Once you have each distribution compiled you will need a script to determine which one to use and either set environment variables or have it create symlinks to the appropriate "installation" of python. I would then use virtualenv and bootstrap in that tree to keep the "in-use" python libraries even more specific.
I can't think of a common Linux distribution that doesn't have Python by default. As such you could use setup.py and/or basic python scripts to script this out since you should be able to rely in Python being present - even if its ye olde version as in RHEL installs. Personally I find the above method overly complicated but it would meet your stated requirements with the allowance for a final script. Of course, you could use shar (SHell ARchive) to tar all of this into a runnable shell script to do the installation and avoid the need for secondary scripts. If you gzip the resulting shel archive then you can decompress it on target systems and execute it to set everything up.
All that said, I would not recommend this. I would recommend determining the minimum Python version you can run on and ensuring that is installed by the distribution whenever possible and if needs be pulling down from a repo and installing. Then, use virtualenv and bootstrap with a requirements.txt to install necessary python libraries and apps into the virutalenv. For that see this documentation
I faced the same problem, so I created PortableVirtualenv. Your Question is just the definition of it.
I use it as a base for commercial multiplatform app I develop. (But PortableVirtualenv is public domain - use it freely.)
If needed, you can pip-install any package and zip the whole directory to distribute also packages you need.
One nice option is to make a "snap" portable linux application. They have a python mode which lets you specify you specify exactly what modules you need. From https://snapcraft.io/first-snap#python :
Snaps let you distribute a dependency-isolated Python app in an app store experience for end users.
Another option is to containerize your application with something like docker. Then instead of executing your script directly, the user is actually running a small OS with just your application and its dependencies. https://www.infoq.com/articles/docker-executable-images/ has more about executable containers.
Container images can also be used for short lived processes: a containerized executable meant to be run on your computer. These containers execute a single task, are short lived and can generally be removed after use. We call these executable images. Examples are compilers (Golang) or build tools (Maven), presentation software (I love to hack a simple presentation in Markdown format and let a RevealJS Docker image serve that) and browsers (a fresh contained browser to follow that fishy link). A real evangelist for executable images is Docker's own Jessie Frazelle. To get some great inspiration be sure to read her blog about them or check out this presentation at DockerCon 2015.
I downloaded tarball of python 2.7.2 to install on Suse Linux server--it comes with 2.6 and 3.1.
Untarred it (I know--wrong lingo, sorry) to a directory.
When trying to run ./configure, which should create a valid makefile I can't get past the step one: the script reports that it can't find a compiler on the path.
But, when I run the shell in the same directory and type "make", make runs.
I am really unfamiliar with Linux, but this just seems so basic that I can't even begin to see what's wrong.
I also downloaded what appears to be an RPM file for python 2.7.2 for SUSE Linux but I can't for the life of me figure out how to get "import" this package into Yast2 or "Install Software." These two tools seem impenetrable and hostile to packages saved in the file system rather than accessed from specific distribution web sites.
Really, this should be just trivial but it is not.
Suse uses Gnome and Gnome seems to have its own view of what the directory structure should be for desktop end user-y kinds of files. That is where I put my downloaded tar file. Might I do better if I put somewhere in usr?
Sorry to be so much more clueless than most stackoverflow participants but I am just not a Linux guy.
Sounds like you simply don't have the compiler installed. Do:
sudo zypper install gcc
If a ./configure fails, there's no point in running make.
Suse has a package manager called Yast. It would do your installation with no fuss.