0

I have a program written in python 3.3 that I'd like to be able to distribute without the need for users to install python or any additional modules. I was able to successfully package this program using cx_Freeze on Windows, but the same script on OS X produced an app that wouldn't launch.

I thought I might have better luck using py2app, but now I'm running into a strange problem. The program opens (it has a GUI built with tkinter) and runs flawlessly when built in Alias mode. When I attempt to construct a final build, however, I get the following message in Terminal:

error: No such file or directory: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-2.1-py3.3.egg/_markerlib/__init__.pyc

I navigated to that directory and found a .egg file that I'm unable to open or extract. I've tried reinstalling setup tools and well as python itself with no luck. Has anyone experienced this problem?

dcastello
  • 35
  • 8
  • How did you install `setuptools`? What do you mean by "unable to open or extract"? (As in, what did you try, and what happened?) Can you force-update it, or uninstall it and reinstall it? – abarnert Jan 14 '14 at 06:10
  • To install `setuptools`, I ran `ez_setup.py` downloaded from Pypi. To open the egg file, I tried downloading a third party tool, which crashed, and renaming it as a .zip, which failed. If I just double click on it, I get the "choose default application" popup. I've tried uninstalling and reinstalling, what's the process for force-updating? – dcastello Jan 14 '14 at 06:23
  • @abarnet It's looking like my `setuptools` installation is flawed. What's the best way to install it? – dcastello Jan 14 '14 at 22:42
  • Assuming your Python didn't come with `setuptools` preinstalled (it looks like a python.org binary installer, in which case it didn't), you can just delete the egg, then follow the [usual instructions](https://pypi.python.org/pypi/setuptools#installation-instructions) with `ez_setup.py`. – abarnert Jan 14 '14 at 22:44

1 Answers1

0

It looks like the problem is that your setuptools is somehow broken.


To open the egg file, I tried downloading a third party tool, which crashed, and renaming it as a .zip, which failed. If I just double click on it, I get the "choose default application" popup.

Double-clicking it relies on the extension to decide what app to launch.

The best way to check whether something is a valid zip file is to use the unzip tool from the command line. For example:

$ unzip -t setuptools.egg

This will check all of the zip headers, and check the CRC of all files in the archive, and report any errors. Or, if it's not a zip at all, it'll report one error right at the start.

You can also use the file command to do a quick check to see whether it's some well-known type of file. If file /path/to/setuptools-whatever.egg just says "data" instead of "Zip archive data", then it's probably corrupted beyond recognition.


Anyway, assuming your setuptools didn't come with your Python installation (if you're using a python.org binary installer, it didn't), the safest thing to do is uninstall it, then reinstall it cleanly.

The reason it's important to uninstall first is that the current version will, by default, not install a .egg archive, but will instead install a normal unzipped package and egg-info directory, meaning it may not overwrite the old, broken copy.

The documentation covers uninstalling. Just delete the setuptools .egg file, and anything else named setuptools*, from your site-packages (and anywhere else on your sys.path). If you have distribute there as well, kill that too. This will leave a few files sitting around in other places (notably easy_install-3.3 somewhere on your PATH), but they'll get overwritten properly by the installation, so that's OK.

To install, just follow the usual instructions to reinstall it:

$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python

… or, if you don't have write access to site-packages:

$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python

If you use pip, you may want to reinstall it after reinstalling setuptools, and then pip install -U setuptools pip just to make sure you have the latest versions—and to verify that everything is now working.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • I ran `$ unzip -t setuptools.egg` from the terminal, and the file the py2app reports missing is there! Here's the output: 'Archive: setuptools-2.1-py3.3.egg testing: easy_install.py OK testing: pkg_resources.py OK testing: __pycache__/easy_install.cpython-33.pyc OK testing: __pycache__/pkg_resources.cpython-33.pyc OK testing: _markerlib/__init__.py OK testing: _markerlib/markers.py OK` – dcastello Jan 14 '14 at 23:03
  • @dcastello: Is it possible that you have both an egg and an unzipped package? Because that's the kind of thing that could, e.g., confuse `py2app` but not `pip`. It's also conceivable that your `zipimport` support somehow got screwed up, but that seems a lot less likely. And of course your `py2app` could be broken. – abarnert Jan 14 '14 at 23:07
  • @dcastello: Anyway, if you do the steps in my answer, I'm pretty sure you should end up with an unzipped `setuptools` instead of an egg install, and it's worth seeing whether `py2app` is happy with that. – abarnert Jan 14 '14 at 23:07
  • When I enter the terminal commands above, I get the error `-bash: wget: command not found`. Is there something else I need to install to use `wget`? – dcastello Jan 14 '14 at 23:15
  • A quick Google search tells me that OS 10.9 doesn't include `wget`, but it is possible to download it. Can the same command be run with `curl`, or should I try for `wget`? – dcastello Jan 14 '14 at 23:22
  • @dcastello: Yes, it can be run with `curl`, but the syntax is slightly different from `wget`, and if you don't know them both, you're probably safer splitting this into two commands: first `curl ` to download it, then `python3 ez_setup.py` (with the `sudo` if necessary). Or you can even use your browser to download it, as in the Windows instructions. – abarnert Jan 14 '14 at 23:25
  • Using `curl` followed by the link prints out the text of the setup file. I'm not sure what directory, if any, it's been downloaded to. I would just download it from Safari, but that's what resulted in the `.egg` initially. – dcastello Jan 14 '14 at 23:33
  • Update. I figured out how to run the file, but now I have a new error: `zipimport.ZipImportError: bad local file header in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/setuptools-2.1-py3.3.egg Something went wrong during the installation.` Thank you for your time and expertise, this is all very frustrating. – dcastello Jan 14 '14 at 23:39
  • Sorry, yeah, `curl ` just outputs to stdout. You can just pipe it to `python`, or use the `-o` flag (takes a local filename) or `-O` flag (guesses a local filename based on URL), or `>` it to a file. But anyway, it sounds like you got past that. – abarnert Jan 15 '14 at 00:11
  • Anyway, it's possible that your `zipimport` module is broken… but that's a builtin, so the only way around that is to uninstall and reinstall Python. Which you already tried, right? Can you use the `zipfile` module to open the file and iterate it? They share a lot of code, so if something goes wrong there, it might tell us what's going wrong in `zipimport`. – abarnert Jan 15 '14 at 00:14
  • If I run `python3.3 ez_setup.py --user` the installation runs without error, but it leaves me with the same problem I had before. I'm getting the same error from py2app. Let me try using `zipfile` on `ez_setup`. – dcastello Jan 15 '14 at 00:16
  • No luck with `zipfile`. Is it significant that I can bypass this error with `--user`? EDIT: Just tried running without `--user`, and I didn't receive an error. I installed `pip` and ran `pip install -U setup tools pip`, which also ran without error. The original problem still remains. – dcastello Jan 15 '14 at 00:22
  • I'm not sure I understand your last two comments. By "no luck" you mean that it fails, or that it can't find any problems? And what error did `--user` bypass? – abarnert Jan 15 '14 at 00:31
  • Sorry about that, I meant that I couldn't run `zipfile`. It may be that I have the syntax wrong. Adding `--User` bypassed this error: `zipimport.ZipImportError: bad local file header in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/se‌​tuptools-2.1-py3.3.egg Something went wrong during the installation.`, but now I'm not getting that error at all. The `setuptools` installation ran, but it resulted in the same `egg` file I had to begin with. – dcastello Jan 15 '14 at 00:34
  • `zipfile` is [a module in the standard library](http://docs.python.org/2/library/zipfile). It's very easy to use, but you'll need to skim the docs, because it doesn't have any real examples. – abarnert Jan 15 '14 at 00:57
  • Anyway, I'm guessing you only got that error the first time because after that time, there was already an egg lying around, so `ez_setup` didn't have to rebuild it, so it didn't get an error rebuilding it. If you uninstalled it (from both system and user) and reinstalled it, presumably you'd get the same error again, whether you did `--user` or not. The big question here is why setuptools is building an egg that not even setuptools can read (via zipimport), and… I have no idea, short of a completely broken Python install. – abarnert Jan 15 '14 at 00:58
  • I'm going to try reinstalling Python again. Guess it can't hurt. – dcastello Jan 15 '14 at 01:03
  • Reinstalled Python, reinstalled `py2app`, reran the whole process, same error. I've hit a wall on this. Cx_Freeze worked on windows, py2app works in alias mode... why is it impossible to package this app on Mac OS? Should I not be using a default Python install from the main website? – dcastello Jan 15 '14 at 01:11
  • @dcastello: I don't know what to tell you. I package standalone app binaries using `py2app`, against a default python.org Python 3.3.1 install. Which sounds like exactly what you're doing. And it works for me (the apps even run on 10.6, despite me building them on a 10.8 machine). So the exact same thing certainly _should_ work for you. No idea why it doesn't. – abarnert Jan 15 '14 at 01:17
  • The only difference then is that I'm using 3.3.3. Do you think downgrading would be worth the trouble? Well that and I'm on 10.9, but I don't think bumping that down is an option. – dcastello Jan 15 '14 at 01:19
  • @dcastello: I doubt it's that. I'm actually using 3.4b2 on my dev machine and 3.3.1 on my build machine, and they both work. One thing that might be different… I don't do any Tkinter in my apps, which means you have one big hairy dependency that I don't: Tk. Are you using Apple's pre-installed Tk framework, or did you install the ActiveTcl version as suggested [on python.org](http://www.python.org/download/mac/tcltk/)? Either way, I don't see how that could cause _this_ problem, but I can definitely see how it could cause the original problem with `cx_freeze` producing a broken app… – abarnert Jan 15 '14 at 01:22
  • I had the same thought, so I was sure to install the latest version. Perhaps I should give up on py2app and give cx_Freeze another shot. I'm getting a new error when I attempt to run it. There's a `.gif` in my program, and `cx_Freeze` tells me it's not a `mach-0` file. Any idea what that might mean? – dcastello Jan 15 '14 at 01:26
  • @dcastello: You mean `Mach-O`? That's the name of the executable file format that Mac OS X uses (like ELF on most other Unixes, and PE32 on Windows). In other words, for some reason, `cx_Freeze` thinks you're trying to give it an executable binary when you think you're giving it a GIF image (and you're the one that's right). That might be worth opening a separate question on, to attract people familiar with `cx_Freeze` instead of `py2app`. – abarnert Jan 15 '14 at 01:41
  • You're right, I may start up another question. Either that or I'm going to douse this computer in kerosene, light it, and become a goat herder on the Eurasian plains. Thank you for all of your help and guidance, regardless that we never found the answer. – dcastello Jan 15 '14 at 01:49
  • Good luck, and say hi to the goats. – abarnert Jan 15 '14 at 02:03