1

Every few months I encounter an app (java, python, etc) that I would like to install in Ubuntu, but it doesn't come as a linux package, nor is there any included installer. It's not often that this happens and so I usually have forgotten the appropriate way to do it. Unfortunately, more times then not, the instalation instructions are like this, and really don't help much:

... Once you have extracted the program.zip and installed the required dependencies, you should be able to run the application with this command:: python /source/program-name.py Preferable you create a shortcut on your platform that issues this command.

Could someone tell me (step-by-step) how to install python apps, as if they had been installed with a "standard" package manager (as a ubuntu/debian package)? (I was hoping there was a simpler way to do this, rather then having to create a package myself -- even something like what I do when installing an app with source files -- ./configure->make->make install).

1) where should I install (move?) python files (does it matter if it uses Python2 or Python3, should I install locally or for all users),

2) do I change the Python file/folder permissions

3) how do I create a menu item with an icon

4) and anything else to properly install the app (including steps so that I can uninstall and upgrade without problems)

I have always hoped that someone would create a script or gui that would walk me through these steps... if there is such a thing, then disregard the above and just let me know the name of the app and where to find it.

  • It's not the answer to your question, but with python3 applications - relative imports work a LOT better. So if it's py3k and has a requirements.txt - being just plain portable and not having to install is nice. – RobotHumans Aug 22 '15 at 2:50
  • is there a specific package/app that you want to install? – Ron Aug 22 '15 at 5:53
  • The answer depends on: 1] if you want to use it locally or for all users 2] If it is a script or an application; should it run in the background, does it have a gui etc. Please give one or (better) some examples. – Jacob Vlijm Aug 22 '15 at 6:04
  • Ron: Right now there is a specific package that I want to install... but shouldn't there be a "standard" template for installing any python app manually? – TJK Aug 22 '15 at 16:03
  • Jacob Vlijm: As I mentioned to Ron (above), what is the "standard" or normal way that apps are installed: locally or for all users? That's the way I want to install it. If it is, eg 50/50, then what are the criteria for deciding whether to install it locally or globally? My lack of understanding of things like this is why I wish there was a "installer app" to walk me through the decisions and/or why I need steps to install an app. As for running "in the background"... I never thought of that being an option. (Again, an eg of my ltd knowledge of the subject of man. installs... very helpful) – TJK Aug 22 '15 at 16:25
1

You don't actually have to "install" the app. Python apps are interpreted, which means the source code is pretty much executable.

In order to run the source code, for a file that is in ~/AppName/ called AppName.py, you can open a command line and just type

python ~/AppName/AppName.py

And that will launch your Application in whatever version of python came with your version of Ubuntu. You can turn this into a desktop shortcut pretty easily... But I'm not in Ubuntu right now, so I can't give you precise instructions, sorry about that.

  1. Put the files wherever you want, as long as you can navigate to the path and have permissions there.
  2. You probably don't need to change any permissions.
  3. This should be pretty easy, but I'm not in linux right now, so hopefully somebody else will edit this part in... sorry.
  4. Nothing else. You didn't install it, so just remove the files and the shortcut you made, and it will be gone. Upgrading might involve upgrading python, but probably won't.
  • 1
    I'd consider this the easiest way to install a python app (and it probably would work to create a "portable app" folder under ~/usr-name/) However, I question the security of doing something like this... I know of a number python apps that are packaged that are installed like any other ubuntu/debian app. In these cases you need to be root to install, and they usually appear in the software manager after instalation (so you can find it with other apps and remove it like any other app). I suppose that I'm wanting a way to install it as if it was in a package... – TJK Aug 23 '15 at 19:07
  • Ah. I don't really know how to package software, but... If the developers have given you the source code, you could just package it yourself... and then install it as usual. Is that what you're asking for? – Daniel Aug 23 '15 at 20:03
  • @Daniel thanks for showing the possibility to install it on the ~, that is the home directory. However I am wondering if that is the best place to install applications. According to my knowledge usr/local would be one of the most appropriate places. Citation: "/usr/local is widely regarded as a good place in which to keep self-compiled or third-party programs. " (See tldp.org/LDP/Linux-Filesystem-Hierarchy/html/usr.html) – loved.by.Jesus Jun 16 '17 at 11:16
