How To Change Py To Dmg

  1. How To Change Py To Dmg File
  2. How To Change Py To Dmg Files
  3. How To Change Py To Dmg Reader
  4. Change Pygame Icon

While I was working on the Quaver Lyrics Finder project (it’s my first time writing Python, please be gentle), I wanted to make it into an easy-to-use program that most people to use. That meant:

  1. Looking native, presenting a GUI when clicked.
  2. Turning it into a self-contained executable file that does not rely on having Python or other dependencies being installed.
  3. Creating a file that users could download in an expected file format. This means having a .exe or .msi for Windows, a .dmg for macOS, and a .deb for Ubuntu.
  1. Create a new folder on Mac and copy.APP file to the new folder. Open Disk Utility File New Image Image from Folder. Choose the new folder. Specify the name of the DMG file and the path where the file should be created and click Save button.
  2. The gibMacOS python script runs on Windows, Linux or macOS and is used in this Guide: Downloading the Recovery HD image - /r/Hackintosh macOS Internet Install - For example to get the Yosemite Recovery Image run in the Terminal./gibMacOS.command -recovery -v 10.10 -m 10.10 (replace 10.10 with the version you need: 10.09 to 10.15).

Here’s what I did.

This is the first part of the series where I write about things I learned while writing a desktop app. The second post can be found here.

Briefcase v0.2 was built as a setuptools extension. The configuration for your project was contained in a setup.py or setup.cfg file, and you invoked Briefcase using python setup.py. Briefcase v0.3 represents a significant change in the development of Briefcase. Briefcase is now a PEP518-compliant build tool. Type pyinstaller myscript.py in the command line and hit enter. It will take a short time to compile and you will get three new folders and an additional file. After it’s finished, look in the folder to find the executable file you’ve created. Go to dist myscript and execute the myscript.exe file.

Contents

  1. Turning the project into a self-contained executable file
    • 2.1 Using PyInstaller
    • 2.2 Customizing the spec file
  2. Creating a package in an expected file format

1. Looking native

For creating a GUI in Python, I chose to use PyQt5, a framework that provides Python bindings for the great C++ Qt framework.

Reasons in favour of PyQt:

How To Change Py To Dmg File

  • Looks like native elements.
  • Compatibility with Python 3.5+.
  • Well tested and documented.

Something that you should consider about PyQt5 is that licensed under the GPL 3.0 license. That means that if you distribute the Qt Gui Toolkit as part of your application binary, your program must also be licensed under a GPL-compatible license. Since my project was open-source anyway and uses the MIT license, this was fine by me.

Other possible choices:

  • Pyside: Another framework for bindings for Qt. In favour: Less restrictive licensing (LGPL instead of GPL). Against: Does not support Qt5, a little bit less well-documented because it’s less well funded than PyQt.
  • TkInter: A GUI framework that comes pre-installed with Python. In favour: Easy to set up, since it’s pre-installed with Python. Against: Does not look native, less popular than PyQt/PySide.
  • Kivy: Another GUI framework. Against: Not Qt, but seems decent otherwise.
  • wxPython: Doesn’t support Python 3, so this was out.

I’ve used PyQt on four different platforms - macOS, Windows, Ubuntu, and elementary OS. The GUI looks pretty good on all of them, so the cross-platform claim checks out!

How To Change Py To Dmg

2. Turning the project into a self-contained executable file

I’m using PyInstaller to generate an executable for my python files.

PyInstaller:

  • Checks for dependencies for all files, and puts them into your executable.
  • Works cross-platform: same commands in macOS, Windows, Linux.
  • Is easy to use - one command in whatever shell you prefer.
  • Is actively maintained, has decent documentation, and relatively popular.

Since it’s popular, chances are that when you have a problem, there’s somebody else who’s already run into it. Stack Overflow, the GitHub page, and even just the documentation are life-savers. Keep in mind also that PyInstaller is not a cross-compiler, i.e. you can’t build Windows .exe files when using macOS, etc. Use PyInstaller in a VM to do that.

Other possibilities include:

  • bbfreeze: But it’s unmaintained and does not support Python 3.
  • py2app: It’s not being maintained, and not cross-platform (you need to use py2exe to create an executable for Windows).
  • cx_Freeze: Less actively maintained compared to PyInstaller.
  • pyqtdeploy: More fussy than PyInstaller, and harder to set up.

2.1 Using PyInstaller

PyInstaller can be downloaded with pip:

Then, starting off with PyInstaller should be as simple as running:

It checks for dependencies, analyzes <your_file>.py, and generates an executable file in dist/ as well as a <your_file>.spec file in the same directory as <your_file>.py. If all goes according to plan, there should now be a single executable file that you can click to open in dist/ and it should run as if you had run your script from the command line.

For more details, read their docs.

2.1.1 Useful options

--onefile allows you to create a single executable.

--onedir creates executables in a folder structure. Useful for debugging.

pyinstaller <your_file>.spec will use the specified spec file to build the executable. This is very useful if you’ve customized the spec file.

