How can I pack python into my project? [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am making a program that will call python. I would like to add python in my project so users don't have to download python in order to use it, also it will be better to use the python that my program has so users don't have to download any dependency.
My program it's going to be writing in C++ (but can be any language) and I guess I have to call the python that is in the same path of my project?
Let's say that the system where the user is running already has python and he/she calls 'pip' i want the program to call pip provided by the python give it by my program and install it in the program directory instead of the system's python?
It's that possible? If it is how can I do it?
Real examples:
There are programs that offer a terminal where you can execute python to do things in the program like:
Maya by Autodesk
Nuke by The foundry
Houdini by Side Effects
Note: It has to be Cross-platform solution

There are programs that "freeze" your python program including Python itself, for example Pyinstaller (http://www.pyinstaller.org/)
It won't help with the requirement in the third paragraph though, for that you'd have to include Python itself as part of the complete download, which seems unnecessary.

In order to run python code, the runtime is sufficient. Under Windows, you can use py2exe to pack your program code together with the python runtime and all recessary dependencies. But pip cannot be used and it makes no sense, as you don't want to develop, but only use the python part.
To distribute the complete python installation, like Panda3D does, you'll have to include it in the chosen installer software.

You can use py2exe to turn you python program into an executable. You do not need to keep python in the executable.

Related

How to share my python game with friends who don't have python or pygame [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Just finished making my first python game based on the space invaders game. Now I don't know exactly how to share it with my friends. I know that I should use py2app, but I haven't found good online instructions on how to do so.
This is how the project file looks like:
I'd appreciate it if someone could help me out.
pip install pyinstaller - this module can generate executables of python scripts.
Then simply run: pyinstaller main.py or whatever the main file is named and it will generate an executable including all needed modules (you can find the
generated package in new created dist folder).
You can try using Py2exe, which, as the name suggests, compiles Python programs to an executable format.
Edit: Just noticed you were using MacOS, here is a Py2app tutorial instead.

How do you run a Python (.py) program by double clicking the icon? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
(I use Mac OS X and Python version 3.4.3).
When I double-click on the Python program (.py), I don't want the source code to load/open in Python IDLE, I just want the program to run in Python Shell?
For example when I click the Spotify Icon App, it just runs the program and doesn't bring up its source code! I understand this maybe a very simple question, but I am really stuck! Any help will be great! If this is unclear feel free to ask me questions.
TLDR: You don't.
This isn't normally done; applications that you double click are usually compiled so that the source code isn't there anymore, instead it's been turned into machine-readable instructions for the computer. Since python code is source code, it's simply not designed to be run like an app.
You can compile your python code into an app every time you want to use it, using something like py2app but then the source-code inside isn't easily editable and it may be fiddly to get complex imports working with this, or multiple python versions. I wouldn't get into the habit of this.
Instead, to run a python file, use the Terminal, and type python file_location where file_location is the path to the file. Alternatively you could navigate in the Terminal to the directory containing your python file and then just use python file_name where file_name is the name of your file.
Only compile your python work into an app when it's at its final stage and ready for "release".
For example, what if your app prints something to the command line? Without running it from the command line where would python print that information? Or what if something goes wrong in it and it returns an error; where would that error message go? Also the newer versions of Mac and their "System Integrity Protection" can make life difficult for bundled apps.

How to put code into html for others to play in browser [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I recently made a game that I enjoy playing, and so do my friends. After they download python for themselves, receive the .py files and then start playing. It's a hastle. I was wondering if there was anyway for me to take my game and all in it, put it in some .html that I host online, and have anyone play it whenever they want.
No, it's not possible to play a python game on a web page. Python is interpreted locally, on the user's computer. They have to download the files in order to play.
However, you can use a utility like py2exe to make your game into an executable file, so it can run on its own without the user having to install python. (I'm assuming this is for Windows -- Macs already have Python installed).
update: Per Anderson Green's comment, putting Skulpt on your site will allow visitors to use python scripts in a web page.
Depending on your version of python you could look at packing it into an executable that would be easier to distribute. But unless there's some way of having your website be a persist ant virtual python environment, I don't think web hosting will be the way to go.
For python 2.x I know distutils is one method of packing an executable, but the last I checked, it wasn't compatible with 3.x.

Python for Android [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I had a look at Kivy,but the problem is it needs a virtual machine to run apps. Isn't there a way where python codes are directly converted to java bytecode which can be run by android without any virtual machine? What are the merits/demerits in terms of performance?
May be something in jython which would help?
Try SL4A for running Python code directly on your device. It requires no compiling, conversion to bytecode or virtual machines.
More information Here
Also, you can download an IDE (I've used Eclipse, like in the tutorial you will find on the site), installed a plug-in, created my source files there and then uploaded them to my phone, if you're uncomfortable with writing code on your device.
This page has full instructions on how to package a Kivy app into an APK: http://kivy.org/docs/guide/packaging-android.html
I think some one mislead you a lot or you are confused about how things work with kivy.
I'll take this opportunity to try and make things a bit more clear.
Kivy can be used to build stand alone apk, only if you had searched kivy in google play. This link shows a list of apps that mention kivy, there are a lot more apps there that use kivy and just don't mention that. There is also a partial user maintained list you can look at. You can install the apps from google play and you'd see that they are self contained and don't require you to download anything extra.
There are very easy instructions available on how to build a apk in the link mentioned by #Marcins.
Every python code passes through the python interpreter usually pre-compiled to pyc, that's how python works even Java uses a virtual machine JVM, Android's implementation uses Dalvik VM. You can learn more about the VirtualMachines used in the languages like java/python here. The python interpreter/vm consumes the code and executes it natively, it doesn't convert it to java byte code.
if you need to make something that needs more performance then you can even use cython with kivy to get more speed.

Export Python script [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm using Blender and Python and want to give the .py file to other users to use my script... My script uses external modules (like NumPy) which will rise the errors (like can't find module xxxx).
Not all people can install NumPy (or even Python :D) as many Blender users are just artists.
Another note is that NumPy doesn't work with Blender (I install it in the system's Python, then delete Blender Python so it relies on the system Python).
If you want to distribute your code with external dependencies then you should build a Python egg. The .egg format was created to solve the issue you are dealing with. It is a self-contained release of your code with dependencies and meta-data. Here is some information on how create Python eggs.

Categories

Resources