0

I've found a great way to install python apps in Ubuntu.

Lets say we have an app, app.py. First, make this file executable by:

  1. Adding the proper shebang to the top of the file. For Python3 apps add #!/usr/bin/env python3 to the very top of the file if it isn't already there. For Python2 apps add #!/usr/bin/env python instead.

  2. Next, change the file permissions to allow execution by any user $ chmod a+x app.py

If you have an executable python prog, for example one made from pyinstaller or the likes, you can skip the previous steps and just mv the executable instead in the next steps.

At this point you could simply save this file wherever you want and execute it directly in the terminal with # /path/to/file. BUT, that's not how apps are typically installed... The proper way IMO is as follows:

  1. move the file to the /usr/bin/ directory. This is where much of the executable code goes for other apps installed with apt or other methods. Use this command to do so: $ mv app.py /usr/bin/app. After that you can execute the app at any time from any directory in the terminal by simply running: # app. Notice I dropped the ".py" from the file when moving it... this is optional, whatever you name the file when moving it becomes the command to run it...

  2. Many people might stop here... But I prefer this last step for my apps. Create a desktop file touch app.desktop. A simple desktop file contains the following:

[Desktop Entry] Type=Application Encoding=UTF-8 Name=App Comment=My custom app Exec=app Icon=/path/to/some/optional/icon.png Terminal=false

Exec should be set to whatever you named the file in the previous step when moving to the usr/bin/ driectory. the Icon field is optional. If you need to see the terminal to use the app set Terminal to true.

Save this file to the /usr/share/applications/ directory with $ mv app.desktop /usr/share/applications/

At this point, you should be able to hit the super(windows) key and start typing the name (the one you listed in the .desktop file) and see your application pop-up as an option... hitting enter or clicking it with your mouse should launch it. You can right click on the option and add to favorites if you'd like.

To see an example hello world python app and it's corresponding desktop file and install bash script see my project at: Hello_project

0

I agree, it is a simple way to do it, which is similar to my approach. Some time ago I wrote a small bash script to install to ~/.local/...

Below is the script, which you will need to edit to suit your installation:

#! /bin/bash
## #############################################
## Install simpelregner application:
## simpelregner.py         ---> $HOME/.local/bin/
## simpelregner.ui         ---> $HOME/.local/bin/simpelregner/
## simpelregner-64.png     ---> $HOME/.local/bin/simpelregner/
## simpelregner.desktop    ---> $HOME/.local/share/applications/
## By Carl Friis-Hansen
## #############################################

## -------- Get path of this script --------
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
APPNAME="simpelregner"

## -------- Write the .desktop launcher file --------
echo \
"[Desktop Entry]
Version=1.0
Encoding=UTF-8
Type=Application
Terminal=false
Name=$APPNAME
Exec=$HOME/.local/bin/$APPNAME.py
Path=
Comment=Simpel Regner
Icon=$HOME/.local/bin/$APPNAME/$APPNAME-64.png
Name[en]=simplecalculator"\
 | tee $HOME/.local/share/applications/$APPNAME.desktop
## -------- Executable .desktop launcher file --------
chmod +x $HOME/.local/share/applications/$APPNAME.desktop

## -------- Copy the rest of the files --------
cp $DIR/$APPNAME.py $HOME/.local/bin/$APPNAME.py
chmod +x $HOME/.local/bin/$APPNAME.py
mkdir -p $HOME/.local/bin/$APPNAME
cp $DIR/$APPNAME.ui $HOME/.local/bin/$APPNAME/$APPNAME.ui
cp $DIR/$APPNAME-64.png $HOME/.local/bin/$APPNAME/$APPNAME-64.png
cp $HOME/.local/share/applications/$APPNAME.desktop $HOME/Desktop/$APPNAME.desktop

## -------- Done, so message to user --------
echo
echo "-----------------------------------------------------------------"
echo "Simple Regner simpelregner er nu installeret"
echo
echo "Dobbeltklik på desktop ikonen simpelregner, enten på desktoppen eller i menuen."
echo "Første gang må du svare på, om du accepterer at køre programmet."
echo "-----------------------------------------------------------------"
echo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.