2.2 Customizing the spec file

The spec file is a Python script that PyInstaller uses to determine what to build and where to build it. Understanding this is essential to understanding PyInstaller. There are several customizations that I’ve done to my spec files that have come in handy.

A spec file is generated automatically in the same directory as your file when you run pyinstaller <your_file>py. You can customize it from there on. Note that if you run pyinstaller <your_file.py again, it will generate another spec file that overwrites any customizations that you made! To avoid this, give pyinstaller a spec file as an argument, e.g. pyinstaller <your_file>.spec.

2.2.1 Assets

If you refer to assets by a relative path in Python file <your_file>.py, likeQtGui.QIcon('./assets/icon.png'),the executable that PyInstaller generates won’t include them in the correct place, and your program will not be able to find the assets. This happens for images, text files, data files, and more.

The workaround that I’ve found:

  1. Add these lines after the a = Analysis(...) code block in the spec file, with more entries as appropriate:

    Note that in certain filesystems, case matters! This bit me in Ubuntu.
    The path to the file is always relative to the directory where you the .py file you are asking PyInstaller to analyse is. As an example, this is what the directory structure could look like:

    With that directory structure, the code snippet would become:


  2. After having modified your spec file, you’ll need to go back to <your_file>.py and add the following code somewhere:

    Explanation: PyInstaller creates a temporary folder called _MEIPASS, that contains the files as named in a.datas. Thus, the _MEIPASS folder exists only when the code is running as an executable bundle generated by PyInstaller. This function checks for that folder, and if it exists, thus knows that it’s running the executable. When the code is in an executable bundle, this function will convert your relative path to the path in the _MEIPASS folder, and otherwise leaves it alone.

  3. Once you’ve added the function to your code, you’ll need to update every place that has a relative path to call that function.
    As an example:


  4. And finally, run PyInstaller with your new spec file. For example, when I’m generating a bundle for Quaver, I do pyinstaller quaver-onefile.spec.

2.2.2 Generating a bundle for macOS

PyInstaller is really good for creating bundles that conform to Apple’s Bundle Structure, making them easily code-signable. Here’s what I add to my spec file after the pyz code block to generate a bundle for macOS.

In BUNDLE(), info_plist will create the appropriate <key> and <string> in the .app bundle structure. For example, the NSHighResolutionCapable example looks like this in the Info.plist file in Quaver.app/Contents/.

Unfortunately, specifying the types of documents the app supports doesn’t work with this format. I have a post about this here, but you need a CFBundleDocumentTypes key with an array of values, which is too complicated for PyInstaller’s spec file to handle. The only solution is to create and save a separate Info.plist file, then replace the one PyInstaller generates in your_app.app/Contents/. See here for more details. :/

2.2.3 Generating a .exe for Windows and executable for Linux

Here’s what I’m using in my spec file for Windows and Linux:

3. Creating a package in an expected file format

After customizing the spec file and running PyInstaller, we now have a nice executable file. A .app on macOS, a .exe on Windows, and an executable file on Linux. The next step is to package it into something that users are used to downloading.

3.1 Creating a .dmg for macOS

I’m not fussy, so I used a simple command line tool that creates a .dmg from a .app, called create-dmg. It’s purposely simple, and doesn’t offer many options.

Assuming you have npm installed (otherwise, brew install npm (and if you don’t have brew click here):

Now, cd into the directory containing your .app file generated by PyInstaller, and run:

You should now have a new <your_app_name> <sem_ver>.dmg file in the directory where you ran create-dmg! Create-dmg pulls the version number from your app’s Contents/Info.plist folder, so if it’s wrong, update the Info.plist file first.

3.2 Creating a .msi file for Windows

If you don’t need to change the registry, you could just distribute the .exe file that PyInstaller generated, since the .exe file is basically a portable version of your program. Otherwise, you’ll need to create a separate installer executable to set things up correctly. Another benefit of an msi file is that it can properly integrate with the start menu and create desktop shortcuts easily.

I’m using the free version of Advanced Installer to do this. Some gotchas: make sure you create a “Simple” project instead of a “Professional” or anything else, because “Simple” is the only one that’s free, and you cannot convert one type of project to another later on. Advanced Installer lets you create Professional projects when you download by automatically activating a trial, which is sneaky.

Customize as necessary. See their website for a simple tutorial on how to get started and their professional guide which walks through a few more tools.

Other competitors:

  • WiX Toolset:
    • ++ Immensely powerful and more customizable.
    • ++ Uses text files for configuration, which simplifies version control and portability.
    • ++ Free and open source.
    • ++ Well documented, and tested.
    • -- Significantly harder to learn and get started with. Since my project didn’t have big requirements (all I wanted to do was add a few registry keys), learning to use WiX would have been overkill.
  • InstallShield:
    • ++ Powerful, solid, and well-liked.
    • ++ Good GUI.
    • ++ Good support.
    • ---- Literally costs thousands of dollars. I’m not exactly going to spend that much for a one-time project.

3.3 Creating a .deb file for Ubuntu

Unlike macOS and Windows, the tools to create a .deb file are built-in to the operating system!

You’ll need to create a directory structure as follows:

The control file is what the advanced package tool reads to see what needs to be changed and which app is being installed. See more in the documentation. A basic control file might look something like this:

The <project>.svg file should contain an SVG of your app icon.

The <project>.desktop file allows the launcher to discover your program, and integrates it with your system. See here for more information. A basic .desktop file might look something like this:

Once all that is done, all that you have to do is a simple command, and your .deb file will be created in the same directory as the folder.

4. Closing notes

How to change py to dmg file

How To Change Py To Dmg Files

Writing the functionality isn’t the last thing that needs to be done – just look at this entire blog post as an example. Keep working through it, and it’ll all work out.

If you’re interested in finding out more about the “Open with” functionality and the second post of this series, see here!

When you are going through can­cer treat­ment, and more specif­i­cal­ly chemother­a­py, your health care team is there to make sure you are com­fort­able. You will have the lux­u­ry of your own pri­vate reclin­ing chair along with med­ica­tions to help man­age side effects but bring­ing a favorite book, movie, blan­ket or friend can also pro­vide com­fort dur­ing your treat­ments. The num­ber of chemother­a­py ses­sions and dura­tion of each treat­ment will vary from patient to patient and even vis­it to vis­it, but it is help­ful if you bring some things to help pass the time and keep you com­fort­able while receiv­ing treatment.

Many peo­ple don’t know what they should bring when they first come to a chemother­a­py treat­ment. Review our sug­ges­tions below and choose a few items to bring to your next chemother­a­py ses­sion. It’s a good idea to switch and bring dif­fer­ent items, as well as some of your favorite items, at each treat­ment ses­sion. You’ll soon fig­ure out what helps you best pass the time.

Com­fort­able Clothes

Patients gen­er­al­ly wear their ​street clothes” dur­ing treat­ment. Think about this when you get ready to go to your appoint­ment. Think about your favorite com­fy clothes, sweat pants, yoga pants, your favorite soft t‑shirt or zip-up sweat­shirt. Many of the infu­sion med­ica­tions can make you feel chilly, while oth­ers can make you feel hot. It is best to dress in lay­ers so that you can eas­i­ly adjust based on how you feel. Also make sure that you dress so that your nurse can eas­i­ly access your port. A V‑neck or but­ton up shirt works best.

Blanket/​Pillow

DMG infu­sion cen­ters pro­vide warm blan­kets, but some­times you want small com­forts of home, so con­sid­er bring­ing a favorite small blan­ket or pil­low. Many patients pass the time by napping.

Read­ing Materials

Whether it be the lat­est edi­tion of your favorite mag­a­zine, or the newest must-read nov­el, hav­ing some­thing to read will help pass the time. Don’t feel like read­ing but want to indulge in a sto­ry? Try an audio-book.

Music

Load your phone or iPod with some of your favorite music to help pass the time. Or, down­load your favorite music stream­ing app on your phone and find some new favorite tunes. Don’t for­get your ear­buds or headphones!

Games

How To Change Py To Dmg Reader

Down­load your favorite game apps to your phone and brush up on your skills. Tsum Tsum, Can­dy Crush, Clash of Clans and soli­taire await! Or, if a friend or fam­i­ly mem­ber is com­ing with you, con­sid­er a favorite board/​card game like Con­nect 4, UNO or Bat­tle­ship. Many com­pa­nies also sell trav­el edi­tions of your favorite games. Puz­zle books are also very popular.

Favorite Hob­by Materials

Do you like to sketch, cro­chet or knit? Keep­ing your hands mov­ing dur­ing your infu­sions will help you keep warm as well as help you make a dent in that project that you were nev­er able to quite fin­ish. Adult col­or­ing books are also a great way to relax and decompress.

Movies

DMG infu­sion suites have DVD play­ers where you can pop in your favorite movie but you can also bring your iPad and stream your favorite movies or TV shows from Net­flix or Hulu through the free Wi-Fi.

Snacks & Beverages

It is impor­tant to main­tain a healthy diet while you are going through can­cer treat­ment. DMG’s Infu­sion Cen­ters offer light snacks and bev­er­ages, but you may want to bring your favorite snack. It’s also impor­tant to stay hydrat­ed — try switch­ing between water, Gatorade and oth­er decaf­feinat­ed beverages.

Sup­port Person

If you gen­er­al­ly go to your infu­sion treat­ments alone, it might be a nice change of pace to invite a friend or fam­i­ly mem­ber. This is a good time to catch up and share your expe­ri­ence with a loved one. Also, hav­ing some­one with you can help divert your atten­tion from your treatment.

Change Pygame Icon

If you have any oth­er ques­tions before dur­ing or after your infu­sion treat­ments, don’t be afraid to talk to your oncol­o­gy team mem­bers — infu­sion nurse, nurse nav­i­ga­tor or physician.